Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/web/__tests__/unit/canonical-urls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ const expectedCanonicals: Array<{ file: string; canonical: string }> = [
file: "(site)/(seo)/google-chrome-screen-recorder/page.tsx",
canonical: "https://cap.so/google-chrome-screen-recorder",
},
{
file: "(site)/deactivate-license/page.tsx",
canonical: "https://cap.so/deactivate-license",
},
];

describe("Canonical URLs", () => {
Expand All @@ -136,4 +140,19 @@ describe("Canonical URLs", () => {
`canonical: \`https://cap.so/tools/convert/\${conversionPath}\``,
);
});

it("dynamic blog [slug] route generates canonical from the post slug", () => {
const content = readPage("(site)/blog/[slug]/page.tsx");
expect(content).toContain(
`canonical: \`https://cap.so/blog/\${post.slug}\``,
);
});

it("dynamic docs route generates canonical from the slug, with /docs as the docs home", () => {
const content = readPage("(docs)/docs/[[...slug]]/page.tsx");
expect(content).toContain(
`const docPath = isDocsHome ? "/docs" : \`/docs/\${slug}\`;`,
);
expect(content).toContain(`canonical: \`https://cap.so\${docPath}\``);
});
});
4 changes: 3 additions & 1 deletion apps/web/app/(docs)/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export async function generateMetadata(
// meaningless share card — present the landing page as the docs home.
const isDocsHome = slug === "introduction";
const pageTitle = isDocsHome ? "Cap Documentation" : `${title} - Cap Docs`;
const docPath = isDocsHome ? "/docs" : `/docs/${slug}`;
const description = summary || title;
const ogImage = image
? `${buildEnv.NEXT_PUBLIC_WEB_URL}${image}`
Expand All @@ -42,11 +43,12 @@ export async function generateMetadata(
return {
title: pageTitle,
description,
alternates: { canonical: `https://cap.so${docPath}` },
openGraph: {
title: pageTitle,
description,
type: "article",
url: `${buildEnv.NEXT_PUBLIC_WEB_URL}/docs/${slug}`,
url: `${buildEnv.NEXT_PUBLIC_WEB_URL}${docPath}`,
images: [{ url: ogImage, width: 1200, height: 630, alt: pageTitle }],
},
twitter: {
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/(site)/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export async function generateMetadata(
return {
title,
description,
alternates: { canonical: `https://cap.so/blog/${post.slug}` },
openGraph: {
title,
description,
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/(site)/deactivate-license/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const metadata: Metadata = {
title: "Deactivate License — Cap",
description:
"Deactivate your Cap commercial license from its current device to use it elsewhere.",
alternates: { canonical: "https://cap.so/deactivate-license" },
};

export default function App() {
Expand Down
Loading