Skip to content

Commit 821467f

Browse files
authored
fix: broken canonical urls (#26)
1 parent 84c793c commit 821467f

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

src/Layout.astro

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
TWITTER_CREATOR,
1818
BOOK_AUTHORS,
1919
THEME_COLOR,
20-
CANONICAL_URL,
2120
} from '@lib/const'
2221
2322
export interface Props {
@@ -35,7 +34,7 @@ const {
3534
ogTitle = OG_TITLE,
3635
ogDescription = OG_DESCRIPTION,
3736
ogImage = OG_IMAGE,
38-
canonical = CANONICAL_URL,
37+
canonical,
3938
} = Astro.props
4039
---
4140

@@ -64,7 +63,7 @@ const {
6463
<meta name="theme-color" content={THEME_COLOR} />
6564

6665
<!-- Canonical URL -->
67-
<link rel="canonical" href={canonical} />
66+
{canonical && <link rel="canonical" href={canonical} />}
6867

6968
<!-- RSS Feed -->
7069
<link

src/components/blog/BlogLayout.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ if (post.rendered?.metadata?.headings) {
6464
description={description}
6565
ogTitle={title}
6666
ogDescription={description}
67+
canonical={`${SITE_URL}/blog/${post.id}`}
6768
>
6869
<main class="min-h-screen bg-base-100">
6970
<!-- Blog Header -->

src/lib/const.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const BOOK_EDITION = 'Fourth Edition'
3939
export const BOOK_PUBLICATION_DATE = '2025-10-09'
4040

4141
// Additional
42-
export const CANONICAL_URL = 'https://nodejsdesignpatterns.com'
42+
export const DEFAULT_CANONICAL_URL = 'https://nodejsdesignpatterns.com'
4343
export const THEME_COLOR = '#16a34a' // Green color from the design
4444

4545
// Free chapter

src/pages/blog/index.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import BlogCard from '../../components/blog/BlogCard.astro'
55
import Breadcrumb from '@components/blog/Breadcrumb.astro'
66
import Footer from '@components/Footer.astro'
77
import BookPromo from '@components/blog/BookPromo.astro'
8+
import { SITE_URL } from '@lib/const'
89
910
// Get all blog posts, sorted by date (newest first)
1011
const posts = (await getCollection('blog')).sort(
@@ -21,6 +22,7 @@ const pageDescription =
2122
description={pageDescription}
2223
ogTitle="Blog - Node.js Design Patterns"
2324
ogDescription={pageDescription}
25+
canonical={`${SITE_URL}/blog/`}
2426
>
2527
<main class="min-h-screen bg-base-100">
2628
<header class="bg-gradient-to-b from-primary/40 to-primary/10">

src/pages/index.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import FreeChapter from '@components/pages/Home/FreeChapter.astro'
1515
import Faq from '@components/pages/Home/Faq.astro'
1616
import Navigation from '@components/Navigation.astro'
1717
import Footer from '@components/Footer.astro'
18+
import { DEFAULT_CANONICAL_URL } from '@lib/const'
1819
---
1920

20-
<Layout>
21+
<Layout canonical={`${DEFAULT_CANONICAL_URL}/`}>
2122
<Navigation />
2223
<Hero />
2324
<Counters />

0 commit comments

Comments
 (0)