Compare commits
48 Commits
Author | SHA1 | Date | |
---|---|---|---|
e8438140a7 | |||
3d2e5e48c1 | |||
fa9f2afbad | |||
7a895c15ab | |||
2f04d66ec5 | |||
6acfddb70d | |||
c34d71238a | |||
2f4fd839a1 | |||
bd8585aa42 | |||
e4f8e53066 | |||
d381f8adad | |||
d1c0501461 | |||
f5d33bdebe | |||
2b9c9225a5 | |||
5ce55190fe | |||
8fb071f57b | |||
3278ef7425 | |||
11282daa38 | |||
1fe7dd8d06 | |||
9175cb7841 | |||
6b9ebcec7a | |||
2159995342 | |||
7fa14ceabd | |||
0294895f78 | |||
74fc97a220 | |||
bab9124ad9 | |||
fda71ac3e6 | |||
3d6a421d25 | |||
a7fca4e0c1 | |||
782c9cd740 | |||
b8ab19a683 | |||
e47869caed | |||
4f06c5d7c5 | |||
c0d223959d | |||
c40c01b5c8 | |||
57868de491 | |||
ccd68a1257 | |||
c1f82be85f | |||
ca3398c4fd | |||
0884b61099 | |||
db8ea28cee | |||
cb898eeef5 | |||
7a0d767e9d | |||
49ca240237 | |||
c802e8846a | |||
1f7be6b8a0 | |||
a0cbe170c8 | |||
5df46f8b77 |
@ -12,30 +12,38 @@ stages:
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- pnpm install -g pnpm
|
||||
- pnpm install -g @shipzone/npmci
|
||||
- npmci npm prepare
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
audit:
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command pnpm audit --audit-level=high --prod
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command pnpm audit --audit-level=high --dev
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
@ -44,28 +52,22 @@ audit:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- npmci npm build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
@ -85,11 +87,12 @@ release:
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
@ -109,11 +112,9 @@ trigger:
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"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"
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm"]
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,29 @@
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "websetup",
|
||||
"shortDescription": "setup basic page properties",
|
||||
"npmPackagename": "@pushrocks/websetup",
|
||||
"license": "MIT"
|
||||
"description": "A library for setting up basic properties of a web page including meta tags, OpenGraph tags, JSON-LD structured data, with support for dynamic content.",
|
||||
"npmPackagename": "@push.rocks/websetup",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"web development",
|
||||
"SEO",
|
||||
"OpenGraph",
|
||||
"JSON-LD",
|
||||
"meta tags",
|
||||
"structured data",
|
||||
"TypeScript",
|
||||
"dynamic content",
|
||||
"website setup",
|
||||
"smart delay",
|
||||
"smart promise",
|
||||
"tag management"
|
||||
]
|
||||
}
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
4751
package-lock.json
generated
4751
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
48
package.json
48
package.json
@ -1,30 +1,41 @@
|
||||
{
|
||||
"name": "@pushrocks/websetup",
|
||||
"version": "2.0.16",
|
||||
"name": "@push.rocks/websetup",
|
||||
"version": "3.0.19",
|
||||
"private": false,
|
||||
"description": "setup basic page properties",
|
||||
"description": "A library for setting up basic properties of a web page including meta tags, OpenGraph tags, JSON-LD structured data, with support for dynamic content.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web && tsbundle npm)"
|
||||
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"keywords": [
|
||||
"lossless",
|
||||
"websafe"
|
||||
"web development",
|
||||
"SEO",
|
||||
"OpenGraph",
|
||||
"JSON-LD",
|
||||
"meta tags",
|
||||
"structured data",
|
||||
"TypeScript",
|
||||
"dynamic content",
|
||||
"website setup",
|
||||
"smart delay",
|
||||
"smart promise",
|
||||
"tag management"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.22",
|
||||
"@gitzone/tsbundle": "^1.0.57",
|
||||
"@gitzone/tstest": "^1.0.28",
|
||||
"@pushrocks/tapbundle": "^3.2.1",
|
||||
"tslint": "^6.1.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": {
|
||||
"@tsclass/tsclass": "^3.0.18"
|
||||
"@pushrocks/smartdelay": "^3.0.1",
|
||||
"@pushrocks/smartpromise": "^4.0.2",
|
||||
"@tsclass/tsclass": "^4.0.41"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
@ -37,5 +48,14 @@
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"type": "module",
|
||||
"homepage": "https://code.foss.global/push.rocks/websetup",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/websetup.git"
|
||||
}
|
||||
}
|
4481
pnpm-lock.yaml
generated
Normal file
4481
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
166
readme.md
166
readme.md
@ -1,39 +1,151 @@
|
||||
# @pushrocks/websetup
|
||||
# @push.rocks/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/)
|
||||
## Install
|
||||
To install @push.rocks/websetup, you can use npm (Node Package Manager). Simply run the following command in your terminal:
|
||||
|
||||
## Status for master
|
||||
```bash
|
||||
npm install @push.rocks/websetup --save
|
||||
```
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
This will download the package and add it to your project's `node_modules` directory, as well as save it as a dependency in your project's `package.json` file.
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class intellisense.
|
||||
To use @push.rocks/websetup in your web applications to set up basic page properties efficiently, follow these steps and guidelines. The examples are provided using ECMAScript modules (ESM) syntax along with TypeScript for type safety and better tooling support.
|
||||
|
||||
## Contribution
|
||||
First, ensure you import the necessary modules from @push.rocks/websetup in your TypeScript files:
|
||||
|
||||
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). :)
|
||||
```typescript
|
||||
// Import the main class `WebSetup` from the package
|
||||
import { WebSetup } from '@push.rocks/websetup';
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
### Basic Setup
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
Begin by creating an instance of `WebSetup` with basic page properties. This example demonstrates setting up page title, description, and canonical URL.
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
```typescript
|
||||
// Create a WebSetup instance with basic meta information
|
||||
const webSetup = new WebSetup({
|
||||
metaObject: {
|
||||
title: 'Example Page Title',
|
||||
description: 'This is a description of the example page.',
|
||||
canonicalDomain: 'https://www.example.com',
|
||||
},
|
||||
});
|
||||
|
||||
// Wait for the setup to complete
|
||||
webSetup.readyPromise.then(() => {
|
||||
console.log('WebSetup is ready.');
|
||||
});
|
||||
```
|
||||
|
||||
### Advanced Usage
|
||||
|
||||
#### Setting up Structured Data with JSON-LD
|
||||
|
||||
Structured data is crucial for SEO and enhancing your page's appearance in search results. @push.rocks/websetup allows you to easily setup company, product, or news article information using JSON-LD.
|
||||
|
||||
```typescript
|
||||
// Define company information
|
||||
const companyInfo = {
|
||||
name: 'Example Company Inc.',
|
||||
contact: {
|
||||
website: 'https://www.example.com',
|
||||
logoUrl: 'https://www.example.com/logo.png',
|
||||
phone: '+1234567890',
|
||||
facebookUrl: 'https://facebook.com/example',
|
||||
twitterUrl: 'https://twitter.com/example',
|
||||
},
|
||||
};
|
||||
|
||||
// Pass the company information to WebSetup
|
||||
const webSetupWithCompanyInfo = new WebSetup({
|
||||
metaObject: {
|
||||
title: 'Example Page Title',
|
||||
ldCompany: companyInfo,
|
||||
},
|
||||
});
|
||||
|
||||
// For products
|
||||
const productInfo = {
|
||||
name: 'Example Product',
|
||||
description: 'A detailed description of the example product.',
|
||||
os: 'Web',
|
||||
category: 'SaaS',
|
||||
logoLink: 'https://www.example.com/product-logo.png',
|
||||
};
|
||||
|
||||
// Pass the product information along with company information for structured data setup
|
||||
const webSetupWithProductInfo = new WebSetup({
|
||||
metaObject: {
|
||||
title: 'Product Page Title',
|
||||
ldProduct: productInfo,
|
||||
ldCompany: companyInfo,
|
||||
},
|
||||
});
|
||||
|
||||
// Wait for setup completion
|
||||
webSetupWithProductInfo.readyPromise.then(() => {
|
||||
console.log('WebSetup with product info is ready.');
|
||||
});
|
||||
```
|
||||
|
||||
#### Dynamic Subpage Levels
|
||||
|
||||
You might have a web application where different "subpages" or sections require different meta tags (e.g., title, description). You can dynamically set these properties without recreating the WebSetup instance.
|
||||
|
||||
```typescript
|
||||
// Assume `webSetup` is an existing instance of WebSetup
|
||||
|
||||
// Define meta object for a new subpage
|
||||
const subPageMeta = {
|
||||
title: 'Subpage Title',
|
||||
description: 'Description for the subpage.',
|
||||
};
|
||||
|
||||
// Dynamically set the subpage level
|
||||
webSetup.setSubLevel(subPageMeta).then(() => {
|
||||
console.log('Subpage meta tags are set.');
|
||||
});
|
||||
|
||||
// Revert to base level when leaving the subpage
|
||||
webSetup.revertToBaseLevel();
|
||||
```
|
||||
|
||||
This approach allows developers to manage site-wide and subpage-specific properties efficiently, enhancing user experience and SEO.
|
||||
|
||||
### Handling Ready for Server-Side Rendering (SSR)
|
||||
|
||||
For projects using server-side rendering (SSR), it is essential to signal when the page is ready to be captured. This is especially useful when using SSR solutions like smartSSR that wait for a signal from the client.
|
||||
|
||||
```typescript
|
||||
// Inform that the page is ready for SSR capture
|
||||
webSetup.informReadyForSmartssr();
|
||||
```
|
||||
|
||||
Note: This feature should be used if you have `smartssrWaitForReadySignal` option enabled during the `WebSetup` initialization.
|
||||
|
||||
### Conclusion
|
||||
|
||||
The `@push.rocks/websetup` package provides a streamlined way to manage basic page properties, structured data using JSON-LD for SEO, and dynamic settings for different page sections or states. By following the examples above and integrating @push.rocks/websetup into your projects, you can improve your web application's SEO, maintainability, and developer experience.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
|
18
test/test.browser.ts
Normal file
18
test/test.browser.ts
Normal 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();
|
@ -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
8
ts/00_commitinfo_data.ts
Normal 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'
|
||||
}
|
38
ts/index.ts
38
ts/index.ts
@ -1,33 +1,5 @@
|
||||
import * as plugins from './websetup.plugins';
|
||||
|
||||
import { setupGoogleAnalytics } from './tools/ganalytics';
|
||||
import { setupFullStory } from './tools/fullstory';
|
||||
import { IMetaObject, setupMetaInformation } from './meta';
|
||||
|
||||
export interface IWebSetupConstructorOptions {
|
||||
googleAnalyticsCode?: string;
|
||||
fsCode?: string;
|
||||
metaObject: IMetaObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* the main WebSetup class
|
||||
*/
|
||||
export class WebSetup {
|
||||
public options: IWebSetupConstructorOptions;
|
||||
constructor(optionsArg: IWebSetupConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
}
|
||||
|
||||
public async setup() {
|
||||
await setupMetaInformation(this.options.metaObject);
|
||||
|
||||
if (this.options.googleAnalyticsCode) {
|
||||
await setupGoogleAnalytics(this.options.googleAnalyticsCode);
|
||||
}
|
||||
|
||||
if (this.options.fsCode) {
|
||||
await setupFullStory(this.options.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
19
ts/interfaces/index.ts
Normal 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;
|
||||
}
|
122
ts/meta/index.ts
122
ts/meta/index.ts
@ -1,122 +0,0 @@
|
||||
import * as plugins from '../websetup.plugins';
|
||||
|
||||
export interface IMetaObject {
|
||||
title: string;
|
||||
description: string;
|
||||
canonicalDomain?: string;
|
||||
ldCompany?: plugins.tsclass.business.ICompany;
|
||||
ldProduct?: any;
|
||||
}
|
||||
|
||||
export const setupMetaInformation = async (metaObjectArg: IMetaObject) => {
|
||||
document.title = metaObjectArg.title;
|
||||
addMetaTag('description', metaObjectArg.description);
|
||||
addMetaTag('google', 'notranslate');
|
||||
addMetaTag('revisit-after', '1 days');
|
||||
metaObjectArg.canonicalDomain ? addLinkTag('canonical', metaObjectArg.canonicalDomain) : null;
|
||||
|
||||
if (metaObjectArg.ldCompany) {
|
||||
addCompanyInfo(metaObjectArg.ldCompany);
|
||||
}
|
||||
};
|
||||
|
||||
const addMetaTag = async (metaNameArg: string, contentArg: string) => {
|
||||
const metaElement = document.createElement('meta');
|
||||
metaElement.name = metaNameArg;
|
||||
metaElement.content = contentArg;
|
||||
document.getElementsByTagName('head')[0].appendChild(metaElement);
|
||||
};
|
||||
|
||||
const addLinkTag = async (relArg, hrefArg): Promise<Element> => {
|
||||
const link = !!document.querySelector("link[rel='canonical']")
|
||||
? document.querySelector("link[rel='canonical']")
|
||||
: document.createElement('link');
|
||||
link.setAttribute('rel', relArg);
|
||||
link.setAttribute('href', hrefArg);
|
||||
document.head.appendChild(link);
|
||||
return link;
|
||||
};
|
||||
|
||||
const addOpenGraphProperty = async (
|
||||
propertyNameArg: string,
|
||||
contentArg: string
|
||||
): Promise<Element> => {
|
||||
const openGraphElement = document.createElement('meta');
|
||||
openGraphElement.setAttribute('property', propertyNameArg);
|
||||
openGraphElement.content = contentArg;
|
||||
document.getElementsByTagName('head')[0].appendChild(openGraphElement);
|
||||
return openGraphElement;
|
||||
};
|
||||
|
||||
const addCompanyInfo = async (
|
||||
companyDataArg: plugins.tsclass.business.ICompany
|
||||
): Promise<Element[]> => {
|
||||
const returnElementArray: Element[] = [];
|
||||
|
||||
// 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 jsonLdElement = document.createElement('script');
|
||||
jsonLdElement.type = 'application/ld+json';
|
||||
jsonLdElement.text = JSON.stringify(companyLd);
|
||||
document.querySelector('head').appendChild(jsonLdElement);
|
||||
returnElementArray.push(jsonLdElement);
|
||||
|
||||
// lets care about open graph
|
||||
returnElementArray.push(await addOpenGraphProperty('og:type', 'business.business'));
|
||||
returnElementArray.push(await addOpenGraphProperty('og:title', companyDataArg.name));
|
||||
returnElementArray.push(await addOpenGraphProperty('og:url', companyDataArg.contact.website));
|
||||
returnElementArray.push(await addOpenGraphProperty('og:image', companyDataArg.contact.logoUrl));
|
||||
returnElementArray.push(
|
||||
await addOpenGraphProperty(
|
||||
'business:contact_data:street_address',
|
||||
`${companyDataArg.contact.address.streetName} ${companyDataArg.contact.address.houseNumber}`
|
||||
)
|
||||
);
|
||||
returnElementArray.push(
|
||||
await addOpenGraphProperty(
|
||||
'business:contact_data:locality',
|
||||
companyDataArg.contact.address.postalCode
|
||||
)
|
||||
);
|
||||
returnElementArray.push(
|
||||
await addOpenGraphProperty('business:contact_data:region', companyDataArg.contact.address.city)
|
||||
);
|
||||
returnElementArray.push(
|
||||
await addOpenGraphProperty(
|
||||
'business:contact_data:postal_code',
|
||||
companyDataArg.contact.address.postalCode
|
||||
)
|
||||
);
|
||||
returnElementArray.push(
|
||||
await addOpenGraphProperty(
|
||||
'business:contact_data:country_name',
|
||||
companyDataArg.contact.address.country
|
||||
)
|
||||
);
|
||||
|
||||
return returnElementArray;
|
||||
};
|
@ -1,70 +0,0 @@
|
||||
declare global {
|
||||
// tslint:disable-next-line: interface-name
|
||||
interface Window {
|
||||
_fs_debug: boolean;
|
||||
_fs_host: any;
|
||||
_fs_org: string;
|
||||
_fs_namespace: string;
|
||||
}
|
||||
}
|
||||
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';
|
||||
((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';
|
||||
o.crossorigin = 'anonymous';
|
||||
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');
|
||||
};
|
@ -1,32 +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;
|
||||
a.crossorigin = 'anonymous';
|
||||
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');
|
||||
};
|
106
ts/websetup.classes.tag.jsonldtag.ts
Normal file
106
ts/websetup.classes.tag.jsonldtag.ts
Normal 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;
|
||||
}
|
||||
}
|
13
ts/websetup.classes.tag.linktag.ts
Normal file
13
ts/websetup.classes.tag.linktag.ts
Normal 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;
|
||||
}
|
||||
}
|
11
ts/websetup.classes.tag.metatag.ts
Normal file
11
ts/websetup.classes.tag.metatag.ts
Normal 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;
|
||||
}
|
||||
}
|
43
ts/websetup.classes.tag.opengraphtag.ts
Normal file
43
ts/websetup.classes.tag.opengraphtag.ts
Normal file
@ -0,0 +1,43 @@
|
||||
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:type', 'product'));
|
||||
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;
|
||||
}
|
||||
|
||||
public static createCompanyOgTags(companyArg: plugins.tsclass.business.ICompany) {
|
||||
const tagArray: OpengraphTag[] = [];
|
||||
tagArray.push(new OpengraphTag('og:type', 'company'));
|
||||
tagArray.push(new OpengraphTag('og:url', globalThis.location.href));
|
||||
tagArray.push(new OpengraphTag('og:title', `${companyArg.name} - ${companyArg.slogan}`));
|
||||
tagArray.push(new OpengraphTag('og:site_name', companyArg.name))
|
||||
tagArray.push(new OpengraphTag('og:description', companyArg.description));
|
||||
tagArray.push(new OpengraphTag('og:image', companyArg.logoLink));
|
||||
return tagArray;
|
||||
}
|
||||
|
||||
constructor(propertyNameArg: string, contentArg: string) {
|
||||
super();
|
||||
const openGraphElement = document.createElement('meta');
|
||||
openGraphElement.setAttribute('property', propertyNameArg);
|
||||
openGraphElement.content = contentArg;
|
||||
this.elementRef = openGraphElement;
|
||||
}
|
||||
}
|
21
ts/websetup.classes.tag.ts
Normal file
21
ts/websetup.classes.tag.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
104
ts/websetup.classes.taglevel.ts
Normal file
104
ts/websetup.classes.taglevel.ts
Normal 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';
|
||||
}
|
||||
}
|
71
ts/websetup.classes.tagmanager.ts
Normal file
71
ts/websetup.classes.tagmanager.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
7
ts/websetup.classes.title.ts
Normal file
7
ts/websetup.classes.title.ts
Normal 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 {}
|
78
ts/websetup.classes.websetup.ts
Normal file
78
ts/websetup.classes.websetup.ts
Normal 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();
|
||||
}
|
||||
}
|
@ -1,3 +1,10 @@
|
||||
// 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 };
|
||||
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
17
tslint.json
17
tslint.json
@ -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"
|
||||
}
|
Reference in New Issue
Block a user