Skip to content

Commit

Permalink
set canonical url for dynamic pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ZibanPirate committed Dec 31, 2024
1 parent b0fe587 commit a2a1695
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion web/cloudflare/handler/contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const handleContributionRequest: PagesFunction<Env> = async (context) =>
const newData = htmlTemplate
.replace(/{{template-title}}/g, pageTitle)
.replace(/{{template-description}}/g, localize("contribute-description"))
.replace(/{{template-lang}}/g, language);
.replace(/{{template-lang}}/g, language)
.replace(/{{template-canonical}}/g, `${fullstackConfig.web.url}${pathName}`);

return new Response(newData, { headers: { "content-type": "text/html; charset=utf-8" } });
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion web/cloudflare/handler/contributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export const handleContributorRequest: PagesFunction<Env> = async (context) => {
const newData = htmlTemplate
.replace(/{{template-title}}/g, pageTitle)
.replace(/{{template-description}}/g, localize("team-description"))
.replace(/{{template-lang}}/g, language);
.replace(/{{template-lang}}/g, language)
.replace(/{{template-canonical}}/g, `${fullstackConfig.web.url}${pathName}`);

return new Response(newData, { headers: { "content-type": "text/html; charset=utf-8" } });
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion web/cloudflare/handler/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export const handleProjectRequest: PagesFunction<Env> = async (context) => {
const newData = htmlTemplate
.replace(/{{template-title}}/g, pageTitle)
.replace(/{{template-description}}/g, localize("projects-description"))
.replace(/{{template-lang}}/g, language);
.replace(/{{template-lang}}/g, language)
.replace(/{{template-canonical}}/g, `${fullstackConfig.web.url}${pathName}`);

return new Response(newData, { headers: { "content-type": "text/html; charset=utf-8" } });
} catch (error) {
Expand Down
5 changes: 4 additions & 1 deletion web/src/_build/gen-multiple-htmls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ allPages.forEach((pageInfo) => {
newHtml = newHtml.replace(/{{keywords}}/g, pageInfo.keywords);
newHtml = newHtml.replace(/{{title}}/g, pageInfo.title);
newHtml = newHtml.replace(/{{description}}/g, pageInfo.description);
newHtml = newHtml.replace(/{{canonical}}/g, `${config.web.url}${pageInfo.uri}`);
newHtml = newHtml.replace(
/{{canonical}}/g,
pageInfo.canonicalUrl || `${config.web.url}${pageInfo.uri}`,
);
newHtml = newHtml.replace(/{{ogImage}}/g, pageInfo.ogImage);
newHtml = newHtml.replace(/{{sentryOrigin}}/g, `https://${SENTRY_ORIGIN}`);

Expand Down
1 change: 1 addition & 0 deletions web/src/_build/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { templatePages } from "./template-pages";

export interface PageInfo {
uri: string;
canonicalUrl?: string;
title: string;
description: string;
ogImage: string;
Expand Down
1 change: 1 addition & 0 deletions web/src/_build/pages/template-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export const templatePages: PageInfo[] = [
"https://images.unsplash.com/photo-1527285341945-715b98b98ea2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1200&h=627&q=80",
keywords: "open-source, algeria, dzcode",
lang: "{{template-lang}}" as unknown as PageInfo["lang"],
canonicalUrl: "{{template-canonical}}",
},
];

0 comments on commit a2a1695

Please sign in to comment.