Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
bab9124ad9 | |||
fda71ac3e6 | |||
3d6a421d25 | |||
a7fca4e0c1 | |||
782c9cd740 | |||
b8ab19a683 | |||
e47869caed | |||
4f06c5d7c5 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/websetup",
|
"name": "@pushrocks/websetup",
|
||||||
"version": "3.0.5",
|
"version": "3.0.9",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/websetup",
|
"name": "@pushrocks/websetup",
|
||||||
"version": "3.0.5",
|
"version": "3.0.9",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "setup basic page properties",
|
"description": "setup basic page properties",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
@ -2,7 +2,7 @@ import * as plugins from '../websetup.plugins';
|
|||||||
|
|
||||||
export interface IMetaObject {
|
export interface IMetaObject {
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description?: string;
|
||||||
canonicalDomain?: string;
|
canonicalDomain?: string;
|
||||||
ldCompany?: plugins.tsclass.business.ICompany;
|
ldCompany?: plugins.tsclass.business.ICompany;
|
||||||
ldProduct?: any;
|
ldProduct?: any;
|
||||||
|
@ -63,6 +63,8 @@ export class JsonLdTag extends Tag {
|
|||||||
},
|
},
|
||||||
"description": newsArticleArg.author.firstName
|
"description": newsArticleArg.author.firstName
|
||||||
};
|
};
|
||||||
|
const ldTag = new JsonLdTag(newsArticleArg);
|
||||||
|
return ldTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(ldObjectArg: any) {
|
constructor(ldObjectArg: any) {
|
||||||
|
@ -6,19 +6,36 @@ import * as plugins from './websetup.plugins';
|
|||||||
|
|
||||||
export type TBaseLevelType = 'global' | 'base' | 'subpage';
|
export type TBaseLevelType = 'global' | 'base' | 'subpage';
|
||||||
|
|
||||||
|
export type TLevelState = 'enabled' | 'disabled';
|
||||||
|
|
||||||
export class TagLevel {
|
export class TagLevel {
|
||||||
public tagManagerRef: TagManager;
|
public tagManagerRef: TagManager;
|
||||||
|
|
||||||
public title: string;
|
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 type: TBaseLevelType;
|
||||||
public tags: Tag[] = [];
|
public tags: Tag[] = [];
|
||||||
|
|
||||||
|
public state: TLevelState = 'disabled';
|
||||||
|
|
||||||
constructor(tagManagerRefArg: TagManager, levelType: TBaseLevelType) {
|
constructor(tagManagerRefArg: TagManager, levelType: TBaseLevelType) {
|
||||||
this.tagManagerRef = tagManagerRefArg;
|
this.tagManagerRef = tagManagerRefArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public addTag(tagArg: Tag) {
|
public addTag(tagArg: Tag) {
|
||||||
this.tags.push(tagArg);
|
this.tags.push(tagArg);
|
||||||
|
if (this.state === 'enabled') {
|
||||||
|
tagArg.appendToDom();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async addCompanyInfo(companyDataArg: plugins.tsclass.business.ICompany) {
|
public async addCompanyInfo(companyDataArg: plugins.tsclass.business.ICompany) {
|
||||||
@ -52,7 +69,9 @@ export class TagLevel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public addPostInfo() {}
|
public addNewsArticleInfo(articleArg: plugins.tsclass.content.IArticle) {
|
||||||
|
this.addTag(JsonLdTag.createNewsArticleLd(articleArg));
|
||||||
|
}
|
||||||
|
|
||||||
public async enable() {
|
public async enable() {
|
||||||
if (this.title) {
|
if (this.title) {
|
||||||
@ -61,11 +80,13 @@ export class TagLevel {
|
|||||||
for (const tagArg of this.tags) {
|
for (const tagArg of this.tags) {
|
||||||
tagArg.appendToDom();
|
tagArg.appendToDom();
|
||||||
}
|
}
|
||||||
|
this.state = 'enabled';
|
||||||
}
|
}
|
||||||
|
|
||||||
public async disable() {
|
public async disable() {
|
||||||
for (const tagArg of this.tags) {
|
for (const tagArg of this.tags) {
|
||||||
tagArg.removeFromDom();
|
tagArg.removeFromDom();
|
||||||
}
|
}
|
||||||
|
this.state = 'disabled';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,22 +6,22 @@ import { JsonLdTag } from './websetup.classes.tag.jsonldtag';
|
|||||||
import { OpengraphTag } from './websetup.classes.tag.opengraphtag';
|
import { OpengraphTag } from './websetup.classes.tag.opengraphtag';
|
||||||
|
|
||||||
export class TagManager {
|
export class TagManager {
|
||||||
public globalLevel: TagLevel;
|
public globalLevel: TagLevel = new TagLevel(this, 'global');
|
||||||
|
|
||||||
public baseLevel: TagLevel;
|
public baseLevel: TagLevel = new TagLevel(this, 'base');
|
||||||
|
|
||||||
public activeLevel: TagLevel;
|
public activeLevel: TagLevel;
|
||||||
|
|
||||||
public async setup(metaObjectArg: interfaces.IMetaObject) {
|
public async setup(metaObjectArg: interfaces.IMetaObject) {
|
||||||
// global tag level
|
// global tag level
|
||||||
this.globalLevel = new TagLevel(this, 'global');
|
|
||||||
this.globalLevel.addTag(new MetaTag('google', 'notranslate'));
|
this.globalLevel.addTag(new MetaTag('google', 'notranslate'));
|
||||||
this.globalLevel.addTag(new MetaTag('revisit-after', '1 days'));
|
this.globalLevel.addTag(new MetaTag('revisit-after', '1 days'));
|
||||||
|
|
||||||
// base tag level
|
// base tag level
|
||||||
this.baseLevel = new TagLevel(this, 'base');
|
|
||||||
this.baseLevel.title = metaObjectArg.title;
|
this.baseLevel.title = metaObjectArg.title;
|
||||||
this.baseLevel.addTag(new MetaTag('description', metaObjectArg.description));
|
if (metaObjectArg.description) {
|
||||||
|
this.baseLevel.addTag(new MetaTag('description', metaObjectArg.description));
|
||||||
|
}
|
||||||
|
|
||||||
if (metaObjectArg.canonicalDomain) {
|
if (metaObjectArg.canonicalDomain) {
|
||||||
this.baseLevel.addTag(new MetaTag('canonical', metaObjectArg.canonicalDomain));
|
this.baseLevel.addTag(new MetaTag('canonical', metaObjectArg.canonicalDomain));
|
||||||
@ -31,24 +31,27 @@ export class TagManager {
|
|||||||
this.baseLevel.addCompanyInfo(metaObjectArg.ldCompany);
|
this.baseLevel.addCompanyInfo(metaObjectArg.ldCompany);
|
||||||
}
|
}
|
||||||
await this.globalLevel.enable();
|
await this.globalLevel.enable();
|
||||||
await this.baseLevel.enable();
|
this.activeLevel = this.baseLevel;
|
||||||
|
await this.activeLevel.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public setSubPageLevel(metaObjectArg: interfaces.IMetaObject) {
|
public async setSubPageLevel(metaObjectArg: interfaces.IMetaObject) {
|
||||||
const subPageLevel = new TagLevel(this, 'subpage');
|
const subPageLevel = new TagLevel(this, 'subpage');
|
||||||
subPageLevel.title = metaObjectArg.title;
|
subPageLevel.title = metaObjectArg.title;
|
||||||
subPageLevel.addTag(new MetaTag('description', metaObjectArg.description));
|
if (metaObjectArg.description) {
|
||||||
this.activeLevel.disable();
|
this.baseLevel.addTag(new MetaTag('description', metaObjectArg.description));
|
||||||
|
}
|
||||||
|
await this.activeLevel.disable();
|
||||||
this.activeLevel = subPageLevel;
|
this.activeLevel = subPageLevel;
|
||||||
this.activeLevel.enable();
|
await this.activeLevel.enable();
|
||||||
return subPageLevel;
|
return subPageLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public revertToBaseLevel() {
|
public async revertToBaseLevel() {
|
||||||
if (this.activeLevel !== this.baseLevel) {
|
if (this.activeLevel !== this.baseLevel) {
|
||||||
this.activeLevel.disable();
|
await this.activeLevel.disable();
|
||||||
this.activeLevel = this.baseLevel;
|
this.activeLevel = this.baseLevel;
|
||||||
this.activeLevel.enable();
|
await this.activeLevel.enable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,10 @@ export class WebSetup {
|
|||||||
/**
|
/**
|
||||||
* an async setup called by the constructor
|
* an async setup called by the constructor
|
||||||
*/
|
*/
|
||||||
private async setup() {
|
public async setup(optionsArg?: IWebSetupConstructorOptions) {
|
||||||
|
if (optionsArg) {
|
||||||
|
this.options = optionsArg;
|
||||||
|
}
|
||||||
await this.tagManager.setup(this.options.metaObject);
|
await this.tagManager.setup(this.options.metaObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +43,8 @@ export class WebSetup {
|
|||||||
* sets a subpage
|
* sets a subpage
|
||||||
* @param metaObjectArg
|
* @param metaObjectArg
|
||||||
*/
|
*/
|
||||||
public setSubLevel(metaObjectArg: interfaces.IMetaObject) {
|
public async setSubLevel(metaObjectArg: interfaces.IMetaObject) {
|
||||||
return this.tagManager.setSubPageLevel(metaObjectArg);
|
const subLevel = await this.tagManager.setSubPageLevel(metaObjectArg);
|
||||||
|
return subLevel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user