2023-05-07 18:24:53 +00:00
|
|
|
import * as plugins from './websetup.plugins.js';
|
|
|
|
import * as interfaces from './interfaces/index.js';
|
2020-11-04 18:01:04 +00:00
|
|
|
|
2023-05-07 18:24:53 +00:00
|
|
|
import { Tag } from './websetup.classes.tag.js';
|
2020-11-04 18:01:04 +00:00
|
|
|
|
|
|
|
export class JsonLdTag extends Tag {
|
2023-05-07 18:24:53 +00:00
|
|
|
public static createCompanyJsonLd(companyDataArg: plugins.tsclass.business.ICompany) {
|
|
|
|
// STATIC
|
2020-11-04 18:01:04 +00:00
|
|
|
// lets care about linked data
|
|
|
|
const companyLd = {
|
|
|
|
'@context': 'https://schema.org',
|
|
|
|
'@type': 'Corporation',
|
|
|
|
name: companyDataArg.name,
|
|
|
|
alternateName: companyDataArg.name.replace(' GmbH', ''),
|
|
|
|
url: companyDataArg.contact.website,
|
|
|
|
logo: companyDataArg.contact.logoUrl,
|
|
|
|
contactPoint: {
|
|
|
|
'@type': 'ContactPoint',
|
|
|
|
telephone: companyDataArg.contact.phone,
|
|
|
|
contactType: 'customer service',
|
|
|
|
areaServed: 'DE',
|
|
|
|
availableLanguage: ['en', 'German'],
|
|
|
|
},
|
|
|
|
sameAs: [],
|
|
|
|
};
|
2020-11-04 18:09:07 +00:00
|
|
|
|
2020-11-04 18:01:04 +00:00
|
|
|
if (companyDataArg.contact.facebookUrl) {
|
|
|
|
companyLd.sameAs.push(companyDataArg.contact.facebookUrl);
|
|
|
|
}
|
2020-11-04 18:09:07 +00:00
|
|
|
|
2020-11-04 18:01:04 +00:00
|
|
|
if (companyDataArg.contact.twitterUrl) {
|
|
|
|
companyLd.sameAs.push(companyDataArg.contact.twitterUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ldTag = new JsonLdTag(companyLd);
|
|
|
|
return ldTag;
|
|
|
|
}
|
|
|
|
|
2020-11-06 01:11:26 +00:00
|
|
|
public static createNewsArticleJsonLd(newsArticleArg: plugins.tsclass.content.IArticle) {
|
2020-11-04 18:31:25 +00:00
|
|
|
const newsArticleLd = {
|
2020-11-06 01:11:26 +00:00
|
|
|
'@context': 'https://schema.org',
|
|
|
|
'@type': 'NewsArticle',
|
|
|
|
mainEntityOfPage: {
|
|
|
|
'@type': 'WebPage',
|
|
|
|
'@id': window.location.href,
|
2020-11-04 18:31:25 +00:00
|
|
|
},
|
2020-11-06 01:11:26 +00:00
|
|
|
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}`,
|
2020-11-04 18:31:25 +00:00
|
|
|
},
|
2020-11-06 01:11:26 +00:00
|
|
|
publisher: {
|
|
|
|
'@type': 'Organization',
|
|
|
|
name: newsArticleArg.author.surName, // TODO
|
|
|
|
logo: {
|
|
|
|
'@type': 'ImageObject',
|
|
|
|
url: newsArticleArg.author.surName, // TODO
|
|
|
|
},
|
2020-11-04 18:31:25 +00:00
|
|
|
},
|
2020-11-06 01:11:26 +00:00
|
|
|
description: newsArticleArg.author.firstName,
|
2020-11-04 18:31:25 +00:00
|
|
|
};
|
2020-11-06 01:11:26 +00:00
|
|
|
const ldTag = new JsonLdTag(newsArticleLd);
|
2020-11-05 17:15:27 +00:00
|
|
|
return ldTag;
|
2020-11-04 18:31:25 +00:00
|
|
|
}
|
2023-05-07 18:24:53 +00:00
|
|
|
public static createProductJsonLd(
|
|
|
|
productArg: plugins.tsclass.saas.IProduct,
|
|
|
|
publisherArg: plugins.tsclass.business.ICompany
|
|
|
|
) {
|
|
|
|
const productLd = {
|
|
|
|
'@context': 'https://schema.org',
|
|
|
|
'@type': 'SoftwareApplication',
|
|
|
|
name: productArg.name,
|
|
|
|
description: productArg.description,
|
|
|
|
operatingSystem: productArg.os,
|
|
|
|
applicationCategory: productArg.category,
|
|
|
|
offers: {
|
|
|
|
'@type': 'Offer',
|
|
|
|
name: 'User-based Plan',
|
|
|
|
priceSpecification: {
|
|
|
|
'@type': 'PropertyValueSpecification',
|
|
|
|
valueName: 'Number of Users',
|
|
|
|
valueRequired: true,
|
|
|
|
price: '4.99',
|
|
|
|
priceCurrency: 'EUR',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
publisher: this.createCompanyJsonLd(publisherArg).elementRef.textContent,
|
|
|
|
screenshot: 'https://www.social.io/screenshot.png',
|
|
|
|
url: 'https://www.social.io/',
|
|
|
|
};
|
|
|
|
const ldTag = new JsonLdTag(productLd);
|
|
|
|
return ldTag;
|
|
|
|
}
|
2020-11-04 18:31:25 +00:00
|
|
|
|
2023-05-07 18:24:53 +00:00
|
|
|
// INSTANCE
|
2020-11-04 18:01:04 +00:00
|
|
|
constructor(ldObjectArg: any) {
|
|
|
|
super();
|
|
|
|
const jsonLdElement = document.createElement('script');
|
|
|
|
jsonLdElement.type = 'application/ld+json';
|
2020-11-05 20:03:12 +00:00
|
|
|
jsonLdElement.text = JSON.stringify(ldObjectArg);
|
2020-11-04 18:01:04 +00:00
|
|
|
this.elementRef = jsonLdElement;
|
|
|
|
}
|
2020-11-04 18:09:07 +00:00
|
|
|
}
|