116 lines
3.4 KiB
JavaScript
116 lines
3.4 KiB
JavaScript
/** Safe for double-quoted HTML attributes */
|
|
const escAttr = (str) =>
|
|
String(str ?? "")
|
|
.replace(/&/g, "&")
|
|
.replace(/"/g, """)
|
|
.replace(/</g, "<");
|
|
|
|
/**
|
|
* Head tags for prerendered Hersteller (Manufacturers) page
|
|
*/
|
|
const generateHerstellerMetaTags = (baseUrl, config, manufacturerCount = 0) => {
|
|
const root = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
const herstellerUrl = root + "/Hersteller";
|
|
const site = config.siteName || config.brandName;
|
|
const desc = manufacturerCount + " Hersteller bei " + config.brandName + ": Top-Marken für Growshop-Produkte. Schnelle Lieferung, Laden Dresden.";
|
|
const descShort = desc.length > 160 ? desc.slice(0, 157) + "..." : desc;
|
|
const e = escAttr;
|
|
const logoUrl =
|
|
config.images && config.images.logo
|
|
? root + config.images.logo
|
|
: root + "/assets/images/nopicture.jpg";
|
|
|
|
return `
|
|
<meta name="description" content="${e(descShort)}">
|
|
<meta property="og:title" content="${e("Hersteller | " + site)}">
|
|
<meta property="og:description" content="${e(descShort)}">
|
|
<meta property="og:url" content="${herstellerUrl}">
|
|
<meta property="og:type" content="website">
|
|
<meta property="og:image" content="${e(logoUrl)}">
|
|
<meta property="og:site_name" content="${e(site)}">
|
|
<meta name="twitter:card" content="summary_large_image">
|
|
<meta name="twitter:title" content="${e("Hersteller | " + site)}">
|
|
<meta name="twitter:description" content="${e(descShort)}">
|
|
<meta name="robots" content="index, follow">
|
|
<link rel="canonical" href="${herstellerUrl}">
|
|
`;
|
|
};
|
|
|
|
const generateHerstellerJsonLd = (baseUrl, config) => {
|
|
const root = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
const herstellerUrl = root + "/Hersteller";
|
|
|
|
const id = {
|
|
business: root + "#business",
|
|
website: root + "#website",
|
|
breadcrumb: herstellerUrl + "#breadcrumb",
|
|
};
|
|
|
|
const logoUrl =
|
|
config.images && config.images.logo
|
|
? root + config.images.logo
|
|
: undefined;
|
|
|
|
const businessNode = {
|
|
"@id": id.business,
|
|
"@type": ["GardenStore", "LocalBusiness", "Organization"],
|
|
name: config.brandName,
|
|
url: root,
|
|
};
|
|
|
|
if (logoUrl) {
|
|
businessNode.logo = { "@type": "ImageObject", url: logoUrl };
|
|
businessNode.image = { "@type": "ImageObject", url: logoUrl };
|
|
}
|
|
|
|
const websiteNode = {
|
|
"@id": id.website,
|
|
"@type": "WebSite",
|
|
name: config.siteName || config.brandName,
|
|
url: root,
|
|
publisher: { "@id": id.business },
|
|
};
|
|
|
|
const breadcrumbNode = {
|
|
"@id": id.breadcrumb,
|
|
"@type": "BreadcrumbList",
|
|
itemListElement: [
|
|
{
|
|
"@type": "ListItem",
|
|
position: 1,
|
|
name: "Home",
|
|
item: root,
|
|
},
|
|
{
|
|
"@type": "ListItem",
|
|
position: 2,
|
|
name: "Hersteller",
|
|
item: herstellerUrl,
|
|
},
|
|
],
|
|
};
|
|
|
|
const collectionPageNode = {
|
|
"@id": herstellerUrl,
|
|
"@type": "CollectionPage",
|
|
name: "Hersteller",
|
|
url: herstellerUrl,
|
|
description: "Alle Hersteller und Marken für Growshop-Produkte",
|
|
isPartOf: { "@id": id.website },
|
|
breadcrumb: { "@id": id.breadcrumb },
|
|
};
|
|
|
|
const graph = [businessNode, websiteNode, breadcrumbNode, collectionPageNode];
|
|
|
|
const herstellerGraph = {
|
|
"@context": "https://schema.org",
|
|
"@graph": graph,
|
|
};
|
|
|
|
return "<script type=\"application/ld+json\">" + JSON.stringify(herstellerGraph) + "</script>";
|
|
};
|
|
|
|
module.exports = {
|
|
generateHerstellerMetaTags,
|
|
generateHerstellerJsonLd,
|
|
}; |