Skip to content

Commit 4b135a2

Browse files
authored
refactor: fix canonical urls (#33)
1 parent 26ce1e4 commit 4b135a2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/layouts/Layout.astro

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ const locale = getLocale(Astro.url);
1919
const phrases = getPhrases(locale);
2020
const title = props.title ? `${props.title} · Auth Wiki` : "Auth Wiki";
2121
const description = props.description ?? phrases.site.description;
22-
const canonical = new URL(Astro.url.pathname, Astro.site).href;
22+
// Needs to remove the file extension from the URL since Astro will add it in production when
23+
// build format is set to "file".
24+
const canonical = new URL(
25+
Astro.url.pathname.endsWith(".html")
26+
? Astro.url.pathname.slice(0, -5)
27+
: Astro.url.pathname,
28+
Astro.site,
29+
).href;
2330
---
2431

2532
<!doctype html>

0 commit comments

Comments
 (0)