websetup/ts/websetup.classes.tagmanager.ts

57 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-11-04 18:01:04 +00:00
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 {
2020-11-05 17:56:35 +00:00
public globalLevel: TagLevel = new TagLevel(this, 'global');
2020-11-04 18:01:04 +00:00
2020-11-05 17:56:35 +00:00
public baseLevel: TagLevel = new TagLevel(this, 'base');
2020-11-04 18:01:04 +00:00
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;
2020-11-05 17:56:35 +00:00
if (metaObjectArg.description) {
this.baseLevel.addTag(new MetaTag('description', metaObjectArg.description));
}
2020-11-04 18:09:07 +00:00
if (metaObjectArg.canonicalDomain) {
this.baseLevel.addTag(new MetaTag('canonical', metaObjectArg.canonicalDomain));
2020-11-04 18:01:04 +00:00
}
2020-11-04 18:09:07 +00:00
2020-11-04 18:01:04 +00:00
if (metaObjectArg.ldCompany) {
this.baseLevel.addCompanyInfo(metaObjectArg.ldCompany);
}
await this.globalLevel.enable();
await this.baseLevel.enable();
}
public setSubPageLevel(metaObjectArg: interfaces.IMetaObject) {
const subPageLevel = new TagLevel(this, 'subpage');
subPageLevel.title = metaObjectArg.title;
2020-11-05 17:56:35 +00:00
if (metaObjectArg.description) {
this.baseLevel.addTag(new MetaTag('description', metaObjectArg.description));
}
2020-11-04 18:01:04 +00:00
this.activeLevel.disable();
this.activeLevel = subPageLevel;
this.activeLevel.enable();
2020-11-05 15:35:31 +00:00
return subPageLevel;
2020-11-04 18:01:04 +00:00
}
public revertToBaseLevel() {
if (this.activeLevel !== this.baseLevel) {
this.activeLevel.disable();
this.activeLevel = this.baseLevel;
this.activeLevel.enable();
}
}
2020-11-04 18:09:07 +00:00
}