Compare commits

..

66 Commits

Author SHA1 Message Date
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
cb80b4df75 1.0.7 2019-03-27 14:46:42 +01:00
74ed988da0 fix(core): update 2019-03-27 14:46:41 +01:00
d1793f9084 1.0.6 2019-03-27 14:40:07 +01:00
4a45262124 fix(core): update 2019-03-27 14:40:06 +01:00
f5f51ac1a6 1.0.5 2019-03-27 14:38:25 +01:00
eb4a4288ed fix(core): update 2019-03-27 14:38:24 +01:00
23 changed files with 10899 additions and 948 deletions

14
.gitignore vendored
View File

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

View File

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

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

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

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

@ -2,5 +2,16 @@
"npmci": { "npmci": {
"npmGlobalTools": [], "npmGlobalTools": [],
"npmAccessLevel": "public" "npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "websetup",
"shortDescription": "setup basic page properties",
"npmPackagename": "@pushrocks/websetup",
"license": "MIT"
}
} }
} }

11035
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +1,46 @@
{ {
"name": "@pushrocks/websetup", "name": "@pushrocks/websetup",
"version": "1.0.4", "version": "3.0.10",
"private": false, "private": false,
"description": "setup basic page properties", "description": "setup basic page properties",
"main": "dist/index.js", "main": "dist_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"build": "(tsbuild)", "build": "(tsbuild --web && tsbundle npm)"
"format": "(gitzone format)"
}, },
"keywords": [
"lossless",
"websafe"
],
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.15", "@gitzone/tsbundle": "^1.0.78",
"@pushrocks/tapbundle": "^3.0.7", "@gitzone/tstest": "^1.0.52",
"tslint": "^5.11.0", "@pushrocks/tapbundle": "^3.2.9",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": {} "dependencies": {
"@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartpromise": "^3.1.3",
"@tsclass/tsclass": "^3.0.29"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
} }

39
readme.md Normal file
View File

@ -0,0 +1,39 @@
# @pushrocks/websetup
setup basic page properties
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/websetup)
* [gitlab.com (source)](https://gitlab.com/pushrocks/websetup)
* [github.com (source mirror)](https://github.com/pushrocks/websetup)
* [docs (typedoc)](https://pushrocks.gitlab.io/websetup/)
## Status for master
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)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](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)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

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

@ -0,0 +1,16 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as websetup from '../ts/index';
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).to.equal('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(websetup.standardExport)
})
tap.start()

View File

@ -1,24 +1,4 @@
import * as plugins from './websetup.plugins'; export * from './websetup.classes.websetup';
export * from './websetup.classes.tag.metatag';
import { setupGoogleAnalytics } from './tools/ganalytics'; export * from './websetup.classes.tag.opengraphtag';
import { setupFullStory } from './tools/fullstory'; export * from './websetup.classes.tag.jsonldtag';
export interface IWebSetupConstructorOptions {
googleAnalyticsCode?: string;
fsCode?: string;
}
/**
* the main WebSetup class
*/
export class WebSetup {
constructor(optionsArg: IWebSetupConstructorOptions) {
if (optionsArg.googleAnalyticsCode) {
setupGoogleAnalytics(optionsArg.googleAnalyticsCode);
}
if (optionsArg.fsCode) {
setupFullStory(optionsArg.fsCode)
}
}
}

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

@ -0,0 +1,9 @@
import * as plugins from '../websetup.plugins';
export interface IMetaObject {
title: string;
description?: string;
canonicalDomain?: string;
ldCompany?: plugins.tsclass.business.ICompany;
ldProduct?: any;
}

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,77 @@
import * as plugins from './websetup.plugins';
import * as interfaces from './interfaces';
import { Tag } from './websetup.classes.tag';
export class JsonLdTag extends Tag {
public static createCompanyLd(companyDataArg: plugins.tsclass.business.ICompany) {
// 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 createNewsArticleLd (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(newsArticleArg);
return ldTag;
}
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';
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';
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,11 @@
import { Tag } from './websetup.classes.tag';
export class OpengraphTag extends Tag {
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';
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,92 @@
import { Tag } from './websetup.classes.tag';
import { JsonLdTag } from './websetup.classes.tag.jsonldtag';
import { OpengraphTag } from './websetup.classes.tag.opengraphtag';
import { TagManager } from './websetup.classes.tagmanager';
import * as plugins from './websetup.plugins';
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) {
this.tags.push(tagArg);
if (this.state === 'enabled') {
tagArg.appendToDom();
}
}
public async addCompanyInfo(companyDataArg: plugins.tsclass.business.ICompany) {
this.addTag(JsonLdTag.createCompanyLd(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.createNewsArticleLd(articleArg));
}
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,57 @@
import { TagLevel } from './websetup.classes.taglevel';
import * as plugins from './websetup.plugins';
import * as interfaces from './interfaces';
import { MetaTag } from './websetup.classes.tag.metatag';
import { JsonLdTag } from './websetup.classes.tag.jsonldtag';
import { OpengraphTag } from './websetup.classes.tag.opengraphtag';
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'));
// 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));
}
if (metaObjectArg.ldCompany) {
this.baseLevel.addCompanyInfo(metaObjectArg.ldCompany);
}
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,52 @@
import * as plugins from './websetup.plugins';
import * as interfaces from './interfaces';
import { TagManager } from './websetup.classes.tagmanager';
import { TagLevel } from './websetup.classes.taglevel';
export interface IWebSetupConstructorOptions {
metaObject: interfaces.IMetaObject;
}
/**
* the main WebSetup class
*/
export class WebSetup {
public tagManager: TagManager = new TagManager();
public options: IWebSetupConstructorOptions;
private readyDeferred = plugins.smartpromise.defer();
public readyPromise = this.readyDeferred.promise;
constructor(optionsArg: IWebSetupConstructorOptions) {
this.options = optionsArg;
this.setup().then(() => {
this.readyDeferred.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;
}
public flashTitle(flashTextArg: string) {}
}

View File

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