From 725242191c3fbff7024d8860a27a0ab26bd9e405 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Mon, 29 Apr 2024 19:02:49 +0200 Subject: [PATCH 1/3] fix(spas): set canonical url --- build/spas.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/build/spas.ts b/build/spas.ts index 1afb175a51a5..dce6f4644a08 100644 --- a/build/spas.ts +++ b/build/spas.ts @@ -19,6 +19,7 @@ import { CONTRIBUTOR_SPOTLIGHT_ROOT, BUILD_OUT_ROOT, DEV_MODE, + BASE_URL, } from "../libs/env/index.js"; import { isValidLocale } from "../libs/locale-utils/index.js"; import { DocFrontmatter, DocParent, NewsItem } from "../libs/types/document.js"; @@ -75,7 +76,7 @@ async function buildContributorSpotlight( }; const context = { hyData }; - const html = renderHTML(`/${locale}/${prefix}/${contributor}`, context); + const html = renderPage(`/${locale}/${prefix}/${contributor}`, context); const outPath = path.join( BUILD_OUT_ROOT, locale.toLowerCase(), @@ -113,6 +114,10 @@ export async function buildSPAs(options: { // The URL isn't very important as long as it triggers the right route in the const url = `/${DEFAULT_LOCALE}/404.html`; const html = renderHTML(url, { pageNotFound: true }); + html.replace( + '', + "" + ); const outPath = path.join( BUILD_OUT_ROOT, DEFAULT_LOCALE.toLowerCase(), @@ -185,7 +190,7 @@ export async function buildSPAs(options: { noIndexing, }; - const html = renderHTML(url, context); + const html = renderPage(url, context); const outPath = path.join(BUILD_OUT_ROOT, pathLocale, prefix); fs.mkdirSync(outPath, { recursive: true }); const filePath = path.join(outPath, "index.html"); @@ -242,7 +247,7 @@ export async function buildSPAs(options: { pageTitle: `${frontMatter.attributes.title || ""} | ${title}`, }; - const html = renderHTML(url, context); + const html = renderPage(url, context); const outPath = path.join( BUILD_OUT_ROOT, locale, @@ -342,7 +347,7 @@ export async function buildSPAs(options: { featuredArticles, }; const context = { hyData }; - const html = renderHTML(url, context); + const html = renderPage(url, context); const outPath = path.join(BUILD_OUT_ROOT, localeLC); fs.mkdirSync(outPath, { recursive: true }); const filePath = path.join(outPath, "index.html"); @@ -458,3 +463,12 @@ async function fetchLatestNews() { items, }; } + +function renderPage(url: string, context: any) { + const html = renderHTML(url, context); + html.replace( + ``, + `` + ); + return html; +} From fc1ac04afb7e5f412a1b0ff060a56a56b8ec636b Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Mon, 29 Apr 2024 19:14:32 +0200 Subject: [PATCH 2/3] fixup! fix(spas): set canonical url --- build/spas.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build/spas.ts b/build/spas.ts index dce6f4644a08..2fef3dce16e1 100644 --- a/build/spas.ts +++ b/build/spas.ts @@ -466,6 +466,11 @@ async function fetchLatestNews() { function renderPage(url: string, context: any) { const html = renderHTML(url, context); + // Better safe than sorry. + html.replace( + ``, + `` + ); html.replace( ``, `` From 30cfed4eed53b4fd9a0338233b7ebc233c737c6e Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Mon, 29 Apr 2024 19:16:43 +0200 Subject: [PATCH 3/3] fixup! fixup! fix(spas): set canonical url --- build/spas.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build/spas.ts b/build/spas.ts index 2fef3dce16e1..bc0206a5c5f6 100644 --- a/build/spas.ts +++ b/build/spas.ts @@ -465,15 +465,15 @@ async function fetchLatestNews() { } function renderPage(url: string, context: any) { - const html = renderHTML(url, context); + let html = renderHTML(url, context); + html = html.replace( + ``, + `` + ); // Better safe than sorry. - html.replace( + html = html.replace( ``, `` ); - html.replace( - ``, - `` - ); return html; }