@rimelight/seo 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/index.d.mts +8 -38
  2. package/dist/index.mjs +8 -175
  3. package/dist/integration.d.mts +6 -0
  4. package/dist/integration.mjs +101 -0
  5. package/dist/llms-BVLxzjr-.d.mts +41 -0
  6. package/dist/llms.d.mts +2 -0
  7. package/dist/llms.mjs +75 -0
  8. package/dist/meta.d.mts +42 -0
  9. package/dist/meta.mjs +66 -0
  10. package/dist/og.d.mts +117 -0
  11. package/dist/og.mjs +302 -0
  12. package/dist/robots.d.mts +3 -4
  13. package/dist/routes/llms-full.txt.d.mts +5 -0
  14. package/dist/routes/llms-full.txt.mjs +57 -0
  15. package/dist/routes/llms.txt.d.mts +5 -0
  16. package/dist/routes/llms.txt.mjs +68 -0
  17. package/dist/routes/robots.txt.d.mts +4 -0
  18. package/dist/routes/robots.txt.mjs +46 -0
  19. package/dist/routes/rss.xml.d.mts +4 -0
  20. package/dist/routes/rss.xml.mjs +51 -0
  21. package/dist/routes/sitemap.xml.d.mts +4 -0
  22. package/dist/routes/sitemap.xml.mjs +27 -0
  23. package/dist/rss.d.mts +8 -0
  24. package/dist/rss.mjs +44 -0
  25. package/dist/schema-C8v69blQ.d.mts +28 -0
  26. package/dist/schema.d.mts +2 -0
  27. package/dist/schema.mjs +52 -0
  28. package/dist/sitemap.d.mts +6 -7
  29. package/dist/types.d.mts +354 -2
  30. package/package.json +24 -5
  31. package/src/components/SEOHead.astro +65 -18
  32. package/src/env.d.ts +33 -3
  33. package/src/index.ts +19 -1
  34. package/src/integration.ts +172 -0
  35. package/src/meta.test.ts +25 -1
  36. package/src/meta.ts +32 -2
  37. package/src/og.ts +444 -0
  38. package/src/routes/llms-full.txt.ts +77 -0
  39. package/src/routes/llms.txt.ts +90 -0
  40. package/src/routes/robots.txt.ts +63 -0
  41. package/src/routes/rss.xml.ts +87 -0
  42. package/src/routes/sitemap.xml.ts +43 -0
  43. package/src/rss.test.ts +28 -0
  44. package/src/rss.ts +63 -0
  45. package/src/types.ts +367 -242
  46. package/dist/types-e7gqYZwc.d.mts +0 -305
package/src/og.ts ADDED
@@ -0,0 +1,444 @@
1
+ /**
2
+ * Font configuration for OG image rendering. Pass to `loadOgFonts()` or `renderOgResponse()`.
3
+ */
4
+ export interface OgFontConfig {
5
+ /**
6
+ * Font-family name referenced in layout styles
7
+ */
8
+ name: string
9
+ /**
10
+ * URL to the regular-weight TTF
11
+ */
12
+ regularUrl: string
13
+ /**
14
+ * URL to the bold-weight TTF
15
+ */
16
+ boldUrl: string
17
+ }
18
+
19
+ /**
20
+ * Default font: Noto Sans from jsDelivr Fontsource CDN.
21
+ */
22
+ export const NOTO_SANS: OgFontConfig = {
23
+ name: "Noto Sans",
24
+ regularUrl: "https://cdn.jsdelivr.net/fontsource/fonts/noto-sans@latest/latin-400-normal.ttf",
25
+ boldUrl: "https://cdn.jsdelivr.net/fontsource/fonts/noto-sans@latest/latin-700-normal.ttf"
26
+ }
27
+
28
+ /**
29
+ * Options for the default OG image layout. Build your own layout instead via `renderOgResponse()`
30
+ * directly.
31
+ */
32
+ export interface OgLayoutOptions {
33
+ /**
34
+ * Main heading -- required
35
+ */
36
+ title: string
37
+ /**
38
+ * Subtitle / excerpt beneath the title
39
+ */
40
+ description?: string
41
+ /**
42
+ * Branding shown top-left. Pass a plain string (site name) or a pre-built takumi-js VNode for a
43
+ * custom logo treatment.
44
+ */
45
+ brand?: string | object
46
+ /**
47
+ * Pill badge shown bottom-left. e.g. "Blog Post", "Documentation", "Legal"
48
+ */
49
+ badge?: string
50
+ /**
51
+ * Date string shown bottom-right. e.g. new Date(postedAt).toLocaleDateString()
52
+ */
53
+ date?: string
54
+ /**
55
+ * Background style. "dark" -> solid #0a0a0a (default) "gradient" -> diagonal dark-to-navy
56
+ * gradient any string -> treated as a CSS `background` value
57
+ */
58
+ background?: "dark" | "gradient" | (string & {})
59
+ /**
60
+ * When true, overlays a dashed red PREVIEW border. Useful during development.
61
+ */
62
+ preview?: boolean
63
+ }
64
+
65
+ /**
66
+ * Rendering config shared by `renderOgResponse()` and `renderDefaultOg()`.
67
+ */
68
+ export interface OgRenderConfig {
69
+ /**
70
+ * Font to embed -- defaults to `NOTO_SANS`
71
+ */
72
+ font?: OgFontConfig
73
+ /**
74
+ * Image width in px -- defaults to 1200
75
+ */
76
+ width?: number
77
+ /**
78
+ * Image height in px -- defaults to 630
79
+ */
80
+ height?: number
81
+ }
82
+
83
+ // ---------------------------------------------------------------------------
84
+ // Font loading
85
+ // ---------------------------------------------------------------------------
86
+
87
+ const fontCaches = new Map<string, { regular: ArrayBuffer; bold: ArrayBuffer }>()
88
+
89
+ /**
90
+ * Fetches an ArrayBuffer with a timeout.
91
+ */
92
+ async function fetchArrayBuffer(url: string, timeoutMs = 5000): Promise<ArrayBuffer> {
93
+ const controller = new AbortController()
94
+ const timeoutId = setTimeout(() => controller.abort(), timeoutMs)
95
+ try {
96
+ const res = await fetch(url, { signal: controller.signal })
97
+ if (!res.ok) {
98
+ throw new Error(`Failed to fetch font from ${url}: status ${res.status}`)
99
+ }
100
+ return await res.arrayBuffer()
101
+ } finally {
102
+ clearTimeout(timeoutId)
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Fetches and caches the regular + bold TTF buffers for the given font config. Uses a module-level
108
+ * cache keyed on `regularUrl`, so repeated calls within the same Worker lifetime are free after the
109
+ * first fetch.
110
+ */
111
+ export async function loadOgFonts(
112
+ config: OgFontConfig = NOTO_SANS,
113
+ timeoutMs = 5000
114
+ ): Promise<{ regular: ArrayBuffer; bold: ArrayBuffer }> {
115
+ const cached = fontCaches.get(config.regularUrl)
116
+ if (cached) return cached
117
+
118
+ const [regular, bold] = await Promise.all([
119
+ fetchArrayBuffer(config.regularUrl, timeoutMs),
120
+ fetchArrayBuffer(config.boldUrl, timeoutMs)
121
+ ])
122
+ const result = { regular, bold }
123
+ fontCaches.set(config.regularUrl, result)
124
+ return result
125
+ }
126
+
127
+ // ---------------------------------------------------------------------------
128
+ // Default layout builder
129
+ // ---------------------------------------------------------------------------
130
+
131
+ /**
132
+ * Builds a takumi-js-compatible VNode for the default Rimelight OG layout.
133
+ *
134
+ * Consumers that need a fully custom look should build their own VNode and call
135
+ * `renderOgResponse()` directly -- this function is just the house style.
136
+ */
137
+ export function defaultOgLayout(options: OgLayoutOptions, font: OgFontConfig = NOTO_SANS): object {
138
+ const {
139
+ title = "",
140
+ description,
141
+ brand,
142
+ badge,
143
+ date,
144
+ background = "dark",
145
+ preview = false
146
+ } = options
147
+
148
+ const MAX_TITLE_LEN = 160
149
+ const MAX_DESC_LEN = 240
150
+ const safeTitle = title.length > MAX_TITLE_LEN ? title.slice(0, MAX_TITLE_LEN - 1) + "…" : title
151
+ const safeDescription =
152
+ description && description.length > MAX_DESC_LEN
153
+ ? description.slice(0, MAX_DESC_LEN - 1) + "…"
154
+ : description
155
+
156
+ const bg =
157
+ background === "dark"
158
+ ? { backgroundColor: "#0a0a0a" }
159
+ : background === "gradient"
160
+ ? { background: "linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 100%)" }
161
+ : { background }
162
+
163
+ const isGradient = background !== "dark"
164
+
165
+ const brandNode: object =
166
+ typeof brand === "object" && brand !== null
167
+ ? brand
168
+ : {
169
+ type: "span",
170
+ props: {
171
+ style: {
172
+ fontSize: "28px",
173
+ fontWeight: 700,
174
+ color: "#ffffff",
175
+ letterSpacing: "-0.02em"
176
+ },
177
+ children: brand ?? ""
178
+ }
179
+ }
180
+
181
+ const accentBar: object | null = isGradient
182
+ ? {
183
+ type: "div",
184
+ props: {
185
+ style: {
186
+ width: "60px",
187
+ height: "4px",
188
+ backgroundColor: "#60a5fa",
189
+ borderRadius: "2px",
190
+ marginBottom: "16px"
191
+ }
192
+ }
193
+ }
194
+ : null
195
+
196
+ const titleFontSize = isGradient ? "52px" : "56px"
197
+ const descColor = isGradient ? "#94a3b8" : "#a0a0a0"
198
+ const descFontSize = isGradient ? "22px" : "24px"
199
+
200
+ const badgeNode: object | null = badge
201
+ ? isGradient
202
+ ? {
203
+ type: "div",
204
+ props: {
205
+ style: {
206
+ padding: "6px 16px",
207
+ borderRadius: "9999px",
208
+ backgroundColor: "rgba(96,165,250,0.15)",
209
+ border: "1px solid rgba(96,165,250,0.3)",
210
+ fontSize: "14px",
211
+ fontWeight: 600,
212
+ color: "#93c5fd"
213
+ },
214
+ children: badge
215
+ }
216
+ }
217
+ : {
218
+ type: "div",
219
+ props: {
220
+ style: {
221
+ padding: "8px 20px",
222
+ borderRadius: "9999px",
223
+ border: "1px solid #333333",
224
+ fontSize: "16px",
225
+ fontWeight: 600,
226
+ color: "#e5e5e5"
227
+ },
228
+ children: badge
229
+ }
230
+ }
231
+ : null
232
+
233
+ const dateNode: object | null = date
234
+ ? {
235
+ type: "div",
236
+ props: {
237
+ style: { fontSize: "16px", color: "#666666" },
238
+ children: date
239
+ }
240
+ }
241
+ : null
242
+
243
+ const previewOverlay: object | null = preview
244
+ ? {
245
+ type: "div",
246
+ props: {
247
+ style: {
248
+ position: "absolute",
249
+ inset: 0,
250
+ border: "6px dashed #ff4444",
251
+ pointerEvents: "none"
252
+ }
253
+ }
254
+ }
255
+ : null
256
+
257
+ const previewLabel: object | null = preview
258
+ ? {
259
+ type: "div",
260
+ props: {
261
+ style: {
262
+ position: "absolute",
263
+ top: "12px",
264
+ right: "12px",
265
+ backgroundColor: "#ff4444",
266
+ color: "#ffffff",
267
+ fontSize: "14px",
268
+ fontWeight: 700,
269
+ padding: "6px 16px",
270
+ borderRadius: "4px",
271
+ letterSpacing: "0.05em"
272
+ },
273
+ children: "PREVIEW"
274
+ }
275
+ }
276
+ : null
277
+
278
+ return {
279
+ type: "div",
280
+ props: {
281
+ style: {
282
+ width: "100%",
283
+ height: "100%",
284
+ display: "flex",
285
+ flexDirection: "column",
286
+ padding: "56px",
287
+ color: "#e5e5e5",
288
+ fontFamily: font.name,
289
+ position: "relative",
290
+ overflow: "hidden",
291
+ ...bg
292
+ },
293
+ children: [
294
+ {
295
+ type: "div",
296
+ props: {
297
+ style: { display: "flex", alignItems: "center" },
298
+ children: [brandNode]
299
+ }
300
+ },
301
+ {
302
+ type: "div",
303
+ props: {
304
+ style: {
305
+ display: "flex",
306
+ flexDirection: "column",
307
+ justifyContent: "center",
308
+ flexGrow: 1,
309
+ paddingTop: "24px"
310
+ },
311
+ children: [
312
+ accentBar,
313
+ {
314
+ type: "div",
315
+ props: {
316
+ style: {
317
+ fontSize: titleFontSize,
318
+ fontWeight: 700,
319
+ color: "#ffffff",
320
+ lineHeight: 1.15,
321
+ maxWidth: "950px"
322
+ },
323
+ children: safeTitle
324
+ }
325
+ },
326
+ safeDescription
327
+ ? {
328
+ type: "div",
329
+ props: {
330
+ style: {
331
+ fontSize: descFontSize,
332
+ fontWeight: 400,
333
+ color: descColor,
334
+ marginTop: isGradient ? "12px" : "16px",
335
+ lineHeight: 1.4,
336
+ maxWidth: isGradient ? "800px" : "850px"
337
+ },
338
+ children: safeDescription
339
+ }
340
+ }
341
+ : null
342
+ ].filter(Boolean)
343
+ }
344
+ },
345
+ {
346
+ type: "div",
347
+ props: {
348
+ style: {
349
+ display: "flex",
350
+ alignItems: "center",
351
+ justifyContent: isGradient ? "flex-start" : "space-between",
352
+ gap: "12px",
353
+ marginTop: "auto"
354
+ },
355
+ children: [badgeNode, dateNode].filter(Boolean)
356
+ }
357
+ },
358
+ previewOverlay,
359
+ previewLabel
360
+ ].filter(Boolean)
361
+ }
362
+ }
363
+ }
364
+
365
+ // ---------------------------------------------------------------------------
366
+ // Render helpers
367
+ // ---------------------------------------------------------------------------
368
+
369
+ /**
370
+ * Renders any takumi-js VNode to a PNG `Response` with standard OG headers. Use this when you
371
+ * supply your own layout entirely.
372
+ *
373
+ * @example
374
+ * const vnode = myBrandedLayout({ title, description })
375
+ * return renderOgResponse(vnode, { font: MY_FONT })
376
+ */
377
+ export async function renderOgResponse(
378
+ vnode: object,
379
+ config: OgRenderConfig = {}
380
+ ): Promise<Response> {
381
+ const { font = NOTO_SANS, width = 1200, height = 630 } = config
382
+
383
+ try {
384
+ const { render } = await import("takumi-js")
385
+ const { regular, bold } = await loadOgFonts(font)
386
+
387
+ const pngBuffer = await render(vnode, {
388
+ width,
389
+ height,
390
+ fonts: [
391
+ { name: font.name, data: regular, weight: 400, style: "normal" },
392
+ { name: font.name, data: bold, weight: 700, style: "normal" }
393
+ ]
394
+ })
395
+
396
+ return new Response(new Blob([new Uint8Array(pngBuffer)], { type: "image/png" }), {
397
+ status: 200,
398
+ headers: {
399
+ "Content-Type": "image/png",
400
+ "Cache-Control": "public, max-age=31536000, immutable",
401
+ "CDN-Cache-Control": "public, max-age=31536000"
402
+ }
403
+ })
404
+ } catch (error) {
405
+ console.error("[OG Render Error]:", error)
406
+ return new Response(
407
+ JSON.stringify({
408
+ error: "Failed to render Open Graph image",
409
+ message: error instanceof Error ? error.message : String(error)
410
+ }),
411
+ {
412
+ status: 500,
413
+ headers: {
414
+ "Content-Type": "application/json",
415
+ "Cache-Control": "no-store"
416
+ }
417
+ }
418
+ )
419
+ }
420
+ }
421
+
422
+ /**
423
+ * Renders the default OG layout to a PNG `Response`. The 90% case -- use `renderOgResponse()` for
424
+ * full layout control.
425
+ *
426
+ * @example
427
+ * export const GET: APIRoute = async ({ request }) => {
428
+ * const url = new URL(request.url)
429
+ * return renderDefaultOg({
430
+ * title: url.searchParams.get("title") ?? "Untitled",
431
+ * description: url.searchParams.get("description") ?? "",
432
+ * brand: "My Site",
433
+ * badge: url.searchParams.get("type") ?? ""
434
+ * })
435
+ * }
436
+ */
437
+ export async function renderDefaultOg(
438
+ options: OgLayoutOptions,
439
+ config: OgRenderConfig = {}
440
+ ): Promise<Response> {
441
+ const { font = NOTO_SANS } = config
442
+ const vnode = defaultOgLayout(options, font)
443
+ return renderOgResponse(vnode, config)
444
+ }
@@ -0,0 +1,77 @@
1
+ import type { APIRoute } from "astro"
2
+ import * as siteConfigMod from "virtual:rimelight-seo/site-config"
3
+ import * as dbMod from "virtual:rimelight-seo/db"
4
+ import * as corpusMod from "virtual:rimelight-seo/corpus"
5
+
6
+ export const prerender = false
7
+
8
+ export const GET: APIRoute = async ({ site, url }) => {
9
+ const siteConfig = siteConfigMod.siteConfig || {}
10
+ const siteUrl = site ? site.toString() : (siteConfig.url || `${url.protocol}//${url.host}`)
11
+ const title = siteConfig.name
12
+ ? `${siteConfig.name} Full Documentation Corpus`
13
+ : "Full Documentation Corpus"
14
+ const description = "Complete single-corpus documentation for AI agents and LLM ingest."
15
+
16
+ // 1. Try corpusPages if available
17
+ if (Array.isArray(corpusMod.corpusPages) && corpusMod.corpusPages.length > 0) {
18
+ const sections = new Map<string, string[]>()
19
+ for (const p of corpusMod.corpusPages) {
20
+ const key = (p.section || "GENERAL").toUpperCase()
21
+ if (!sections.has(key)) sections.set(key, [])
22
+ const slug = p.slug === "index" ? "" : p.slug
23
+ const pageUrl = `${siteUrl.replace(/\/$/, "")}/${slug}`.replace(/\/+$/, "")
24
+ sections.get(key)!.push(`### ${p.title}\nURL: ${pageUrl}\n${p.description || ""}`)
25
+ }
26
+
27
+ const body = [
28
+ `# ${title}`,
29
+ "",
30
+ description,
31
+ "",
32
+ ...Array.from(sections.entries()).flatMap(([section, pages]) => [
33
+ `## ${section}`,
34
+ "",
35
+ ...pages,
36
+ ""
37
+ ])
38
+ ].join("\n")
39
+
40
+ return new Response(body, {
41
+ headers: {
42
+ "Content-Type": "text/plain; charset=utf-8",
43
+ "Cache-Control": "public, max-age=3600, s-maxage=86400"
44
+ }
45
+ })
46
+ }
47
+
48
+ // 2. Try CMS renderCorpusMarkdown if db exists
49
+ if (dbMod.db) {
50
+ try {
51
+ const { renderCorpusMarkdown } = await import("@rimelight/cms")
52
+ const body = await renderCorpusMarkdown(dbMod.db, {
53
+ type: "doc",
54
+ locale: "en",
55
+ siteUrl,
56
+ title,
57
+ description
58
+ })
59
+
60
+ return new Response(body, {
61
+ headers: {
62
+ "Content-Type": "text/plain; charset=utf-8",
63
+ "Cache-Control": "public, max-age=3600, s-maxage=86400"
64
+ }
65
+ })
66
+ } catch {
67
+ // Fallback
68
+ }
69
+ }
70
+
71
+ return new Response(`# ${title}\n\n${description}\n`, {
72
+ headers: {
73
+ "Content-Type": "text/plain; charset=utf-8",
74
+ "Cache-Control": "public, max-age=3600, s-maxage=86400"
75
+ }
76
+ })
77
+ }
@@ -0,0 +1,90 @@
1
+ import type { APIRoute } from "astro"
2
+ import { buildLlmsTxt, type LlmsPage } from "../llms.js"
3
+ import * as siteConfigMod from "virtual:rimelight-seo/site-config"
4
+ import * as dbMod from "virtual:rimelight-seo/db"
5
+ import * as corpusMod from "virtual:rimelight-seo/corpus"
6
+ import seoOptions from "virtual:rimelight-seo/options"
7
+
8
+ export const prerender = false
9
+
10
+ export const GET: APIRoute = async ({ site, url }) => {
11
+ const siteConfig = siteConfigMod.siteConfig || {}
12
+ const siteUrl = site ? site.toString() : (siteConfig.url || `${url.protocol}//${url.host}`)
13
+ const llmsOpts = typeof seoOptions?.llms === "object" ? seoOptions.llms : {}
14
+
15
+ let pages: LlmsPage[] = []
16
+
17
+ if (Array.isArray(llmsOpts.pages) && llmsOpts.pages.length > 0) {
18
+ pages = llmsOpts.pages
19
+ } else if (Array.isArray(corpusMod.corpusPages) && corpusMod.corpusPages.length > 0) {
20
+ pages = corpusMod.corpusPages.map((p: any) => {
21
+ const slug = p.slug === "index" ? "" : p.slug
22
+ const pageUrl = `${siteUrl.replace(/\/$/, "")}/${slug}`.replace(/\/+$/, "")
23
+ return {
24
+ title: p.title,
25
+ description: p.description,
26
+ url: pageUrl,
27
+ section: p.section ? p.section.toUpperCase() : "GENERAL"
28
+ }
29
+ })
30
+ } else if (dbMod.db) {
31
+ try {
32
+ const { pages: pagesTable } = await import("#db/schema").catch(() => ({ pages: null }))
33
+ const { and, isNotNull, isNull } = await import("drizzle-orm")
34
+ if (pagesTable) {
35
+ const docRows = await dbMod.db
36
+ .select()
37
+ .from(pagesTable)
38
+ .where(and(isNull(pagesTable.deletedAt), isNotNull(pagesTable.publishedVersionId)))
39
+ .catch(() => [])
40
+
41
+ const resolveLocalized = (val: unknown): string => {
42
+ if (typeof val === "string") return val
43
+ if (typeof val === "object" && val !== null) {
44
+ const rec = val as Record<string, string>
45
+ return rec["en"] || Object.values(rec)[0] || ""
46
+ }
47
+ return typeof val === "number" ? String(val) : ""
48
+ }
49
+
50
+ pages = docRows.map((p: any) => {
51
+ const title = resolveLocalized(p.title) || p.slug
52
+ const description = resolveLocalized(p.description)
53
+ const slug = p.slug === "index" ? "" : p.slug
54
+ const pathPrefix = p.type === "doc" ? "docs" : p.type || "docs"
55
+ const pageUrl = `${siteUrl.replace(/\/$/, "")}/en/${pathPrefix}/${slug}`.replace(/\/+$/, "")
56
+ const markdownUrl = `${pageUrl}.md`
57
+
58
+ return {
59
+ title,
60
+ description,
61
+ url: pageUrl,
62
+ markdownUrl,
63
+ section: p.type ? p.type.toUpperCase() : "GENERAL"
64
+ }
65
+ })
66
+ }
67
+ } catch {
68
+ // Fallback
69
+ }
70
+ }
71
+
72
+ const title = llmsOpts.title || siteConfig.name || "Documentation"
73
+ const description =
74
+ llmsOpts.description || siteConfig.description || "Documentation index for AI agents."
75
+
76
+ const body = buildLlmsTxt({
77
+ site: siteUrl,
78
+ title,
79
+ description,
80
+ pages,
81
+ ...llmsOpts
82
+ })
83
+
84
+ return new Response(body, {
85
+ headers: {
86
+ "Content-Type": "text/plain; charset=utf-8",
87
+ "Cache-Control": "public, max-age=3600, s-maxage=86400"
88
+ }
89
+ })
90
+ }
@@ -0,0 +1,63 @@
1
+ import type { APIRoute } from "astro"
2
+ import { buildRobotsTxt } from "../robots.js"
3
+ import * as seoConfig from "virtual:rimelight-seo/config"
4
+ import * as siteConfigMod from "virtual:rimelight-seo/site-config"
5
+ import seoOptions from "virtual:rimelight-seo/options"
6
+
7
+ export const GET: APIRoute = ({ site, url }) => {
8
+ const siteUrl = site ? site.toString() : (siteConfigMod.siteConfig?.url || url.origin)
9
+ const sitemapURL = new URL("sitemap.xml", siteUrl).toString()
10
+
11
+ const defaultPrivatePrefixes = [
12
+ "/dashboard",
13
+ "/admin",
14
+ "/cms",
15
+ "/internal",
16
+ "/api",
17
+ "/dev",
18
+ "/og",
19
+ "/open-graph",
20
+ "/auth"
21
+ ]
22
+
23
+ const customPrivatePrefixes = Array.isArray(seoConfig.PRIVATE_PATH_PREFIXES)
24
+ ? seoConfig.PRIVATE_PATH_PREFIXES
25
+ : []
26
+
27
+ const privatePrefixes = Array.from(new Set([...defaultPrivatePrefixes, ...customPrivatePrefixes]))
28
+
29
+ const disallowPatterns = [
30
+ ...privatePrefixes,
31
+ ...privatePrefixes.map((p) => `/*${p.startsWith("/") ? p : `/${p}`}/`)
32
+ ]
33
+
34
+ const robotsOpts = typeof seoOptions?.robots === "object" ? seoOptions.robots : {}
35
+
36
+ const defaultAgentRules = [
37
+ {
38
+ userAgent: "GPTBot",
39
+ disallow: privatePrefixes.map((p) => `${p.startsWith("/") ? p : `/${p}`}/`),
40
+ allow: ["/"]
41
+ },
42
+ {
43
+ userAgent: "ClaudeBot",
44
+ disallow: privatePrefixes.map((p) => `${p.startsWith("/") ? p : `/${p}`}/`),
45
+ allow: ["/"]
46
+ }
47
+ ]
48
+
49
+ const robots = buildRobotsTxt({
50
+ sitemapUrl: sitemapURL,
51
+ disallow: disallowPatterns,
52
+ allow: ["/"],
53
+ userAgentRules: defaultAgentRules,
54
+ ...robotsOpts
55
+ })
56
+
57
+ return new Response(robots, {
58
+ headers: {
59
+ "Content-Type": "text/plain; charset=utf-8",
60
+ "Cache-Control": "public, max-age=3600, stale-while-revalidate=86400"
61
+ }
62
+ })
63
+ }