Skip to content
Merged
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
13 changes: 13 additions & 0 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Html, Head, Main, NextScript } from "next/document";

export default function Document() {
return (
<Html lang="en">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
1 change: 1 addition & 0 deletions scripts/seo-build.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function links(html) {
for (const route of routes) {
test(`built metadata: ${route}`, () => {
const html = read(`.next/server/pages${route === "/" ? "/index" : route}.html`);
assert.match(html, /<html\b[^>]*\slang="en"(?:\s|>)/, "English pages must declare their document language");
const tags = links(html);
const { canonicalUrl, chineseUrl } = getPageUrls(route);
assert.deepEqual(tags.filter((link) => link.rel === "canonical").map((link) => link.href), [canonicalUrl]);
Expand Down
4 changes: 4 additions & 0 deletions scripts/seo.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { getPageUrls, hasChineseTranslation, normalizePath } from "../lib/seo.mj
const root = new URL("../", import.meta.url);
const read = (path) => readFileSync(new URL(path, root), "utf8");

test("English document declares its language before client rendering", () => {
assert.match(read("pages/_document.tsx"), /<Html\s+lang="en">/);
});

test("canonical paths exclude queries, fragments, and trailing slashes", () => {
for (const path of [undefined, "", "/", "/?utm_source=test#top"]) {
assert.equal(normalizePath(path), "/");
Expand Down
Loading