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
4 changes: 4 additions & 0 deletions site/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
User-agent: *
Allow: /

Sitemap: https://devstream.jamesconway.dev/sitemap.xml
13 changes: 13 additions & 0 deletions site/src/pages/404.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
import Base from "../layouts/Base.astro";
---

<!-- Without a 404.html, Cloudflare Pages serves the home page with a 200 for every unknown path. -->
<Base title="Page not found · DevStream" description="There is no page at this address.">
<section class="hero">
<div class="wrap">
<h1>Page not found</h1>
<p>There's nothing at this address. <a href="/">Back to the leaderboard</a>.</p>
</div>
</section>
</Base>
18 changes: 18 additions & 0 deletions site/src/pages/sitemap.xml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { loadAll } from "../lib/data.ts";

// Without this file Cloudflare Pages answers /sitemap.xml with the home page.
export function GET({ site }: { site: URL }) {
const paths = [
"/",
"/how-it-works/",
"/archived/",
...loadAll().categories.map((c) => `/category/${c.slug}/`),
];
const urls = paths
.map((p) => ` <url><loc>${new URL(p, site)}</loc></url>`)
.join("\n");
return new Response(
`<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls}\n</urlset>\n`,
{ headers: { "Content-Type": "application/xml" } },
);
}
22 changes: 22 additions & 0 deletions site/tests/dist.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,25 @@ test("the Trending tab marks exactly the rows trending() allows", async () => {
);
}
});

test("robots.txt, sitemap.xml and 404.html are real files", () => {
assert.match(
read("robots.txt"),
/Sitemap: https:\/\/devstream\.jamesconway\.dev\/sitemap\.xml/,
);
const sitemap = read("sitemap.xml");
const cats = JSON.parse(
readFileSync(join(fixtures, "categories.json"), "utf8"),
);
for (const p of [
"/",
"/how-it-works/",
"/archived/",
...cats.map((c) => `/category/${c.slug}/`),
])
assert.ok(
sitemap.includes(`<loc>https://devstream.jamesconway.dev${p}</loc>`),
p,
);
assert.ok(read("404.html").includes("Page not found"));
});
Loading