Skip to content

Commit ce7556a

Browse files
committed
feat(site): list localized Console sitemaps in robots.txt
1 parent 12f2a2f commit ce7556a

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

‎services/site/src/lib/robots-txt.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
21
// /robots.txt: a machine interface around the agent message, served by src/middleware.ts. The
32
// rules are plain, and everything else is a "#" comment. The numbers in the comments are computed
43
// here, once per process, so edits can't make them wrong: each line's byte offset in the gutter,
54
// the file size, the CRC32 and SHA-256 of the rule lines, and the matrix verdicts from the rules.
65

6+
import { LOCALES } from "~/lib/language"
7+
78
const rules = ["User-agent: *", "Allow: /", "Disallow: /s/", "Disallow: /share/"]
8-
const sitemap = "Sitemap: https://opencode.ai/sitemap.xml"
9+
// The Console serves a sitemap per locale; English is already in the site's sitemap index.
10+
const sitemaps = [
11+
"Sitemap: https://opencode.ai/sitemap.xml",
12+
...LOCALES.filter((locale) => locale !== "en").map(
13+
(locale) => `Sitemap: https://opencode.ai/${locale}/console/sitemap.xml`,
14+
),
15+
]
916

1017
// The agent message, laid out to fit the payload frame.
1118
const message = [
@@ -71,7 +78,7 @@ export function robotsTxt() {
7178
}
7279

7380
async function build() {
74-
const ruleText = [...rules, sitemap].join("\n")
81+
const ruleText = [...rules, ...sitemaps].join("\n")
7582
const sha = [...new Uint8Array(await crypto.subtle.digest("SHA-256", encoder.encode(ruleText)))]
7683
.map((byte) => byte.toString(16).padStart(2, "0"))
7784
.join("")
@@ -89,15 +96,15 @@ async function build() {
8996
"",
9097
justify("OPENCODE.AI · ROBOTS.TXT · FOR AGENTS · UTF-8", `SHA-256(rules) ${sha.slice(0, 8)}`),
9198
"=".repeat(full),
92-
justify(`[BOOT] 0x${hex("OPENCODE")} ("OPENCODE") RULES ${rules.length} SITEMAP 1`, "OK"),
99+
justify(`[BOOT] 0x${hex("OPENCODE")} ("OPENCODE") RULES ${rules.length} SITEMAPS ${sitemaps.length}`, "OK"),
93100
justify("[LINK]", "GET /robots.txt -> 200 -> GET /llms.txt -> 200 -> GET *.md -> 200"),
94101
"",
95102
justify("PARSER COMPLIANCE MATRIX", "(computed from the rules)"),
96103
...matrix(),
97104
"",
98105
...frame(message, "DECODED PAYLOAD"),
99106
"",
100-
justify(`BASE64 ${btoa(sitemap.slice("Sitemap: ".length))}`, "(sitemap)"),
107+
justify(`BASE64 ${btoa(sitemaps[0].slice("Sitemap: ".length))}`, "(site sitemap)"),
101108
`-- EXECUTE ${"-".repeat(full - 11)}`,
102109
...rules.map((rule, i) => {
103110
const [label, value] = notes[i]
@@ -106,8 +113,8 @@ async function build() {
106113
}),
107114
"-".repeat(full),
108115
justify(`${rules.length} RULES LOADED · 0 ERRORS`, `CRC32(rules, comments stripped) ${crc}`),
109-
justify("SITEMAP", "NEXT LINE, A BARE URL WITH NO COMMENT"),
110-
{ raw: sitemap },
116+
justify("SITEMAPS", `NEXT ${sitemaps.length} LINES, ONE BARE URL EACH, NO COMMENT`),
117+
...sitemaps.map((line) => ({ raw: line })),
111118
leader("DESIGN AUTHORITY", "OBEY DAVID"),
112119
justify(`EOF · {SIZE} BYTES · CRC32(rules) ${crc}`, "END OF TRANSMISSION"),
113120
]

‎services/site/test/robots-txt.test.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
import { describe, expect, test } from "bun:test"
2+
import { LOCALES } from "../src/lib/language"
23
import { robotsTxt } from "../src/lib/robots-txt"
34

45
// Served at /robots.txt by src/middleware.ts.
56
const text = await robotsTxt()
67
const lines = text.replace(/\n$/, "").split("\n")
78
const directives = lines.filter((line) => !line.startsWith("#")).map((line) => line.replace(/\s*#.*$/, ""))
9+
const consoleSitemaps = LOCALES.filter((locale) => locale !== "en").map(
10+
(locale) => `Sitemap: https://opencode.ai/${locale}/console/sitemap.xml`,
11+
)
812
const encoder = new TextEncoder()
913

1014
describe("robots.txt", () => {
11-
test("has exactly the rules, in one group, then the sitemap", () => {
15+
test("has exactly the rules, in one group, then the sitemaps", () => {
1216
expect(directives).toEqual([
1317
"User-agent: *",
1418
"Allow: /",
1519
"Disallow: /s/",
1620
"Disallow: /share/",
1721
"Sitemap: https://opencode.ai/sitemap.xml",
22+
...consoleSitemaps,
1823
])
1924
const group = lines.slice(
2025
lines.findIndex((line) => line.startsWith("User-agent")),
@@ -24,6 +29,13 @@ describe("robots.txt", () => {
2429
expect(lines.find((line) => line.startsWith("Sitemap"))).toBe("Sitemap: https://opencode.ai/sitemap.xml")
2530
})
2631

32+
test("lists a Console sitemap for every non-English locale, and none for English", () => {
33+
const consoleLines = directives.filter((line) => line.endsWith("/console/sitemap.xml"))
34+
expect(consoleLines).toHaveLength(17)
35+
for (const locale of LOCALES)
36+
expect(directives.includes(`Sitemap: https://opencode.ai/${locale}/console/sitemap.xml`)).toBe(locale !== "en")
37+
})
38+
2739
test("decorates only in comments, within 80 columns", () => {
2840
expect(
2941
lines.filter((line) => !line.startsWith("#") && !/^(User-agent|Allow|Disallow|Sitemap): /.test(line)),

0 commit comments

Comments
 (0)