mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
help: Add canonical URL pointing to zulip.com.
Partially fixes #35110. We ideally want this only for self hosted installations since we want to point them to the right canonical URL. But we can have this for all pages since for zulip.com, this will be a self referencing URL.
This commit is contained in:
committed by
Tim Abbott
parent
94f8198072
commit
c3fdee6ed0
@@ -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,
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user