fix(metadata): update package metadata and align company schema integration with latest tsclass types
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/websetup',
|
||||
version: '3.0.19',
|
||||
description: 'setup basic page properties'
|
||||
name: '@push.rocks/websetup',
|
||||
version: '3.0.20',
|
||||
description: 'A library for setting up basic properties of a web page including meta tags, OpenGraph tags, JSON-LD structured data, with support for dynamic content.'
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ export interface IMetaObject {
|
||||
title: string;
|
||||
description?: string;
|
||||
canonicalDomain?: string;
|
||||
ldCompany?: plugins.tsclass.business.ICompany;
|
||||
ldCompany?: plugins.tsclass.business.TCompany;
|
||||
ldProduct?: plugins.tsclass.saas.IProduct;
|
||||
|
||||
// handles
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as interfaces from './interfaces/index.js';
|
||||
import { Tag } from './websetup.classes.tag.js';
|
||||
|
||||
export class JsonLdTag extends Tag {
|
||||
public static createCompanyJsonLd(companyDataArg: plugins.tsclass.business.ICompany) {
|
||||
public static createCompanyJsonLd(companyDataArg: plugins.tsclass.business.TCompany) {
|
||||
// STATIC
|
||||
// lets care about linked data
|
||||
const companyLd = {
|
||||
@@ -12,24 +12,26 @@ export class JsonLdTag extends Tag {
|
||||
'@type': 'Corporation',
|
||||
name: companyDataArg.name,
|
||||
alternateName: companyDataArg.name.replace(' GmbH', ''),
|
||||
url: companyDataArg.contact.website,
|
||||
logo: companyDataArg.contact.logoUrl,
|
||||
url: companyDataArg.website,
|
||||
logo: companyDataArg.logoUrl,
|
||||
contactPoint: {
|
||||
'@type': 'ContactPoint',
|
||||
telephone: companyDataArg.contact.phone,
|
||||
telephone: companyDataArg.phone,
|
||||
contactType: 'customer service',
|
||||
areaServed: 'DE',
|
||||
availableLanguage: ['en', 'German'],
|
||||
},
|
||||
sameAs: [],
|
||||
sameAs: [] as string[],
|
||||
};
|
||||
|
||||
if (companyDataArg.contact.facebookUrl) {
|
||||
companyLd.sameAs.push(companyDataArg.contact.facebookUrl);
|
||||
const facebookUrl = companyDataArg.socials?.find((socialArg) => socialArg.type === 'facebook')?.url;
|
||||
if (facebookUrl) {
|
||||
companyLd.sameAs.push(facebookUrl);
|
||||
}
|
||||
|
||||
if (companyDataArg.contact.twitterUrl) {
|
||||
companyLd.sameAs.push(companyDataArg.contact.twitterUrl);
|
||||
const twitterUrl = companyDataArg.socials?.find((socialArg) => socialArg.type === 'twitter')?.url;
|
||||
if (twitterUrl) {
|
||||
companyLd.sameAs.push(twitterUrl);
|
||||
}
|
||||
|
||||
const ldTag = new JsonLdTag(companyLd);
|
||||
@@ -67,7 +69,7 @@ export class JsonLdTag extends Tag {
|
||||
}
|
||||
public static createProductJsonLd(
|
||||
productArg: plugins.tsclass.saas.IProduct,
|
||||
publisherArg: plugins.tsclass.business.ICompany
|
||||
publisherArg?: plugins.tsclass.business.TCompany
|
||||
) {
|
||||
const productLd = {
|
||||
'@context': 'https://schema.org',
|
||||
@@ -87,7 +89,7 @@ export class JsonLdTag extends Tag {
|
||||
priceCurrency: 'EUR',
|
||||
},
|
||||
},
|
||||
publisher: this.createCompanyJsonLd(publisherArg).elementRef.textContent,
|
||||
publisher: publisherArg ? this.createCompanyJsonLd(publisherArg).elementRef.textContent : undefined,
|
||||
screenshot: 'https://www.social.io/screenshot.png',
|
||||
url: 'https://www.social.io/',
|
||||
};
|
||||
|
||||
@@ -3,9 +3,7 @@ import { Tag } from './websetup.classes.tag.js';
|
||||
export class LinkTag extends Tag {
|
||||
constructor(relArg: string, hrefArg: string) {
|
||||
super();
|
||||
const linkElement = !!document.querySelector("link[rel='canonical']")
|
||||
? document.querySelector("link[rel='canonical']")
|
||||
: document.createElement('link');
|
||||
const linkElement = document.querySelector("link[rel='canonical']") ?? document.createElement('link');
|
||||
linkElement.setAttribute('rel', relArg);
|
||||
linkElement.setAttribute('href', hrefArg);
|
||||
this.elementRef = linkElement;
|
||||
|
||||
@@ -4,10 +4,10 @@ import { Tag } from './websetup.classes.tag.js';
|
||||
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:url', newsArticleArg.url ?? globalThis.location.href));
|
||||
tagArray.push(new OpengraphTag('og:title', newsArticleArg.title));
|
||||
tagArray.push(new OpengraphTag('og:description', newsArticleArg.content));
|
||||
tagArray.push(new OpengraphTag('og:image', newsArticleArg.featuredImageUrl));
|
||||
tagArray.push(new OpengraphTag('og:image', newsArticleArg.featuredImageUrl ?? ''));
|
||||
return tagArray;
|
||||
}
|
||||
|
||||
@@ -16,20 +16,20 @@ export class OpengraphTag extends Tag {
|
||||
tagArray.push(new OpengraphTag('og:type', 'product'));
|
||||
tagArray.push(new OpengraphTag('og:url', globalThis.location.href));
|
||||
tagArray.push(new OpengraphTag('og:title', `${productArg.name} - ${productArg.slogan}`));
|
||||
tagArray.push(new OpengraphTag('og:site_name', productArg.name))
|
||||
tagArray.push(new OpengraphTag('og:site_name', productArg.name));
|
||||
tagArray.push(new OpengraphTag('og:description', productArg.description));
|
||||
tagArray.push(new OpengraphTag('og:image', productArg.logoLink));
|
||||
return tagArray;
|
||||
}
|
||||
|
||||
public static createCompanyOgTags(companyArg: plugins.tsclass.business.ICompany) {
|
||||
public static createCompanyOgTags(companyArg: plugins.tsclass.business.TCompany) {
|
||||
const tagArray: OpengraphTag[] = [];
|
||||
tagArray.push(new OpengraphTag('og:type', 'company'));
|
||||
tagArray.push(new OpengraphTag('og:url', globalThis.location.href));
|
||||
tagArray.push(new OpengraphTag('og:title', `${companyArg.name} - ${companyArg.slogan}`));
|
||||
tagArray.push(new OpengraphTag('og:site_name', companyArg.name))
|
||||
tagArray.push(new OpengraphTag('og:title', companyArg.name));
|
||||
tagArray.push(new OpengraphTag('og:site_name', companyArg.name));
|
||||
tagArray.push(new OpengraphTag('og:description', companyArg.description));
|
||||
tagArray.push(new OpengraphTag('og:image', companyArg.logoLink));
|
||||
tagArray.push(new OpengraphTag('og:image', companyArg.logoUrl ?? ''));
|
||||
return tagArray;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import * as plugins from './websetup.plugins.js';
|
||||
|
||||
export class Tag {
|
||||
public elementRef: Element;
|
||||
public elementRef!: Element;
|
||||
|
||||
public tagLevel: 'global' | 'levelbound';
|
||||
public tagLevel: 'global' | 'levelbound' = 'levelbound';
|
||||
|
||||
public appendToDom() {
|
||||
if (!this.elementRef.parentElement && !this.elementRef.parentNode) {
|
||||
|
||||
@@ -11,14 +11,14 @@ export type TLevelState = 'enabled' | 'disabled';
|
||||
export class TagLevel {
|
||||
public tagManagerRef: TagManager;
|
||||
|
||||
private titleStore: string;
|
||||
private titleStore?: string;
|
||||
public set title(titleArg: string) {
|
||||
this.titleStore = titleArg;
|
||||
if (this.state === 'enabled') {
|
||||
document.title = this.titleStore;
|
||||
}
|
||||
}
|
||||
public get title() {
|
||||
public get title(): string | undefined {
|
||||
return this.titleStore;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ export class TagLevel {
|
||||
|
||||
constructor(tagManagerRefArg: TagManager, levelType: TBaseLevelType) {
|
||||
this.tagManagerRef = tagManagerRefArg;
|
||||
this.type = levelType;
|
||||
}
|
||||
|
||||
public addTag(tagArg: Tag | Tag[]) {
|
||||
@@ -44,34 +45,34 @@ export class TagLevel {
|
||||
}
|
||||
}
|
||||
|
||||
public async addCompanyInfo(companyDataArg: plugins.tsclass.business.ICompany) {
|
||||
public async addCompanyInfo(companyDataArg: plugins.tsclass.business.TCompany) {
|
||||
this.addTag(JsonLdTag.createCompanyJsonLd(companyDataArg));
|
||||
|
||||
// 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('og:url', companyDataArg.website ?? ''));
|
||||
this.addTag(new OpengraphTag('og:image', companyDataArg.logoUrl ?? ''));
|
||||
this.addTag(
|
||||
new OpengraphTag(
|
||||
'business:contact_data:street_address',
|
||||
`${companyDataArg.contact.address.streetName} ${companyDataArg.contact.address.houseNumber}`
|
||||
`${companyDataArg.address.streetName} ${companyDataArg.address.houseNumber}`
|
||||
)
|
||||
);
|
||||
this.addTag(
|
||||
new OpengraphTag('business:contact_data:locality', companyDataArg.contact.address.postalCode)
|
||||
new OpengraphTag('business:contact_data:locality', companyDataArg.address.postalCode)
|
||||
);
|
||||
this.addTag(
|
||||
new OpengraphTag('business:contact_data:region', companyDataArg.contact.address.city)
|
||||
new OpengraphTag('business:contact_data:region', companyDataArg.address.city)
|
||||
);
|
||||
this.addTag(
|
||||
new OpengraphTag(
|
||||
'business:contact_data:postal_code',
|
||||
companyDataArg.contact.address.postalCode
|
||||
companyDataArg.address.postalCode
|
||||
)
|
||||
);
|
||||
this.addTag(
|
||||
new OpengraphTag('business:contact_data:country_name', companyDataArg.contact.address.country)
|
||||
new OpengraphTag('business:contact_data:country_name', companyDataArg.address.country)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -80,7 +81,7 @@ export class TagLevel {
|
||||
this.addTag(OpengraphTag.createNewsArticleOgTags(articleArg));
|
||||
}
|
||||
|
||||
public addProductInfo(productArg: plugins.tsclass.saas.IProduct, companyArg: plugins.tsclass.business.ICompany) {
|
||||
public addProductInfo(productArg: plugins.tsclass.saas.IProduct, companyArg?: plugins.tsclass.business.TCompany) {
|
||||
this.addTag(JsonLdTag.createProductJsonLd(productArg, companyArg));
|
||||
this.addTag(OpengraphTag.createProductOgTags(productArg));
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export class TagManager {
|
||||
|
||||
public baseLevel: TagLevel = new TagLevel(this, 'base');
|
||||
|
||||
public activeLevel: TagLevel;
|
||||
public activeLevel!: TagLevel;
|
||||
|
||||
public async setup(metaObjectArg: interfaces.IMetaObject) {
|
||||
// global tag level
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// pushrocks scope
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
|
||||
export { smartdelay, smartpromise };
|
||||
export { smartpromise };
|
||||
|
||||
// tsclass scope
|
||||
import * as tsclass from '@tsclass/tsclass';
|
||||
|
||||
Reference in New Issue
Block a user