-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathastro.config.ts
More file actions
158 lines (150 loc) · 5.87 KB
/
astro.config.ts
File metadata and controls
158 lines (150 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { config } from "dotenv"
import { defineConfig } from "astro/config"
import vercel from "@astrojs/vercel"
import preact from "@astrojs/preact"
import react from "@astrojs/react"
import mdx from "@astrojs/mdx"
import rehypeSlug from "rehype-slug"
import rehypeAutolinkHeadings from "rehype-autolink-headings"
import rehypeWrapAll from "rehype-wrap-all"
import sitemap from "@astrojs/sitemap"
import { RehypePlugins } from "@astrojs/markdown-remark"
import yaml from "@rollup/plugin-yaml"
import { ccipRedirects } from "./src/config/redirects/ccip"
import trailingSlashMiddleware from "./src/integrations/trailing-slash-middleware"
import redirectsJson from "./src/features/redirects/redirects.json"
import { extractCanonicalUrlsWithLanguageVariants } from "./src/utils/sidebar"
import remarkCodeFenceFilename from "./src/lib/markdown/remarkCodeFenceFilename"
import rehypeCodeSampleFences from "./src/lib/markdown/rehypeCodeSampleFences"
config() // Load .env file
// Prepare set of redirect source URLs to exclude from sitemap
// This prevents duplicate entries and ensures only canonical URLs are indexed
const redirectSources = new Set(
redirectsJson.redirects
.map((r) => r.source)
.filter((source) => source)
.map((source) => {
const normalized = source.startsWith("/") ? source : `/${source}`
return normalized.endsWith("/") ? normalized.slice(0, -1) : normalized
})
)
// Extract canonical URLs that have language-specific variants from sidebar config
// These redirect pages should NOT be in the sitemap
// Only the actual content pages (-go, -ts) are indexed
const canonicalUrlsWithLanguageVariants = extractCanonicalUrlsWithLanguageVariants()
// https://astro.build/config
export default defineConfig({
site: "https://docs.chain.link",
trailingSlash: "never",
redirects: {
"/ccip/directory": "/ccip/directory/mainnet",
"/ccip/supported-networks": "/ccip/directory/mainnet",
"/getting-started": "/getting-started/conceptual-overview",
"/resources": "/resources/link-token-contracts",
...ccipRedirects,
},
integrations: [
trailingSlashMiddleware(),
preact({
include: ["**/preact/*"],
}),
react({
include: ["**/react/*"],
}),
sitemap({
changefreq: "daily",
customPages: [
"https://docs.chain.link/llms.txt",
"https://docs.chain.link/cre/llms-full-go.txt",
"https://docs.chain.link/cre/llms-full-ts.txt",
"https://docs.chain.link/vrf/llms-full.txt",
"https://docs.chain.link/ccip/llms-full.txt",
"https://docs.chain.link/data-feeds/llms-full.txt",
"https://docs.chain.link/data-streams/llms-full.txt",
"https://docs.chain.link/dta-technical-standard/llms-full.txt",
"https://docs.chain.link/datalink/llms-full.txt",
"https://docs.chain.link/chainlink-functions/llms-full.txt",
"https://docs.chain.link/chainlink-automation/llms-full.txt",
"https://docs.chain.link/resources/llms-full.txt",
"https://docs.chain.link/architecture-overview/llms-full.txt",
"https://docs.chain.link/getting-started/llms-full.txt",
"https://docs.chain.link/chainlink-nodes/llms-full.txt",
"https://docs.chain.link/chainlink-local/llms-full.txt",
],
filter: (page) => {
// Exclude redirect source URLs from sitemap to prevent duplicates
const pathname = new URL(page).pathname
const cleanPath = pathname.endsWith("/") && pathname !== "/" ? pathname.slice(0, -1) : pathname
// Exclude short format API reference URLs (e.g., /api-reference/v150, /ccip/api-reference/evm/v150)
// These are aliases for versioned content - we keep only the canonical long format URLs
const shortVersionPattern = /\/api-reference\/(?:.*\/)?v\d{3,4}(?:\/|$)/
if (shortVersionPattern.test(cleanPath)) {
return false
}
// Exclude canonical URLs that have language-specific variants (from sidebar config)
if (canonicalUrlsWithLanguageVariants.has(cleanPath)) {
return false
}
return !redirectSources.has(cleanPath)
},
serialize(item) {
// Remove trailing slash from URLs (except for root)
const url = new URL(item.url)
if (url.pathname.endsWith("/") && url.pathname !== "/") {
url.pathname = url.pathname.slice(0, -1)
item.url = url.toString()
}
return item
},
}),
// Ensure our fence-meta parser runs for `.mdx` pages (in addition to `markdown.remarkPlugins`).
mdx({
remarkPlugins: [remarkCodeFenceFilename],
}),
],
markdown: {
remarkPlugins: [remarkCodeFenceFilename],
rehypePlugins: [
rehypeSlug, // Required for autolink to work properly
[
rehypeAutolinkHeadings,
{
behavior: "wrap",
},
],
// Wrap tables in div with overflow supported
[rehypeWrapAll, { selector: "table", wrapper: "div.overflow-wrapper" }],
rehypeCodeSampleFences,
] as RehypePlugins,
syntaxHighlight: "prism",
smartypants: false,
},
// output: 'static' (fully static or partial SSR with `prerender = false` ==> export const prerender = false;)
output: "static",
adapter: vercel(),
vite: {
plugins: [yaml()],
build: {
target: "esnext", // Use latest ES features, no transpilation for modern browsers
// Optimize CSS delivery
cssMinify: true,
// Increase the threshold for inlining assets to reduce render-blocking CSS
assetsInlineLimit: 20000, // Inline CSS files up to 20KB to eliminate render-blocking
// Removed manual chunking to prevent serverless function bloat
// rollupOptions: {
// output: {
// manualChunks: ...
// }
// },
},
esbuild: {
target: "esnext", // Match build target for consistency
},
css: {
devSourcemap: false,
},
},
legacy: {
collections: false,
},
})