fix(core): update

This commit is contained in:
Philipp Kunz 2019-03-27 14:38:24 +01:00
parent 56bcfcdae4
commit eb4a4288ed
5 changed files with 48 additions and 4 deletions

View File

@ -12,6 +12,10 @@
"build": "(tsbuild)",
"format": "(gitzone format)"
},
"keywords": [
"lossless",
"websafe"
],
"devDependencies": {
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tstest": "^1.0.15",

View File

@ -2,7 +2,7 @@ import { expect, tap } from '@pushrocks/tapbundle';
import * as websetup from '../ts/index'
tap.test('first test', async () => {
console.log(websetup.standardExport)
console.log('Waiting for proper puppeteer support here');
})
tap.start()
tap.start();

View File

@ -2,10 +2,14 @@ import * as plugins from './websetup.plugins';
import { setupGoogleAnalytics } from './tools/ganalytics';
import { setupFullStory } from './tools/fullstory';
import { setupServiceWoker } from './serviceworker';
import { IMetaObject, setupMetaInformation } from './meta';
export interface IWebSetupConstructorOptions {
googleAnalyticsCode?: string;
fsCode?: string;
metaObject: IMetaObject;
serviceworker?: boolean;
}
/**
@ -13,12 +17,21 @@ export interface IWebSetupConstructorOptions {
*/
export class WebSetup {
constructor(optionsArg: IWebSetupConstructorOptions) {
// most important, lets get the meta information in place
this.setup(optionsArg);
}
async setup(optionsArg: IWebSetupConstructorOptions) {
if(optionsArg.serviceworker) {
await setupServiceWoker()
}
if (optionsArg.googleAnalyticsCode) {
setupGoogleAnalytics(optionsArg.googleAnalyticsCode);
await setupGoogleAnalytics(optionsArg.googleAnalyticsCode);
}
if (optionsArg.fsCode) {
setupFullStory(optionsArg.fsCode)
await setupFullStory(optionsArg.fsCode)
}
}
}

18
ts/meta/index.ts Normal file
View File

@ -0,0 +1,18 @@
export interface IMetaObject {
title: string;
description: string;
}
export const setupMetaInformation = async (metaObjectArg: IMetaObject) => {
document.title = metaObjectArg.title;
addMetaTag('description', metaObjectArg.description);
addMetaTag('google', 'notranslate');
addMetaTag('revisited-after', '1 days');
};
const addMetaTag = async (linkNameArg: string, contentArg: string) => {
const metaElement = document.createElement('meta');
metaElement.name = linkNameArg;
metaElement.content = contentArg;
document.getElementsByTagName('head')[0].appendChild(metaElement);
};

View File

@ -0,0 +1,9 @@
export const setupServiceWoker = async () => {
// serviceworker
const script = document.createElement('script');
script.onload = () => {
console.log('Loaded Serviceworker. The serviceworker helps us with notifications and offline capabilities, so you can also read this site when your device is offline.');
};
script.src = 'serviceworker/mainthread.js';
document.head.appendChild(script);
};