Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
2b9c9225a5 | |||
5ce55190fe | |||
8fb071f57b | |||
3278ef7425 | |||
11282daa38 | |||
1fe7dd8d06 | |||
9175cb7841 | |||
6b9ebcec7a | |||
2159995342 | |||
7fa14ceabd |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/websetup",
|
"name": "@pushrocks/websetup",
|
||||||
"version": "3.0.10",
|
"version": "3.0.15",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/websetup",
|
"name": "@pushrocks/websetup",
|
||||||
"version": "3.0.10",
|
"version": "3.0.15",
|
||||||
"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,3 +2,4 @@ export * from './websetup.classes.websetup';
|
|||||||
export * from './websetup.classes.tag.metatag';
|
export * from './websetup.classes.tag.metatag';
|
||||||
export * from './websetup.classes.tag.opengraphtag';
|
export * from './websetup.classes.tag.opengraphtag';
|
||||||
export * from './websetup.classes.tag.jsonldtag';
|
export * from './websetup.classes.tag.jsonldtag';
|
||||||
|
export * from './websetup.classes.title';
|
||||||
|
@ -6,4 +6,15 @@ export interface IMetaObject {
|
|||||||
canonicalDomain?: string;
|
canonicalDomain?: string;
|
||||||
ldCompany?: plugins.tsclass.business.ICompany;
|
ldCompany?: plugins.tsclass.business.ICompany;
|
||||||
ldProduct?: any;
|
ldProduct?: any;
|
||||||
|
|
||||||
|
// handles
|
||||||
|
twitterHandle?: string;
|
||||||
|
facebookHandle?: string;
|
||||||
|
|
||||||
|
// links
|
||||||
|
companyWebsiteLink?: string;
|
||||||
|
googleNewsLink?: string;
|
||||||
|
mediumLink?: string;
|
||||||
|
slackLink?: string;
|
||||||
|
airmeetLink?: string;
|
||||||
}
|
}
|
||||||
|
@ -35,35 +35,33 @@ export class JsonLdTag extends Tag {
|
|||||||
return ldTag;
|
return ldTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static createNewsArticleLd (newsArticleArg: plugins.tsclass.content.IArticle) {
|
public static createNewsArticleJsonLd(newsArticleArg: plugins.tsclass.content.IArticle) {
|
||||||
const newsArticleLd = {
|
const newsArticleLd = {
|
||||||
"@context": "https://schema.org",
|
'@context': 'https://schema.org',
|
||||||
"@type": "NewsArticle",
|
'@type': 'NewsArticle',
|
||||||
"mainEntityOfPage": {
|
mainEntityOfPage: {
|
||||||
"@type": "WebPage",
|
'@type': 'WebPage',
|
||||||
"@id": window.location.href
|
'@id': window.location.href,
|
||||||
},
|
},
|
||||||
"headline": "Article headline",
|
headline: 'Article headline',
|
||||||
"image": [
|
image: [newsArticleArg.featuredImageUrl],
|
||||||
newsArticleArg.featuredImageUrl
|
datePublished: new Date(newsArticleArg.timestamp).toISOString(),
|
||||||
],
|
dateModified: new Date(newsArticleArg.timestamp).toISOString(),
|
||||||
"datePublished": new Date(newsArticleArg.timestamp).toISOString(),
|
author: {
|
||||||
"dateModified": new Date(newsArticleArg.timestamp).toISOString(),
|
'@type': 'Person',
|
||||||
"author": {
|
name: `${newsArticleArg.author.firstName} ${newsArticleArg.author.surName}`,
|
||||||
"@type": "Person",
|
|
||||||
"name": `${newsArticleArg.author.firstName} ${newsArticleArg.author.surName}`
|
|
||||||
},
|
},
|
||||||
"publisher": {
|
publisher: {
|
||||||
"@type": "Organization",
|
'@type': 'Organization',
|
||||||
"name": newsArticleArg.author.surName, // TODO
|
name: newsArticleArg.author.surName, // TODO
|
||||||
"logo": {
|
logo: {
|
||||||
"@type": "ImageObject",
|
'@type': 'ImageObject',
|
||||||
"url": newsArticleArg.author.surName // TODO
|
url: newsArticleArg.author.surName, // TODO
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"description": newsArticleArg.author.firstName
|
},
|
||||||
|
description: newsArticleArg.author.firstName,
|
||||||
};
|
};
|
||||||
const ldTag = new JsonLdTag(newsArticleArg);
|
const ldTag = new JsonLdTag(newsArticleLd);
|
||||||
return ldTag;
|
return ldTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,16 @@
|
|||||||
|
import * as plugins from './websetup.plugins';
|
||||||
import { Tag } from './websetup.classes.tag';
|
import { Tag } from './websetup.classes.tag';
|
||||||
|
|
||||||
export class OpengraphTag extends Tag {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(propertyNameArg: string, contentArg: string) {
|
constructor(propertyNameArg: string, contentArg: string) {
|
||||||
super();
|
super();
|
||||||
const openGraphElement = document.createElement('meta');
|
const openGraphElement = document.createElement('meta');
|
||||||
|
@ -31,12 +31,18 @@ export class TagLevel {
|
|||||||
this.tagManagerRef = tagManagerRefArg;
|
this.tagManagerRef = tagManagerRefArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public addTag(tagArg: Tag) {
|
public addTag(tagArg: Tag | Tag[]) {
|
||||||
|
if (tagArg instanceof Array) {
|
||||||
|
for (const tagArg2 of tagArg) {
|
||||||
|
this.addTag(tagArg2);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
this.tags.push(tagArg);
|
this.tags.push(tagArg);
|
||||||
if (this.state === 'enabled') {
|
if (this.state === 'enabled') {
|
||||||
tagArg.appendToDom();
|
tagArg.appendToDom();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async addCompanyInfo(companyDataArg: plugins.tsclass.business.ICompany) {
|
public async addCompanyInfo(companyDataArg: plugins.tsclass.business.ICompany) {
|
||||||
this.addTag(JsonLdTag.createCompanyLd(companyDataArg));
|
this.addTag(JsonLdTag.createCompanyLd(companyDataArg));
|
||||||
@ -70,7 +76,8 @@ export class TagLevel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public addNewsArticleInfo(articleArg: plugins.tsclass.content.IArticle) {
|
public addNewsArticleInfo(articleArg: plugins.tsclass.content.IArticle) {
|
||||||
this.addTag(JsonLdTag.createNewsArticleLd(articleArg));
|
this.addTag(JsonLdTag.createNewsArticleJsonLd(articleArg));
|
||||||
|
this.addTag(OpengraphTag.createNewsArticleOgTags(articleArg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async enable() {
|
public async enable() {
|
||||||
|
@ -17,6 +17,12 @@ export class TagManager {
|
|||||||
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'));
|
||||||
|
|
||||||
|
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
|
// base tag level
|
||||||
this.baseLevel.title = metaObjectArg.title;
|
this.baseLevel.title = metaObjectArg.title;
|
||||||
if (metaObjectArg.description) {
|
if (metaObjectArg.description) {
|
||||||
|
9
ts/websetup.classes.title.ts
Normal file
9
ts/websetup.classes.title.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import * as plugins from './websetup.plugins';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a title proxy class
|
||||||
|
* --> to be used in the future when flashing titles is supported
|
||||||
|
*/
|
||||||
|
export class Title {
|
||||||
|
|
||||||
|
}
|
@ -5,6 +5,7 @@ import { TagLevel } from './websetup.classes.taglevel';
|
|||||||
|
|
||||||
export interface IWebSetupConstructorOptions {
|
export interface IWebSetupConstructorOptions {
|
||||||
metaObject: interfaces.IMetaObject;
|
metaObject: interfaces.IMetaObject;
|
||||||
|
smartssrWaitForReadySignal?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -13,12 +14,21 @@ export interface IWebSetupConstructorOptions {
|
|||||||
export class WebSetup {
|
export class WebSetup {
|
||||||
public tagManager: TagManager = new TagManager();
|
public tagManager: TagManager = new TagManager();
|
||||||
public options: IWebSetupConstructorOptions;
|
public options: IWebSetupConstructorOptions;
|
||||||
|
|
||||||
|
// private deferreds
|
||||||
private readyDeferred = plugins.smartpromise.defer();
|
private readyDeferred = plugins.smartpromise.defer();
|
||||||
|
private readyForSmartssrDeferred = plugins.smartpromise.defer();
|
||||||
|
|
||||||
|
// public promises
|
||||||
public readyPromise = this.readyDeferred.promise;
|
public readyPromise = this.readyDeferred.promise;
|
||||||
|
public readyForSmartssrPromise = this.readyForSmartssrDeferred.promise;
|
||||||
constructor(optionsArg: IWebSetupConstructorOptions) {
|
constructor(optionsArg: IWebSetupConstructorOptions) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
this.setup().then(() => {
|
this.setup().then(() => {
|
||||||
this.readyDeferred.resolve();
|
this.readyDeferred.resolve();
|
||||||
|
if (!this.options.smartssrWaitForReadySignal) {
|
||||||
|
this.readyForSmartssrDeferred.resolve();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,5 +58,19 @@ export class WebSetup {
|
|||||||
return subLevel;
|
return subLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* flashes the title with the given text
|
||||||
|
* @param flashTextArg
|
||||||
|
*/
|
||||||
public flashTitle(flashTextArg: string) {}
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user