2020-11-04 18:01:04 +00:00
|
|
|
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';
|
|
|
|
|
2020-11-05 17:27:10 +00:00
|
|
|
export type TLevelState = 'enabled' | 'disabled';
|
|
|
|
|
2020-11-04 18:01:04 +00:00
|
|
|
export class TagLevel {
|
|
|
|
public tagManagerRef: TagManager;
|
2020-11-04 18:09:07 +00:00
|
|
|
|
2020-11-05 17:56:35 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-11-04 18:01:04 +00:00
|
|
|
public type: TBaseLevelType;
|
|
|
|
public tags: Tag[] = [];
|
|
|
|
|
2020-11-05 17:27:10 +00:00
|
|
|
public state: TLevelState = 'disabled';
|
|
|
|
|
2020-11-04 18:01:04 +00:00
|
|
|
constructor(tagManagerRefArg: TagManager, levelType: TBaseLevelType) {
|
|
|
|
this.tagManagerRef = tagManagerRefArg;
|
|
|
|
}
|
|
|
|
|
|
|
|
public addTag(tagArg: Tag) {
|
|
|
|
this.tags.push(tagArg);
|
2020-11-05 17:27:10 +00:00
|
|
|
if (this.state === 'enabled') {
|
|
|
|
tagArg.appendToDom();
|
|
|
|
}
|
2020-11-04 18:01:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 18:09:07 +00:00
|
|
|
public async addCompanyInfo(companyDataArg: plugins.tsclass.business.ICompany) {
|
2020-11-04 18:01:04 +00:00
|
|
|
this.addTag(JsonLdTag.createCompanyLd(companyDataArg));
|
2020-11-04 18:09:07 +00:00
|
|
|
|
2020-11-04 18:01:04 +00:00
|
|
|
// 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(
|
2020-11-04 18:09:07 +00:00
|
|
|
new OpengraphTag('business:contact_data:locality', companyDataArg.contact.address.postalCode)
|
2020-11-04 18:01:04 +00:00
|
|
|
);
|
|
|
|
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(
|
2020-11-04 18:09:07 +00:00
|
|
|
new OpengraphTag('business:contact_data:country_name', companyDataArg.contact.address.country)
|
2020-11-04 18:01:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-05 17:15:27 +00:00
|
|
|
public addNewsArticleInfo(articleArg: plugins.tsclass.content.IArticle) {
|
|
|
|
this.addTag(JsonLdTag.createNewsArticleLd(articleArg));
|
|
|
|
}
|
2020-11-04 18:09:07 +00:00
|
|
|
|
2020-11-04 18:01:04 +00:00
|
|
|
public async enable() {
|
|
|
|
if (this.title) {
|
|
|
|
document.title = this.title;
|
|
|
|
}
|
|
|
|
for (const tagArg of this.tags) {
|
|
|
|
tagArg.appendToDom();
|
|
|
|
}
|
2020-11-05 17:27:10 +00:00
|
|
|
this.state = 'enabled';
|
2020-11-04 18:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public async disable() {
|
|
|
|
for (const tagArg of this.tags) {
|
|
|
|
tagArg.removeFromDom();
|
|
|
|
}
|
2020-11-05 17:27:10 +00:00
|
|
|
this.state = 'disabled';
|
2020-11-04 18:01:04 +00:00
|
|
|
}
|
2020-11-04 18:09:07 +00:00
|
|
|
}
|