Compare commits

...

10 Commits

Author SHA1 Message Date
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
7 changed files with 75 additions and 14 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/websetup",
"version": "3.0.3",
"version": "3.0.8",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/websetup",
"version": "3.0.3",
"version": "3.0.8",
"private": false,
"description": "setup basic page properties",
"main": "dist_ts/index.js",

View File

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

View File

@ -35,6 +35,38 @@ export class JsonLdTag extends Tag {
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');

View File

@ -6,19 +6,36 @@ import * as plugins from './websetup.plugins';
export type TBaseLevelType = 'global' | 'base' | 'subpage';
export type TLevelState = 'enabled' | 'disabled';
export class TagLevel {
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 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) {
@ -52,7 +69,9 @@ export class TagLevel {
);
}
public addPostInfo() {}
public addNewsArticleInfo(articleArg: plugins.tsclass.content.IArticle) {
this.addTag(JsonLdTag.createNewsArticleLd(articleArg));
}
public async enable() {
if (this.title) {
@ -61,11 +80,13 @@ export class TagLevel {
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

@ -6,22 +6,22 @@ import { JsonLdTag } from './websetup.classes.tag.jsonldtag';
import { OpengraphTag } from './websetup.classes.tag.opengraphtag';
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 async setup(metaObjectArg: interfaces.IMetaObject) {
// global tag level
this.globalLevel = new TagLevel(this, 'global');
this.globalLevel.addTag(new MetaTag('google', 'notranslate'));
this.globalLevel.addTag(new MetaTag('revisit-after', '1 days'));
// base tag level
this.baseLevel = new TagLevel(this, 'base');
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));
@ -37,10 +37,13 @@ export class TagManager {
public setSubPageLevel(metaObjectArg: interfaces.IMetaObject) {
const subPageLevel = new TagLevel(this, 'subpage');
subPageLevel.title = metaObjectArg.title;
subPageLevel.addTag(new MetaTag('description', metaObjectArg.description));
if (metaObjectArg.description) {
this.baseLevel.addTag(new MetaTag('description', metaObjectArg.description));
}
this.activeLevel.disable();
this.activeLevel = subPageLevel;
this.activeLevel.enable();
return subPageLevel;
}
public revertToBaseLevel() {

View File

@ -25,7 +25,10 @@ export class WebSetup {
/**
* 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);
}
@ -38,7 +41,9 @@ export class WebSetup {
/**
* sets a subpage
* @param metaObject
* @param metaObjectArg
*/
public setSubLevel(metaObject: interfaces.IMetaObject) {}
public setSubLevel(metaObjectArg: interfaces.IMetaObject) {
return this.tagManager.setSubPageLevel(metaObjectArg);
}
}