Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

help: Add canonical URL pointing to zulip.com.

Shubham Padiac3fdee6ed07c
diff --git a/starlight_help/src/route_data.ts b/starlight_help/src/route_data.ts
index 544109a1877..0d59c623918 100644
--- a/starlight_help/src/route_data.ts
+++ b/starlight_help/src/route_data.ts
@@ -33,4 +33,25 @@ export const onRequest = defineRouteMiddleware((context) => {
content: extractFirstParagraph(context.locals.starlightRoute.entry.body),
},
});
+
+ const canonicalUrl = `https://zulip.com/help/${context.locals.starlightRoute.id}`;
+ const existingCanonicalTag = context.locals.starlightRoute.head.find(
+ (item) => item.tag === "link" && item.attrs?.rel === "canonical",
+ );
+
+ if (existingCanonicalTag) {
+ existingCanonicalTag.attrs!.href = canonicalUrl;
+ } else {
+ // Starlight already has the canonical tag by default and this might
+ // never get executed in practice. But it feels like a nice-to-have
+ // if any upstream changes happen in starlight and that behaviour
+ // changes.
+ context.locals.starlightRoute.head.push({
+ tag: "link",
+ attrs: {
+ rel: "canonical",
+ href: canonicalUrl,
+ },
+ });
+ }
});