Skip to content

Commit 99217d5

Browse files
authored
Merge pull request #631 from dzcode-io/fix/canonical-url
2 parents 175db46 + 106cd7c commit 99217d5

File tree

11 files changed

+17
-7
lines changed

11 files changed

+17
-7
lines changed

web/cloudflare/handler/contribution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export const handleContributionRequest: PagesFunction<Env> = async (context) =>
5656
const newData = htmlTemplate
5757
.replace(/{{template-title}}/g, pageTitle)
5858
.replace(/{{template-description}}/g, localize("contribute-description"))
59-
.replace(/{{template-lang}}/g, language);
59+
.replace(/{{template-lang}}/g, language)
60+
.replace(/{{template-canonical}}/g, `${fullstackConfig.web.url}${pathName}`);
6061

6162
return new Response(newData, { headers: { "content-type": "text/html; charset=utf-8" } });
6263
} catch (error) {

web/cloudflare/handler/contributor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export const handleContributorRequest: PagesFunction<Env> = async (context) => {
5555
const newData = htmlTemplate
5656
.replace(/{{template-title}}/g, pageTitle)
5757
.replace(/{{template-description}}/g, localize("team-description"))
58-
.replace(/{{template-lang}}/g, language);
58+
.replace(/{{template-lang}}/g, language)
59+
.replace(/{{template-canonical}}/g, `${fullstackConfig.web.url}${pathName}`);
5960

6061
return new Response(newData, { headers: { "content-type": "text/html; charset=utf-8" } });
6162
} catch (error) {

web/cloudflare/handler/project.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export const handleProjectRequest: PagesFunction<Env> = async (context) => {
5353
const newData = htmlTemplate
5454
.replace(/{{template-title}}/g, pageTitle)
5555
.replace(/{{template-description}}/g, localize("projects-description"))
56-
.replace(/{{template-lang}}/g, language);
56+
.replace(/{{template-lang}}/g, language)
57+
.replace(/{{template-canonical}}/g, `${fullstackConfig.web.url}${pathName}`);
5758

5859
return new Response(newData, { headers: { "content-type": "text/html; charset=utf-8" } });
5960
} catch (error) {

web/src/_build/gen-multiple-htmls.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import { readFileSync, writeFileSync, mkdirSync } from "fs";
77
import { allPages } from "./pages";
88
import { Environment, environments } from "@dzcode.io/utils/dist/config/environment";
99
import { SENTRY_ORIGIN } from "../../src/utils/sentry-origin";
10+
import { fsConfig } from "@dzcode.io/utils/dist/config";
1011

1112
let stage = process.env.STAGE as Environment;
1213
if (!environments.includes(stage)) {
1314
console.log(`⚠️ No STAGE provided, falling back to "development"`);
1415
stage = "development";
1516
}
1617

18+
const config = fsConfig(stage);
1719
const distFolder = "./bundle";
1820

1921
const indexHtmlPath = join(distFolder, "index.html");
@@ -56,6 +58,10 @@ allPages.forEach((pageInfo) => {
5658
newHtml = newHtml.replace(/{{keywords}}/g, pageInfo.keywords);
5759
newHtml = newHtml.replace(/{{title}}/g, pageInfo.title);
5860
newHtml = newHtml.replace(/{{description}}/g, pageInfo.description);
61+
newHtml = newHtml.replace(
62+
/{{canonical}}/g,
63+
pageInfo.canonicalUrl || `${config.web.url}${pageInfo.uri}`,
64+
);
5965
newHtml = newHtml.replace(/{{ogImage}}/g, pageInfo.ogImage);
6066
newHtml = newHtml.replace(/{{sentryOrigin}}/g, `https://${SENTRY_ORIGIN}`);
6167

web/src/_build/pages/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { templatePages } from "./template-pages";
66

77
export interface PageInfo {
88
uri: string;
9+
canonicalUrl?: string;
910
title: string;
1011
description: string;
1112
ogImage: string;

web/src/_build/pages/template-pages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export const templatePages: PageInfo[] = [
99
"https://images.unsplash.com/photo-1527285341945-715b98b98ea2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1200&h=627&q=80",
1010
keywords: "open-source, algeria, dzcode",
1111
lang: "{{template-lang}}" as unknown as PageInfo["lang"],
12+
canonicalUrl: "{{template-canonical}}",
1213
},
1314
];

web/src/_entry/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<title>{{title}}</title>
1717
<meta name="description" content="{{description}}" />
1818

19+
<!-- SEO -->
20+
<link rel="canonical" href="{{canonical}}" />
21+
1922
<!-- Facebook Meta Tags -->
2023
<meta property="og:type" content="website" />
2124
<meta property="og:title" content="{{title}}" />

web/src/pages/contribute/contribution/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export default function Page(): JSX.Element {
4141
{localize("contribution-title-post")}
4242
</title>
4343
<meta name="description" content={localize("contribute-description")} />
44-
{/* @TODO-ZM: add canonical url on all pages */}
4544
<link rel="canonical" href={getContributionURL(contribution)} />
4645
</Helmet>
4746
) : null}

web/src/pages/contribute/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export default function Page(): JSX.Element {
1818
dispatch(fetchContributionsListAction());
1919
}, [dispatch]);
2020

21-
// @TODO-ZM: add filters and search
2221
return (
2322
<main className="flex flex-col self-center">
2423
<Helmet>

web/src/pages/projects/project/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export default function Page(): JSX.Element {
4949
{localize("project-title-pre")} {project.name} {localize("project-title-post")}
5050
</title>
5151
<meta name="description" content={localize("projects-description")} />
52-
{/* @TODO-ZM: add canonical url on all pages */}
5352
<link rel="canonical" href={getProjectURL(project)} />
5453
</Helmet>
5554
) : null}

web/src/utils/contribution.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ export function getContributionURL({
44
id,
55
title,
66
}: Pick<ContributionEntity, "id" | "title">): string {
7-
// @TODO-ZM: use slug instead
87
return `/contribute/${title.replace(/\s/g, "-")}-${id}`;
98
}

0 commit comments

Comments
 (0)