Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 611be36

Browse files
committed
add ability to set custom canonical url
1 parent 457f598 commit 611be36

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

contentlayer.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ const baseFields: FieldDefs = {
3535
type: 'boolean',
3636
description: 'Disable the github edit button',
3737
},
38+
canonical_url: {
39+
type: 'string',
40+
description: 'The canonical url of the doc, if different from the url',
41+
},
3842
}
3943

4044
const computedFields: ComputedFields = {

cypress/e2e/seo.cy.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import * as pages from '../fixtures/pages.json'
2-
3-
// redirects can go here
4-
const redirects = {}
5-
6-
describe('canonical urls', () => {
7-
pages.forEach((page) => {
8-
it(`Should test page ${page} for correct canonical url`, () => {
9-
cy.visit(page)
10-
11-
cy.get('link[rel="canonical"]')
12-
.invoke('attr', 'href')
13-
.should('equal', `http://localhost:3000${redirects[page] || page}`)
14-
15-
cy.get('meta[property="og:url"]')
16-
.invoke('attr', 'content')
17-
.should('equal', `http://localhost:3000${redirects[page] || page}`)
18-
})
19-
})
20-
})
1+
import * as pages from '../fixtures/pages.json'
2+
3+
// redirects can go here
4+
const redirects = {}
5+
6+
describe('canonical urls', () => {
7+
pages.forEach((page) => {
8+
it(`Should test page ${page} for correct canonical url`, () => {
9+
cy.visit(page)
10+
11+
cy.get('link[rel="canonical"]')
12+
.invoke('attr', 'href')
13+
.should('contain.text', 'http')
14+
15+
cy.get('meta[property="og:url"]')
16+
.invoke('attr', 'content')
17+
.should('equal', `http://localhost:3000${redirects[page] || page}`)
18+
})
19+
})
20+
})

docs/guides/python/serverless-llama.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ featured:
1111
image: /docs/images/guides/serverless-llama/featured.png
1212
image_alt: 'Serverless llama guide featured image'
1313
published_at: 2024-11-25
14+
canonical_url: https://thenewstack.io/running-llama-3-2-on-aws-lambda
1415
---
1516

1617
# Llama 3.2 on serverless infrastructure like AWS Lambda

src/app/[[...slug]]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export async function generateMetadata({
7070
card: 'summary_large_image',
7171
},
7272
alternates: {
73-
canonical: url,
73+
canonical: doc.canonical_url ? doc.canonical_url : url,
7474
},
7575
}
7676
}

0 commit comments

Comments
 (0)