Compare commits

..

22 Commits

Author SHA1 Message Date
d1c0501461 3.0.16 2021-12-10 18:03:47 +01:00
f5d33bdebe fix(core): update 2021-12-10 18:03:46 +01:00
2b9c9225a5 3.0.15 2020-12-08 22:31:35 +00:00
5ce55190fe fix(core): update 2020-12-08 22:31:35 +00:00
8fb071f57b 3.0.14 2020-12-08 22:29:20 +00:00
3278ef7425 fix(core): update 2020-12-08 22:29:19 +00:00
11282daa38 3.0.13 2020-12-07 23:11:14 +00:00
1fe7dd8d06 fix(core): update 2020-12-07 23:11:13 +00:00
9175cb7841 3.0.12 2020-12-07 05:06:31 +00:00
6b9ebcec7a fix(core): update 2020-12-07 05:06:30 +00:00
2159995342 3.0.11 2020-11-06 01:11:26 +00:00
7fa14ceabd fix(core): update 2020-11-06 01:11:26 +00:00
0294895f78 3.0.10 2020-11-05 20:03:13 +00:00
74fc97a220 fix(core): update 2020-11-05 20:03:12 +00:00
bab9124ad9 3.0.9 2020-11-05 18:36:09 +00:00
fda71ac3e6 fix(core): update 2020-11-05 18:36:08 +00:00
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
12 changed files with 19480 additions and 3596 deletions

22866
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/websetup",
"version": "3.0.5",
"version": "3.0.16",
"private": false,
"description": "setup basic page properties",
"main": "dist_ts/index.js",
@ -16,16 +16,17 @@
"websafe"
],
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsbundle": "^1.0.78",
"@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.2.9",
"@gitzone/tsbuild": "^2.1.28",
"@gitzone/tsbundle": "^1.0.88",
"@gitzone/tstest": "^1.0.60",
"@pushrocks/tapbundle": "^3.2.15",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {
"@pushrocks/smartpromise": "^3.1.3",
"@tsclass/tsclass": "^3.0.29"
"@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartpromise": "^3.1.6",
"@tsclass/tsclass": "^3.0.37"
},
"files": [
"ts/**/*",

View File

@ -1,4 +1,6 @@
import { expect, tap } from '@pushrocks/tapbundle';
import { expect, tap, webhelpers } from '@pushrocks/tapbundle';
webhelpers.enable();
import * as websetup from '../ts/index';
tap.test('first test', async () => {

View File

@ -2,3 +2,4 @@ export * from './websetup.classes.websetup';
export * from './websetup.classes.tag.metatag';
export * from './websetup.classes.tag.opengraphtag';
export * from './websetup.classes.tag.jsonldtag';
export * from './websetup.classes.title';

View File

@ -2,8 +2,19 @@ import * as plugins from '../websetup.plugins';
export interface IMetaObject {
title: string;
description: string;
description?: string;
canonicalDomain?: string;
ldCompany?: plugins.tsclass.business.ICompany;
ldProduct?: any;
// handles
twitterHandle?: string;
facebookHandle?: string;
// links
companyWebsiteLink?: string;
googleNewsLink?: string;
mediumLink?: string;
slackLink?: string;
airmeetLink?: string;
}

View File

@ -35,41 +35,41 @@ export class JsonLdTag extends Tag {
return ldTag;
}
public static createNewsArticleLd (newsArticleArg: plugins.tsclass.content.IArticle) {
public static createNewsArticleJsonLd(newsArticleArg: plugins.tsclass.content.IArticle) {
const newsArticleLd = {
"@context": "https://schema.org",
"@type": "NewsArticle",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": window.location.href
'@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}`
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
}
publisher: {
'@type': 'Organization',
name: newsArticleArg.author.surName, // TODO
logo: {
'@type': 'ImageObject',
url: newsArticleArg.author.surName, // TODO
},
},
"description": newsArticleArg.author.firstName
description: newsArticleArg.author.firstName,
};
const ldTag = new JsonLdTag(newsArticleLd);
return ldTag;
}
constructor(ldObjectArg: any) {
super();
const jsonLdElement = document.createElement('script');
jsonLdElement.type = 'application/ld+json';
jsonLdElement.text = JSON.stringify(JSON.stringify(ldObjectArg));
jsonLdElement.text = JSON.stringify(ldObjectArg);
this.elementRef = jsonLdElement;
}
}

View File

@ -1,6 +1,16 @@
import * as plugins from './websetup.plugins';
import { Tag } from './websetup.classes.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) {
super();
const openGraphElement = document.createElement('meta');

View File

@ -6,19 +6,42 @@ 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);
public addTag(tagArg: Tag | Tag[]) {
if (tagArg instanceof Array) {
for (const tagArg2 of tagArg) {
this.addTag(tagArg2);
}
} else {
this.tags.push(tagArg);
if (this.state === 'enabled') {
tagArg.appendToDom();
}
}
}
public async addCompanyInfo(companyDataArg: plugins.tsclass.business.ICompany) {
@ -52,7 +75,10 @@ export class TagLevel {
);
}
public addPostInfo() {}
public addNewsArticleInfo(articleArg: plugins.tsclass.content.IArticle) {
this.addTag(JsonLdTag.createNewsArticleJsonLd(articleArg));
this.addTag(OpengraphTag.createNewsArticleOgTags(articleArg));
}
public async enable() {
if (this.title) {
@ -61,11 +87,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,28 @@ 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'));
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
this.baseLevel = new TagLevel(this, 'base');
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) {
this.baseLevel.addTag(new MetaTag('canonical', metaObjectArg.canonicalDomain));
@ -31,24 +37,27 @@ export class TagManager {
this.baseLevel.addCompanyInfo(metaObjectArg.ldCompany);
}
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');
subPageLevel.title = metaObjectArg.title;
subPageLevel.addTag(new MetaTag('description', metaObjectArg.description));
this.activeLevel.disable();
if (metaObjectArg.description) {
subPageLevel.addTag(new MetaTag('description', metaObjectArg.description));
}
await this.activeLevel.disable();
this.activeLevel = subPageLevel;
this.activeLevel.enable();
await this.activeLevel.enable();
return subPageLevel;
}
public revertToBaseLevel() {
public async revertToBaseLevel() {
if (this.activeLevel !== this.baseLevel) {
this.activeLevel.disable();
await this.activeLevel.disable();
this.activeLevel = this.baseLevel;
this.activeLevel.enable();
await this.activeLevel.enable();
}
}
}

View 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 {
}

View File

@ -5,6 +5,7 @@ import { TagLevel } from './websetup.classes.taglevel';
export interface IWebSetupConstructorOptions {
metaObject: interfaces.IMetaObject;
smartssrWaitForReadySignal?: boolean;
}
/**
@ -13,19 +14,31 @@ export interface IWebSetupConstructorOptions {
export class WebSetup {
public tagManager: TagManager = new TagManager();
public options: IWebSetupConstructorOptions;
// private deferreds
private readyDeferred = plugins.smartpromise.defer();
private readyForSmartssrDeferred = plugins.smartpromise.defer();
// public promises
public readyPromise = this.readyDeferred.promise;
public readyForSmartssrPromise = this.readyForSmartssrDeferred.promise;
constructor(optionsArg: IWebSetupConstructorOptions) {
this.options = optionsArg;
this.setup().then(() => {
this.readyDeferred.resolve();
if (!this.options.smartssrWaitForReadySignal) {
this.readyForSmartssrDeferred.resolve();
}
});
}
/**
* 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);
}
@ -40,7 +53,24 @@ export class WebSetup {
* sets a subpage
* @param metaObjectArg
*/
public setSubLevel(metaObjectArg: interfaces.IMetaObject) {
return this.tagManager.setSubPageLevel(metaObjectArg);
public async setSubLevel(metaObjectArg: interfaces.IMetaObject) {
const subLevel = await this.tagManager.setSubPageLevel(metaObjectArg);
return subLevel;
}
/**
* flashes the title with the given text
* @param flashTextArg
*/
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();
}
}

View File

@ -1,7 +1,8 @@
// pushrocks scope
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartpromise from '@pushrocks/smartpromise';
export { smartpromise };
export { smartdelay, smartpromise };
// tsclass scope
import * as tsclass from '@tsclass/tsclass';