From 046205327c4661d756e58684a39ca3fa9a065e20 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Tue, 22 Apr 2025 10:48:23 +0100 Subject: [PATCH 1/8] Fixed issue with canonical URLs containing query strings --- src/components/seo.jsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/seo.jsx b/src/components/seo.jsx index a66ad942..8c1afa5a 100644 --- a/src/components/seo.jsx +++ b/src/components/seo.jsx @@ -1,10 +1,15 @@ import Head from "next/head"; export default function SEO({ title, description, imageUrl, url }) { - const canonicalUrl = url - ? // eslint-disable-next-line no-restricted-globals, n/prefer-global/process, n/prefer-global/url - new URL(url, process.env.NEXT_PUBLIC_SITE_URL) - : undefined; + let canonicalUrl = false; + + if (url) { + // eslint-disable-next-line no-restricted-globals, n/prefer-global/process, n/prefer-global/url + const urlObject = new URL(url, process.env.NEXT_PUBLIC_SITE_URL); + // Remove any query string as search is writable so we remove any potential query string + urlObject.search = ""; + canonicalUrl = urlObject.toString(); + } return ( From 2e20c55a1e7c8d25c7a97ecca2ca81fe6aee63ad Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Tue, 22 Apr 2025 10:53:08 +0100 Subject: [PATCH 2/8] Update src/components/seo.jsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/components/seo.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/seo.jsx b/src/components/seo.jsx index 8c1afa5a..3781a7ac 100644 --- a/src/components/seo.jsx +++ b/src/components/seo.jsx @@ -1,7 +1,7 @@ import Head from "next/head"; export default function SEO({ title, description, imageUrl, url }) { - let canonicalUrl = false; + let canonicalUrl = undefined; if (url) { // eslint-disable-next-line no-restricted-globals, n/prefer-global/process, n/prefer-global/url From 5d46196ff14c0e4b863e73639f0ade6a0954d4f1 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Tue, 22 Apr 2025 11:00:45 +0100 Subject: [PATCH 3/8] Reverting change. --- src/components/seo.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/seo.jsx b/src/components/seo.jsx index 3781a7ac..8c1afa5a 100644 --- a/src/components/seo.jsx +++ b/src/components/seo.jsx @@ -1,7 +1,7 @@ import Head from "next/head"; export default function SEO({ title, description, imageUrl, url }) { - let canonicalUrl = undefined; + let canonicalUrl = false; if (url) { // eslint-disable-next-line no-restricted-globals, n/prefer-global/process, n/prefer-global/url From 08b7d3ef9e9580e421d5a16ee4042dff6ea83fe9 Mon Sep 17 00:00:00 2001 From: Alexander Georgiev Date: Mon, 5 May 2025 19:16:36 +0300 Subject: [PATCH 4/8] fix: cannonicalUrl for Docs --- src/components/docs-layout.jsx | 9 +++++++-- src/components/seo.jsx | 14 +++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/components/docs-layout.jsx b/src/components/docs-layout.jsx index 48fec74b..5dd2b012 100644 --- a/src/components/docs-layout.jsx +++ b/src/components/docs-layout.jsx @@ -32,6 +32,8 @@ const flattenRoutes = (routeConfig) => { return flatRoutes; }; +const stripQueryParameters = (path) => path.split("?")[0]; + export default function DocumentPage({ children, docsNavData: routes, @@ -39,16 +41,19 @@ export default function DocumentPage({ }) { const flatRoutes = flattenRoutes(routes); const { - asPath, + asPath: rawAsPath, query: { slug = [] }, } = useRouter(); + // Use the outer-scoped function + const cannonicalUrl = stripQueryParameters(rawAsPath); + return ( <> path.split("?")[0]; + canonicalUrl = stripQueryParameters(url); + canonicalUrl = new URL(canonicalUrl, process.env.NEXT_PUBLIC_SITE_URL); + } + return ( From c4856d699083c66558cf21e57e631eb1aa7b1dff Mon Sep 17 00:00:00 2001 From: Alexander Georgiev Date: Fri, 9 May 2025 14:48:39 +0300 Subject: [PATCH 5/8] fix: use router query params --- src/components/docs-layout.jsx | 14 ++++++++------ src/components/seo.jsx | 14 +++----------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/components/docs-layout.jsx b/src/components/docs-layout.jsx index 5dd2b012..cb85515c 100644 --- a/src/components/docs-layout.jsx +++ b/src/components/docs-layout.jsx @@ -32,8 +32,6 @@ const flattenRoutes = (routeConfig) => { return flatRoutes; }; -const stripQueryParameters = (path) => path.split("?")[0]; - export default function DocumentPage({ children, docsNavData: routes, @@ -41,19 +39,23 @@ export default function DocumentPage({ }) { const flatRoutes = flattenRoutes(routes); const { - asPath: rawAsPath, query: { slug = [] }, } = useRouter(); - // Use the outer-scoped function - const cannonicalUrl = stripQueryParameters(rawAsPath); + // Build the path from slug + const canonicalPath = + Array.isArray(slug) && slug.length > 0 + ? `/docs/${slug.join("/")}/` + : "/docs/"; + + const canonicalUrl = `${canonicalPath}`; return ( <> path.split("?")[0]; - canonicalUrl = stripQueryParameters(url); - canonicalUrl = new URL(canonicalUrl, process.env.NEXT_PUBLIC_SITE_URL); - } - return ( From 885d019a410f9f9b07f4d4d0742fd22e7b555eae Mon Sep 17 00:00:00 2001 From: Alex Moon Date: Tue, 13 May 2025 13:07:46 -0700 Subject: [PATCH 6/8] fix: extend ISR cache time --- src/pages/docs/[[...slug]].jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/docs/[[...slug]].jsx b/src/pages/docs/[[...slug]].jsx index 21fd2bf7..97cea921 100644 --- a/src/pages/docs/[[...slug]].jsx +++ b/src/pages/docs/[[...slug]].jsx @@ -16,7 +16,7 @@ export async function getStaticProps({ params }) { source, docsNavData, }, - revalidate: 1, + revalidate: 600, }; } catch (error) { if (error.notFound) { From a661ca991b71e69ba606dac032689c83510b24a5 Mon Sep 17 00:00:00 2001 From: Alex Moon Date: Tue, 13 May 2025 13:08:18 -0700 Subject: [PATCH 7/8] fix: simplify code --- src/components/docs-layout.jsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/components/docs-layout.jsx b/src/components/docs-layout.jsx index cb85515c..bd55d506 100644 --- a/src/components/docs-layout.jsx +++ b/src/components/docs-layout.jsx @@ -42,13 +42,8 @@ export default function DocumentPage({ query: { slug = [] }, } = useRouter(); - // Build the path from slug - const canonicalPath = - Array.isArray(slug) && slug.length > 0 - ? `/docs/${slug.join("/")}/` - : "/docs/"; - - const canonicalUrl = `${canonicalPath}`; + // Build the canonical path from slug + const canonicalUrl = ["/docs", ...slug].join("/") + "/"; return ( <> From 274cdba8dd002a53632cea1b2beff6c7a817ee34 Mon Sep 17 00:00:00 2001 From: Alex Moon Date: Tue, 13 May 2025 13:08:36 -0700 Subject: [PATCH 8/8] refactor: remove unused code --- package.json | 1 - pnpm-lock.yaml | 3 --- src/lib/remark-parsing.mjs | 23 ----------------------- 3 files changed, 27 deletions(-) diff --git a/package.json b/package.json index 6f6010fa..2ad68b72 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,6 @@ "shiki": "^3.2.1", "strip-markdown": "^6.0.0", "unified": "^11.0.5", - "unist-util-visit": "^5.0.0", "vfile-matter": "^5.0.1" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 04b040c3..bebb6f0e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -123,9 +123,6 @@ importers: unified: specifier: ^11.0.5 version: 11.0.5 - unist-util-visit: - specifier: ^5.0.0 - version: 5.0.0 vfile-matter: specifier: ^5.0.1 version: 5.0.1 diff --git a/src/lib/remark-parsing.mjs b/src/lib/remark-parsing.mjs index b18671c4..9f533e1d 100644 --- a/src/lib/remark-parsing.mjs +++ b/src/lib/remark-parsing.mjs @@ -13,7 +13,6 @@ import withSmartQuotes from "remark-smartypants"; import remarkStringify from "remark-stringify"; import remarkStrip from "strip-markdown"; import { unified } from "unified"; -import { visit } from "unist-util-visit"; import { matter } from "vfile-matter"; import { getRemoteImgUrl } from "./remote-mdx-files.mjs"; /** @@ -36,28 +35,6 @@ function addFrontmatterToVFile() { return (_, file) => matter(file); } -export function addTocToVFile() { - return (tree, file) => { - const toc = []; - visit(tree, "element", (node) => { - if ( - (node.tagName === "h2" || node.tagName === "h3") && - node.children[0].value - ) { - const title = node.children[0]?.value; - - toc.push({ - id: node.properties.id, - text: title, - level: Number.parseInt(node.tagName[1], 10), - }); - } - }); - - file.data.toc = toc; - }; -} - /** * Returns the parsed content of a document from its markdown content. *