Compare commits

...

78 Commits

Author SHA1 Message Date
6acfddb70d 3.0.19 2023-05-08 15:22:28 +02:00
c34d71238a fix(core): update 2023-05-08 15:22:27 +02:00
2f4fd839a1 3.0.18 2023-05-08 10:07:34 +02:00
bd8585aa42 fix(core): update 2023-05-08 10:07:33 +02:00
e4f8e53066 3.0.17 2023-05-07 20:24:53 +02:00
d381f8adad fix(core): update 2023-05-07 20:24:53 +02:00
d1c0501461 3.0.16 2021-12-10 18:03:47 +01:00
f5d33bdebe fix(core): update 2021-12-10 18:03:46 +01:00
2b9c9225a5 3.0.15 2020-12-08 22:31:35 +00:00
5ce55190fe fix(core): update 2020-12-08 22:31:35 +00:00
8fb071f57b 3.0.14 2020-12-08 22:29:20 +00:00
3278ef7425 fix(core): update 2020-12-08 22:29:19 +00:00
11282daa38 3.0.13 2020-12-07 23:11:14 +00:00
1fe7dd8d06 fix(core): update 2020-12-07 23:11:13 +00:00
9175cb7841 3.0.12 2020-12-07 05:06:31 +00:00
6b9ebcec7a fix(core): update 2020-12-07 05:06:30 +00:00
2159995342 3.0.11 2020-11-06 01:11:26 +00:00
7fa14ceabd fix(core): update 2020-11-06 01:11:26 +00:00
0294895f78 3.0.10 2020-11-05 20:03:13 +00:00
74fc97a220 fix(core): update 2020-11-05 20:03:12 +00:00
bab9124ad9 3.0.9 2020-11-05 18:36:09 +00:00
fda71ac3e6 fix(core): update 2020-11-05 18:36:08 +00:00
3d6a421d25 3.0.8 2020-11-05 17:56:36 +00:00
a7fca4e0c1 fix(core): update 2020-11-05 17:56:35 +00:00
782c9cd740 3.0.7 2020-11-05 17:27:10 +00:00
b8ab19a683 fix(core): update 2020-11-05 17:27:10 +00:00
e47869caed 3.0.6 2020-11-05 17:15:28 +00:00
4f06c5d7c5 fix(core): update 2020-11-05 17:15:27 +00:00
c0d223959d 3.0.5 2020-11-05 15:35:32 +00:00
c40c01b5c8 fix(core): update 2020-11-05 15:35:31 +00:00
57868de491 3.0.4 2020-11-04 18:31:26 +00:00
ccd68a1257 fix(core): update 2020-11-04 18:31:25 +00:00
c1f82be85f 3.0.3 2020-11-04 18:09:08 +00:00
ca3398c4fd fix(core): update 2020-11-04 18:09:07 +00:00
0884b61099 3.0.2 2020-11-04 18:02:02 +00:00
db8ea28cee fix(core): update 2020-11-04 18:02:02 +00:00
cb898eeef5 3.0.1 2020-11-04 18:01:04 +00:00
7a0d767e9d fix(core): update 2020-11-04 18:01:04 +00:00
49ca240237 3.0.0 2020-09-22 14:26:14 +00:00
c802e8846a BREAKING CHANGE(core): update 2020-09-22 14:26:13 +00:00
1f7be6b8a0 2.0.18 2020-07-08 19:01:56 +00:00
a0cbe170c8 2.0.17 2020-07-08 11:10:20 +00:00
5df46f8b77 fix(core): update 2020-07-08 11:10:20 +00:00
c12e9eaf76 2.0.16 2020-06-27 12:51:34 +00:00
2aa1839c22 fix(core): update 2020-06-27 12:51:34 +00:00
8e4bdb867c 2.0.15 2020-06-27 12:50:45 +00:00
359e18f5dc fix(core): update 2020-06-27 12:50:44 +00:00
751a325c81 2.0.14 2020-03-15 19:11:14 +00:00
93d4bc491f fix(core): update 2020-03-15 19:11:14 +00:00
bdf55a19d9 2.0.13 2020-03-13 11:46:21 +00:00
cd1f68f55e fix(core): update 2020-03-13 11:46:20 +00:00
f2bd7145b3 2.0.12 2020-03-08 15:14:25 +00:00
6d9789df45 fix(core): update 2020-03-08 15:14:24 +00:00
0be8a6f60d 2.0.11 2020-03-08 10:54:12 +00:00
a3793572e7 fix(core): update 2020-03-08 10:54:12 +00:00
6ace59d1d1 2.0.10 2020-03-08 10:48:23 +00:00
b6ddf6a87b 2.0.9 2020-03-07 22:01:04 +00:00
b999627ba5 fix(core): update 2020-03-07 22:01:03 +00:00
5e8a91f302 2.0.8 2020-03-07 16:23:12 +00:00
2fc0613fa6 fix(core): update 2020-03-07 16:23:12 +00:00
2283cdb633 2.0.7 2020-03-07 16:08:22 +00:00
c0db06fc18 fix(core): update 2020-03-07 16:08:21 +00:00
4557000629 2.0.6 2020-03-06 15:26:27 +00:00
78997e1e5a fix(core): update 2020-03-06 15:26:26 +00:00
4d5564e8d4 2.0.5 2020-03-06 15:12:24 +00:00
11d89adc4b fix(core): update 2020-03-06 15:12:23 +00:00
a99fd6374c 2.0.4 2020-03-06 09:57:32 +00:00
ba287cdb76 fix(core): update 2020-03-06 09:57:31 +00:00
5318408037 2.0.3 2019-07-24 11:43:20 +02:00
16ef41ae20 fix(core): update 2019-07-24 11:43:20 +02:00
7375675d7d 2.0.2 2019-07-16 18:54:33 +02:00
68f9221d33 fix(core): update 2019-07-16 18:54:33 +02:00
269e658967 2.0.1 2019-07-16 18:54:19 +02:00
9008aca718 fix(core): update 2019-07-16 18:54:19 +02:00
74d73a0d21 2.0.0 2019-07-16 18:49:16 +02:00
5496c8c482 BREAKING CHANGE(core): remove serviceworker 2019-07-16 18:49:15 +02:00
c748c5102c 1.0.8 2019-03-27 14:58:24 +01:00
308133fe4f fix(core): update 2019-03-27 14:58:24 +01:00
30 changed files with 5161 additions and 1892 deletions

14
.gitignore vendored
View File

@ -1,8 +1,20 @@
.nogit/
node_modules/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,119 +1,122 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
- security
- test
- release
- metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ====================
# security stage
# ====================
mirror:
# ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci git mirror
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --prod
tags:
- docker
- notpriv
- lossless
- docker
allow_failure: true
snyk:
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --dev
tags:
- docker
- notpriv
- lossless
- docker
allow_failure: true
# ====================
# test stage
# ====================
testLTS:
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testSTABLE:
- docker
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
- npmci node install stable
- npmci npm install
- npmci npm build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
- npmci node install stable
- npmci npm publish
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
only:
- tags
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
tags:
- docker
- priv
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
- npmci trigger
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
- npmci command npm run buildDocs
tags:
- lossless
- docker
- notpriv
only:
@ -121,5 +124,5 @@ pages:
artifacts:
expire_in: 1 week
paths:
- public
- public
allow_failure: true

11
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

View File

@ -4,11 +4,12 @@
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "websetup",
"shortDescription": "setup basic page properties",
"description": "setup basic page properties",
"npmPackagename": "@pushrocks/websetup",
"license": "MIT"
}

1617
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,46 @@
{
"name": "@pushrocks/websetup",
"version": "1.0.7",
"version": "3.0.19",
"private": false,
"description": "setup basic page properties",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH",
"license": "MIT",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild --web)",
"format": "(gitzone format)"
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)",
"buildDocs": "tsdoc"
},
"keywords": [
"lossless",
"websafe"
],
"devDependencies": {
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.7",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0"
"@gitzone/tsbuild": "^2.1.65",
"@gitzone/tsbundle": "^2.0.7",
"@gitzone/tstest": "^1.0.74",
"@pushrocks/tapbundle": "^5.0.4"
},
"dependencies": {}
"dependencies": {
"@pushrocks/smartdelay": "^3.0.1",
"@pushrocks/smartpromise": "^4.0.2",
"@tsclass/tsclass": "^4.0.41"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
],
"type": "module"
}

4481
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -8,19 +8,30 @@ setup basic page properties
* [docs (typedoc)](https://pushrocks.gitlab.io/websetup/)
## Status for master
[![build status](https://gitlab.com/pushrocks/websetup/badges/master/build.svg)](https://gitlab.com/pushrocks/websetup/commits/master)
[![coverage report](https://gitlab.com/pushrocks/websetup/badges/master/coverage.svg)](https://gitlab.com/pushrocks/websetup/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/websetup.svg)](https://www.npmjs.com/package/@pushrocks/websetup)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/websetup/badge.svg)](https://snyk.io/test/npm/@pushrocks/websetup)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/websetup/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/websetup/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/websetup)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/websetup)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/websetup)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/websetup)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/websetup)](https://lossless.cloud)
## Usage
Use TypeScript for best in class intellisense.
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)
## Legal
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)

18
test/test.browser.ts Normal file
View File

@ -0,0 +1,18 @@
import { expect, tap, webhelpers } from '@pushrocks/tapbundle';
webhelpers.enable();
import * as websetup from '../ts/index.js';
tap.test('first test', async () => {
const websetupInstance = new websetup.WebSetup({
metaObject: {
description: 'A awesome description',
title: 'mytitle',
canonicalDomain: 'lossless.com',
},
});
await websetupInstance.readyPromise;
expect(document.title).toEqual('mytitle');
});
tap.start();

View File

@ -1,8 +0,0 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as websetup from '../ts/index';
tap.test('first test', async () => {
console.log('Waiting for proper puppeteer support here');
});
tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/websetup',
version: '3.0.19',
description: 'setup basic page properties'
}

View File

@ -1,37 +1,5 @@
import * as plugins from './websetup.plugins';
import { setupGoogleAnalytics } from './tools/ganalytics';
import { setupFullStory } from './tools/fullstory';
import { setupServiceWoker } from './serviceworker';
import { IMetaObject, setupMetaInformation } from './meta';
export interface IWebSetupConstructorOptions {
googleAnalyticsCode?: string;
fsCode?: string;
metaObject: IMetaObject;
serviceworker?: boolean;
}
/**
* the main WebSetup class
*/
export class WebSetup {
constructor(optionsArg: IWebSetupConstructorOptions) {
// most important, lets get the meta information in place
this.setup(optionsArg);
}
async setup(optionsArg: IWebSetupConstructorOptions) {
if (optionsArg.serviceworker) {
await setupServiceWoker();
}
if (optionsArg.googleAnalyticsCode) {
await setupGoogleAnalytics(optionsArg.googleAnalyticsCode);
}
if (optionsArg.fsCode) {
await setupFullStory(optionsArg.fsCode);
}
}
}
export * from './websetup.classes.websetup.js';
export * from './websetup.classes.tag.metatag.js';
export * from './websetup.classes.tag.opengraphtag.js';
export * from './websetup.classes.tag.jsonldtag.js';
export * from './websetup.classes.title.js';

19
ts/interfaces/index.ts Normal file
View File

@ -0,0 +1,19 @@
import * as plugins from '../websetup.plugins.js';
export interface IMetaObject {
title: string;
description?: string;
canonicalDomain?: string;
ldCompany?: plugins.tsclass.business.ICompany;
ldProduct?: plugins.tsclass.saas.IProduct;
// handles
twitterHandle?: string;
facebookHandle?: string;
// links
companyWebsiteLink?: string;
googleNewsLink?: string;
mediumLink?: string;
slackLink?: string;
airmeetLink?: string;
}

View File

@ -1,18 +0,0 @@
export interface IMetaObject {
title: string;
description: string;
}
export const setupMetaInformation = async (metaObjectArg: IMetaObject) => {
document.title = metaObjectArg.title;
addMetaTag('description', metaObjectArg.description);
addMetaTag('google', 'notranslate');
addMetaTag('revisited-after', '1 days');
};
const addMetaTag = async (linkNameArg: string, contentArg: string) => {
const metaElement = document.createElement('meta');
metaElement.name = linkNameArg;
metaElement.content = contentArg;
document.getElementsByTagName('head')[0].appendChild(metaElement);
};

View File

@ -1,11 +0,0 @@
export const setupServiceWoker = async () => {
// serviceworker
const script = document.createElement('script');
script.onload = () => {
console.log(
'Loaded Serviceworker. The serviceworker helps us with notifications and offline capabilities, so you can also read this site when your device is offline.'
);
};
script.src = 'serviceworker/mainthread.js';
document.head.appendChild(script);
};

View File

@ -1,66 +0,0 @@
declare global {
// tslint:disable-next-line: interface-name
interface Window {
_fs_host: any;
}
}
export const setupFullStory = async (fsCodeArg: string) => {
// tslint:disable-next-line: no-string-literal
window['_fs_debug'] = false;
// tslint:disable-next-line: no-string-literal
window['_fs_host'] = 'fullstory.com';
// tslint:disable-next-line: no-string-literal
window['_fs_org'] = fsCodeArg;
// tslint:disable-next-line: no-string-literal
window['_fs_namespace'] = 'FS';
(function(m, n, e, t, l, o, g, y) {
if (e in m) {
if (m.console && m.console.log) {
m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].');
}
return;
}
// tslint:disable-next-line: only-arrow-functions
g = m[e] = function(a, b, s) {
g.q ? g.q.push([a, b, s]) : g._api(a, b, s);
};
g.q = [];
o = n.createElement(t);
o.async = 1;
o.src = 'https://' + window._fs_host + '/s/fs.js';
y = n.getElementsByTagName(t)[0];
y.parentNode.insertBefore(o, y);
// tslint:disable-next-line: only-arrow-functions
g.identify = function(i, v, s) {
g(l, { uid: i }, s);
if (v) g(l, v, s);
};
g.setUserVars = function(v, s) {
g(l, v, s);
};
g.event = function(i, v, s) {
g('event', { n: i, p: v }, s);
};
// tslint:disable-next-line: only-arrow-functions
g.shutdown = function() {
g('rec', !1);
};
g.restart = function() {
g('rec', !0);
};
// tslint:disable-next-line: only-arrow-functions
g.consent = function(a) {
g('consent', !arguments.length || a);
};
// tslint:disable-next-line: only-arrow-functions
g.identifyAccount = function(i, v) {
o = 'account';
v = v || {};
v.acctId = i;
g(o, v);
};
// tslint:disable-next-line: only-arrow-functions
g.clearUserCookie = function() {};
// tslint:disable-next-line: no-string-literal
})(window, document, window['_fs_namespace'], 'script', 'user');
};

View File

@ -1,31 +0,0 @@
declare global {
// tslint:disable-next-line: interface-name
interface Window {
analytics: any;
}
}
export const setupGoogleAnalytics = async (gaCode: string) => {
// tslint:disable-next-line: only-arrow-functions
(function(i, s, o, g, r, a, m) {
// tslint:disable-next-line: no-string-literal
i['GoogleAnalyticsObject'] = r;
// tslint:disable-next-line: ban-comma-operator
(i[r] =
i[r] ||
// tslint:disable-next-line: only-arrow-functions
function() {
(i[r].q = i[r].q || []).push(arguments);
}),
(i[r].l = new Date().getTime());
// tslint:disable-next-line: ban-comma-operator
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m);
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'analytics');
window.analytics('create', gaCode, 'auto');
window.analytics('send', 'pageview');
console.log('Loaded Google Analytics. You may view our privacy policy at https://lossless.gmbh');
};

View File

@ -0,0 +1,106 @@
import * as plugins from './websetup.plugins.js';
import * as interfaces from './interfaces/index.js';
import { Tag } from './websetup.classes.tag.js';
export class JsonLdTag extends Tag {
public static createCompanyJsonLd(companyDataArg: plugins.tsclass.business.ICompany) {
// STATIC
// lets care about linked data
const companyLd = {
'@context': 'https://schema.org',
'@type': 'Corporation',
name: companyDataArg.name,
alternateName: companyDataArg.name.replace(' GmbH', ''),
url: companyDataArg.contact.website,
logo: companyDataArg.contact.logoUrl,
contactPoint: {
'@type': 'ContactPoint',
telephone: companyDataArg.contact.phone,
contactType: 'customer service',
areaServed: 'DE',
availableLanguage: ['en', 'German'],
},
sameAs: [],
};
if (companyDataArg.contact.facebookUrl) {
companyLd.sameAs.push(companyDataArg.contact.facebookUrl);
}
if (companyDataArg.contact.twitterUrl) {
companyLd.sameAs.push(companyDataArg.contact.twitterUrl);
}
const ldTag = new JsonLdTag(companyLd);
return ldTag;
}
public static createNewsArticleJsonLd(newsArticleArg: plugins.tsclass.content.IArticle) {
const newsArticleLd = {
'@context': 'https://schema.org',
'@type': 'NewsArticle',
mainEntityOfPage: {
'@type': 'WebPage',
'@id': window.location.href,
},
headline: 'Article headline',
image: [newsArticleArg.featuredImageUrl],
datePublished: new Date(newsArticleArg.timestamp).toISOString(),
dateModified: new Date(newsArticleArg.timestamp).toISOString(),
author: {
'@type': 'Person',
name: `${newsArticleArg.author.firstName} ${newsArticleArg.author.surName}`,
},
publisher: {
'@type': 'Organization',
name: newsArticleArg.author.surName, // TODO
logo: {
'@type': 'ImageObject',
url: newsArticleArg.author.surName, // TODO
},
},
description: newsArticleArg.author.firstName,
};
const ldTag = new JsonLdTag(newsArticleLd);
return ldTag;
}
public static createProductJsonLd(
productArg: plugins.tsclass.saas.IProduct,
publisherArg: plugins.tsclass.business.ICompany
) {
const productLd = {
'@context': 'https://schema.org',
'@type': 'SoftwareApplication',
name: productArg.name,
description: productArg.description,
operatingSystem: productArg.os,
applicationCategory: productArg.category,
offers: {
'@type': 'Offer',
name: 'User-based Plan',
priceSpecification: {
'@type': 'PropertyValueSpecification',
valueName: 'Number of Users',
valueRequired: true,
price: '4.99',
priceCurrency: 'EUR',
},
},
publisher: this.createCompanyJsonLd(publisherArg).elementRef.textContent,
screenshot: 'https://www.social.io/screenshot.png',
url: 'https://www.social.io/',
};
const ldTag = new JsonLdTag(productLd);
return ldTag;
}
// INSTANCE
constructor(ldObjectArg: any) {
super();
const jsonLdElement = document.createElement('script');
jsonLdElement.type = 'application/ld+json';
jsonLdElement.text = JSON.stringify(ldObjectArg);
this.elementRef = jsonLdElement;
}
}

View File

@ -0,0 +1,13 @@
import { Tag } from './websetup.classes.tag.js';
export class LinkTag extends Tag {
constructor(relArg: string, hrefArg: string) {
super();
const linkElement = !!document.querySelector("link[rel='canonical']")
? document.querySelector("link[rel='canonical']")
: document.createElement('link');
linkElement.setAttribute('rel', relArg);
linkElement.setAttribute('href', hrefArg);
this.elementRef = linkElement;
}
}

View File

@ -0,0 +1,11 @@
import { Tag } from './websetup.classes.tag.js';
export class MetaTag extends Tag {
constructor(metaNameArg: string, contentArg: string) {
super();
const metaElement = document.createElement('meta');
metaElement.name = metaNameArg;
metaElement.content = contentArg;
this.elementRef = metaElement;
}
}

View File

@ -0,0 +1,31 @@
import * as plugins from './websetup.plugins.js';
import { Tag } from './websetup.classes.tag.js';
export class OpengraphTag extends Tag {
public static createNewsArticleOgTags(newsArticleArg: plugins.tsclass.content.IArticle) {
const tagArray: OpengraphTag[] = [];
tagArray.push(new OpengraphTag('og:url', newsArticleArg.url));
tagArray.push(new OpengraphTag('og:title', newsArticleArg.title));
tagArray.push(new OpengraphTag('og:description', newsArticleArg.content));
tagArray.push(new OpengraphTag('og:image', newsArticleArg.featuredImageUrl));
return tagArray;
}
public static createProductOgTags(productArg: plugins.tsclass.saas.IProduct) {
const tagArray: OpengraphTag[] = [];
tagArray.push(new OpengraphTag('og:url', globalThis.location.href));
tagArray.push(new OpengraphTag('og:title', `${productArg.name} - ${productArg.slogan}`));
tagArray.push(new OpengraphTag('og:site_name', productArg.name))
tagArray.push(new OpengraphTag('og:description', productArg.description));
tagArray.push(new OpengraphTag('og:image', productArg.logoLink));
return tagArray;
}
constructor(propertyNameArg: string, contentArg: string) {
super();
const openGraphElement = document.createElement('meta');
openGraphElement.setAttribute('property', propertyNameArg);
openGraphElement.content = contentArg;
this.elementRef = openGraphElement;
}
}

View File

@ -0,0 +1,21 @@
import * as plugins from './websetup.plugins.js';
export class Tag {
public elementRef: Element;
public tagLevel: 'global' | 'levelbound';
public appendToDom() {
if (!this.elementRef.parentElement && !this.elementRef.parentNode) {
document.getElementsByTagName('head')[0].appendChild(this.elementRef);
}
}
public removeFromDom() {
if (this.elementRef.parentElement) {
this.elementRef.parentElement.removeChild(this.elementRef);
} else if (this.elementRef.parentNode) {
this.elementRef.parentNode.removeChild(this.elementRef);
}
}
}

View File

@ -0,0 +1,104 @@
import { Tag } from './websetup.classes.tag.js';
import { JsonLdTag } from './websetup.classes.tag.jsonldtag.js';
import { OpengraphTag } from './websetup.classes.tag.opengraphtag.js';
import { TagManager } from './websetup.classes.tagmanager.js';
import * as plugins from './websetup.plugins.js';
export type TBaseLevelType = 'global' | 'base' | 'subpage';
export type TLevelState = 'enabled' | 'disabled';
export class TagLevel {
public tagManagerRef: TagManager;
private titleStore: string;
public set title(titleArg: string) {
this.titleStore = titleArg;
if (this.state === 'enabled') {
document.title = this.titleStore;
}
}
public get title() {
return this.titleStore;
}
public type: TBaseLevelType;
public tags: Tag[] = [];
public state: TLevelState = 'disabled';
constructor(tagManagerRefArg: TagManager, levelType: TBaseLevelType) {
this.tagManagerRef = tagManagerRefArg;
}
public addTag(tagArg: Tag | Tag[]) {
if (tagArg instanceof Array) {
for (const tagArg2 of tagArg) {
this.addTag(tagArg2);
}
} else {
this.tags.push(tagArg);
if (this.state === 'enabled') {
tagArg.appendToDom();
}
}
}
public async addCompanyInfo(companyDataArg: plugins.tsclass.business.ICompany) {
this.addTag(JsonLdTag.createCompanyJsonLd(companyDataArg));
// lets care about open graph
this.addTag(new OpengraphTag('og:type', 'business.business'));
this.addTag(new OpengraphTag('og:title', companyDataArg.name));
this.addTag(new OpengraphTag('og:url', companyDataArg.contact.website));
this.addTag(new OpengraphTag('og:image', companyDataArg.contact.logoUrl));
this.addTag(
new OpengraphTag(
'business:contact_data:street_address',
`${companyDataArg.contact.address.streetName} ${companyDataArg.contact.address.houseNumber}`
)
);
this.addTag(
new OpengraphTag('business:contact_data:locality', companyDataArg.contact.address.postalCode)
);
this.addTag(
new OpengraphTag('business:contact_data:region', companyDataArg.contact.address.city)
);
this.addTag(
new OpengraphTag(
'business:contact_data:postal_code',
companyDataArg.contact.address.postalCode
)
);
this.addTag(
new OpengraphTag('business:contact_data:country_name', companyDataArg.contact.address.country)
);
}
public addNewsArticleInfo(articleArg: plugins.tsclass.content.IArticle) {
this.addTag(JsonLdTag.createNewsArticleJsonLd(articleArg));
this.addTag(OpengraphTag.createNewsArticleOgTags(articleArg));
}
public addProductInfo(productArg: plugins.tsclass.saas.IProduct, companyArg: plugins.tsclass.business.ICompany) {
this.addTag(JsonLdTag.createProductJsonLd(productArg, companyArg));
this.addTag(OpengraphTag.createProductOgTags(productArg));
}
public async enable() {
if (this.title) {
document.title = this.title;
}
for (const tagArg of this.tags) {
tagArg.appendToDom();
}
this.state = 'enabled';
}
public async disable() {
for (const tagArg of this.tags) {
tagArg.removeFromDom();
}
this.state = 'disabled';
}
}

View File

@ -0,0 +1,71 @@
import { TagLevel } from './websetup.classes.taglevel.js';
import * as plugins from './websetup.plugins.js';
import * as interfaces from './interfaces/index.js';
import { MetaTag } from './websetup.classes.tag.metatag.js';
import { JsonLdTag } from './websetup.classes.tag.jsonldtag.js';
import { OpengraphTag } from './websetup.classes.tag.opengraphtag.js';
export class TagManager {
public globalLevel: TagLevel = new TagLevel(this, 'global');
public baseLevel: TagLevel = new TagLevel(this, 'base');
public activeLevel: TagLevel;
public async setup(metaObjectArg: interfaces.IMetaObject) {
// global tag level
this.globalLevel.addTag(new MetaTag('google', 'notranslate'));
this.globalLevel.addTag(new MetaTag('revisit-after', '1 days'));
if (metaObjectArg.twitterHandle) {
this.globalLevel.addTag(new MetaTag('twitter:card', 'summary_large_image'));
this.globalLevel.addTag(new MetaTag('twitter:site', metaObjectArg.twitterHandle));
this.globalLevel.addTag(new MetaTag('twitter:creator', metaObjectArg.twitterHandle));
}
// base tag level
this.baseLevel.title = metaObjectArg.title;
if (metaObjectArg.description) {
this.baseLevel.addTag(new MetaTag('description', metaObjectArg.description));
}
if (metaObjectArg.canonicalDomain) {
this.baseLevel.addTag(new MetaTag('canonical', metaObjectArg.canonicalDomain));
}
// json ld
switch (true) {
case metaObjectArg.ldCompany && !metaObjectArg.ldProduct:
this.baseLevel.addCompanyInfo(metaObjectArg.ldCompany);
break;
case !!metaObjectArg.ldProduct:
this.baseLevel.addProductInfo(metaObjectArg.ldProduct, metaObjectArg.ldCompany);
break;
}
await this.globalLevel.enable();
this.activeLevel = this.baseLevel;
await this.activeLevel.enable();
}
public async setSubPageLevel(metaObjectArg: interfaces.IMetaObject) {
const subPageLevel = new TagLevel(this, 'subpage');
subPageLevel.title = metaObjectArg.title;
if (metaObjectArg.description) {
subPageLevel.addTag(new MetaTag('description', metaObjectArg.description));
}
await this.activeLevel.disable();
this.activeLevel = subPageLevel;
await this.activeLevel.enable();
return subPageLevel;
}
public async revertToBaseLevel() {
if (this.activeLevel !== this.baseLevel) {
await this.activeLevel.disable();
this.activeLevel = this.baseLevel;
await this.activeLevel.enable();
}
}
}

View File

@ -0,0 +1,7 @@
import * as plugins from './websetup.plugins.js';
/**
* a title proxy class
* --> to be used in the future when flashing titles is supported
*/
export class Title {}

View File

@ -0,0 +1,78 @@
import * as plugins from './websetup.plugins.js';
import * as interfaces from './interfaces/index.js';
import { TagManager } from './websetup.classes.tagmanager.js';
import { TagLevel } from './websetup.classes.taglevel.js';
export interface IWebSetupConstructorOptions {
metaObject: interfaces.IMetaObject;
smartssrWaitForReadySignal?: boolean;
}
/**
* the main WebSetup class
*/
export class WebSetup {
public tagManager: TagManager = new TagManager();
public options: IWebSetupConstructorOptions;
// private deferreds
private readyDeferred = plugins.smartpromise.defer();
private readyForSmartssrDeferred = plugins.smartpromise.defer();
// public promises
public readyPromise = this.readyDeferred.promise;
public readyForSmartssrPromise = this.readyForSmartssrDeferred.promise;
constructor(optionsArg: IWebSetupConstructorOptions) {
this.options = optionsArg;
this.setup().then(() => {
this.readyDeferred.resolve();
if (!this.options.smartssrWaitForReadySignal) {
this.readyForSmartssrDeferred.resolve();
}
});
}
/**
* an async setup called by the constructor
*/
public async setup(optionsArg?: IWebSetupConstructorOptions) {
if (optionsArg) {
this.options = optionsArg;
}
await this.tagManager.setup(this.options.metaObject);
}
/**
* reverts the active level and returns to the base level
*/
public revertToBaseLevel() {
this.tagManager.revertToBaseLevel();
}
/**
* sets a subpage
* @param metaObjectArg
*/
public async setSubLevel(metaObjectArg: interfaces.IMetaObject) {
const subLevel = await this.tagManager.setSubPageLevel(metaObjectArg);
return subLevel;
}
/**
* flashes the title with the given text
* @param flashTextArg
*/
public flashTitle(flashTextArg: string) {}
/**
* informs smartssr that the page is ready to be rendered
*/
public informReadyForSmartssr() {
if (!this.options.smartssrWaitForReadySignal) {
console.error(
`You have not indicated that you inform smartssr by a dedicated signal! Please consider doing so!`
);
}
this.readyForSmartssrDeferred.resolve();
}
}

View File

@ -1,2 +1,10 @@
const removeme = {};
export { removeme };
// pushrocks scope
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartpromise from '@pushrocks/smartpromise';
export { smartdelay, smartpromise };
// tsclass scope
import * as tsclass from '@tsclass/tsclass';
export { tsclass };

10
tsconfig.json Normal file
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true
}
}

View File

@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}