Feat: JsonLd product metadata (#2)

* Generates JSON ld structured metadata from a product & appends to head

* Updated IProduct & IVariation interface

* Added IProductResponse & IProductsResponse interfaces

* Fixed sitemap urls having to many protocols
This commit is contained in:
2022-11-28 22:19:32 +01:00
committed by GitHub
parent f3751da335
commit 296cfb80a0
17 changed files with 103 additions and 45 deletions

View File

@@ -41,18 +41,16 @@ export async function GET() {
return new Response(body, { headers });
}
function buildSitemapUrl(address: string, modified: string, frequency: string) {
function buildSitemapUrl(path: string, modified: string, frequency: string) {
return `<url>
<loc>https://${address}</loc>
<loc>https://${domain}${path}</loc>
<lastmod>${modified}</lastmod>
<changefreq>${frequency}</changefreq>
</url>`;
}
function sitemapPages(): string {
return pages
.map((page) => buildSitemapUrl(`https://${domain}/${page.name}`, page.modified, 'yearly'))
.join('\n');
return pages.map((page) => buildSitemapUrl(`/${page.name}`, page.modified, 'yearly')).join('\n');
}
async function sitemapShopPages(): Promise<string> {
@@ -66,11 +64,7 @@ async function sitemapShopPages(): Promise<string> {
return products?.products
?.map((product) =>
buildSitemapUrl(
`https://${domain}/shop/${product.product_no}`,
String(product.updated),
'daily'
)
buildSitemapUrl(`/shop/${product.product_no}`, String(product.updated), 'daily')
)
.join('\n');
}