-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathastro.config.mjs
More file actions
364 lines (350 loc) · 12.4 KB
/
Copy pathastro.config.mjs
File metadata and controls
364 lines (350 loc) · 12.4 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
// @ts-check
import { defineConfig, sharpImageService } from 'astro/config'
import starlight from '@astrojs/starlight'
import react from '@astrojs/react'
import path from 'path'
import vue from '@astrojs/vue'
import starlightSidebarTopics from 'starlight-sidebar-topics'
import starlightImageZoom from 'starlight-image-zoom'
import { pluginCollapsibleSections } from '@expressive-code/plugin-collapsible-sections'
import starlightDocSearch from '@astrojs/starlight-docsearch'
import starlightPageActions from 'starlight-page-actions'
import starlightThemeNova from 'starlight-theme-nova'
import starlightVideos from 'starlight-videos'
import starlightCopyInlineCode from 'starlight-copy-inline-code'
import starlightLinksValidator from 'starlight-links-validator'
import starlightLlmsTxt from 'starlight-llms-txt'
import starlightBlog from 'starlight-blog'
import { sidebar as sidebarConfig, topics, exclude } from './src/configs/sidebar.config'
import { redirects } from './src/configs/redirects.config'
import { llmsConfig } from './src/configs/llms.config.ts'
import { pageActionsPrompt } from './src/configs/page-actions.config.ts'
import tailwindcss from '@tailwindcss/vite'
import d2 from 'astro-d2' // https://astro-d2.vercel.app/configuration/
import Icons from 'unplugin-icons/vite'
import netlify from '@astrojs/netlify'
import openapiToMarkdown from './src/integrations/openapi-markdown'
// https://astro.build/config
export default defineConfig({
// Switched from 'server' to default (static) to drastically reduce build memory.
// Astro 6's Vite Environments API creates separate build contexts per output mode;
// 'server' mode processes all 300+ pages through a heavy SSR pipeline.
// The few SSR pages (auth, health, admin) already have `prerender = false`.
// output: 'server',
site: 'https://docs.scalekit.com',
server: {
// Match Netlify dev's readiness probe, which connects to `localhost`.
host: 'localhost',
port: 4321,
},
redirects,
integrations: [
starlight({
title: 'Scalekit Docs',
pagefind: false,
routeMiddleware: './src/routeData.ts',
lastUpdated: true,
tableOfContents: {
minHeadingLevel: 2,
maxHeadingLevel: 4,
},
favicon: '/images/favicon.png',
components: {
// SocialIcons: './src/components/overrides/SocialIcons.astro',
// Sidebar: './src/components/overrides/Sidebar.astro',
Head: './src/components/overrides/Head.astro',
Header: './src/components/overrides/Header.astro',
Footer: './src/components/overrides/Footer.astro',
PageSidebar: './src/components/overrides/PageSidebar.astro',
PageTitle: './src/components/overrides/PageTitle.astro',
MarkdownContent: './src/components/overrides/MarkdownContent.astro',
Banner: './src/components/overrides/Banner.astro',
},
logo: {
dark: '/src/assets/images/scalekit-logo-white.svg',
light: '/src/assets/images/logos-v4/sk-docs-light.svg',
replacesTitle: true,
},
defaultLocale: 'en',
editLink: {
baseUrl: 'https://github.com/scalekit-inc/developer-docs/edit/main',
},
expressiveCode: {
useStarlightDarkModeSwitch: true,
// themes: ['vitesse-dark', 'vitesse-light'],
themes: ['tokyo-night', 'light-plus'],
styleOverrides: {
codeFontFamily:
"'JetBrains Mono', 'Inter Variable', ui-monospace, 'Courier New', monospace",
borderRadius: '0.375rem',
},
},
customCss: [
'@fontsource-variable/inter',
'@fontsource-variable/atkinson-hyperlegible-next',
'@fontsource/jetbrains-mono',
'./src/styles/theme-priority.css',
],
plugins: [
starlightThemeNova({ stylingSystem: 'tailwind' }),
starlightImageZoom({
showCaptions: true,
}),
starlightSidebarTopics(sidebarConfig, { topics, exclude }),
starlightDocSearch({
appId: '7554BDRAJD',
apiKey: 'b2fecf525a556f05d46ef2389ad7e4b6',
indexName: 'scalekit-starlight-crawler',
askAi: '8jKZkVuXS0hG',
}),
starlightVideos(),
// Links validator disabled in CI to reduce build memory usage.
// Run locally with: pnpm astro build (without NETLIFY env var)
...(!process.env.NETLIFY
? [
starlightLinksValidator({
exclude: ['/apis/**'],
}),
]
: []),
starlightLlmsTxt(llmsConfig),
starlightPageActions({
prompt: pageActionsPrompt,
actions: {
markdown: true,
chatgpt: false,
claude: true,
custom: {
cursor: {
label: 'Open in Cursor',
href: 'https://cursor.com/link/prompt?text=',
},
},
},
// No baseUrl — prevents llms.txt generation (already handled by starlight-llms-txt)
}),
// Provide copy-to-clipboard button for inline code snippets site-wide for better UX
starlightCopyInlineCode({
// Show copy button only on hover (default: true)
showOnHover: false,
// Tooltip text for copy button (default: 'Copy')
copyLabel: 'Copy',
// Tooltip text after successful copy (default: 'Copied!')
copiedLabel: 'Copied!',
// CSS selector for inline code elements (default: ':not(pre) > code')
selector: ':not(pre) > code',
}),
starlightBlog({
prefix: 'cookbooks',
rss: false,
metrics: {
readingTime: true,
words: 'total',
},
}),
],
head: [
{
tag: 'link',
attrs: {
rel: 'alternate',
type: 'text/plain',
title: 'LLM-friendly documentation',
href: '/llms.txt',
},
},
{
tag: 'script',
attrs: {
async: true,
src: 'https://www.googletagmanager.com/gtag/js?id=G-F4K36V5HPL',
},
},
{
tag: 'script',
content: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-F4K36V5HPL');
`,
},
{
tag: 'script',
attrs: {
src: '/js/posthog.js',
},
},
{
// NOTE: Inlined from /public/js/iframe-detection.js for early execution
// If you need to modify this script, edit /public/js/iframe-detection.js and copy the content here
tag: 'script',
content: `
;(function () {
function inIframe() {
try {
return window.self !== window.top
} catch (e) {
return true
}
}
if (inIframe()) {
// Force light mode immediately (before DOM loads)
document.documentElement.setAttribute('data-theme', 'light')
document.documentElement.classList.add('in-iframe')
document.documentElement.style.colorScheme = 'light'
// Override localStorage to prevent theme changes
localStorage.setItem('theme-toggle', 'light')
localStorage.setItem('colorMode', 'light')
// Remove zoom functionality after DOM loads
document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('starlight-image-zoom-zoomable').forEach(function (el) {
var img = el.querySelector('img')
var btn = el.querySelector('button')
if (btn) btn.remove()
if (img) {
var newImg = img.cloneNode(true)
el.parentNode.replaceChild(newImg, el)
}
})
// Observer for dynamically loaded images
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
mutation.addedNodes.forEach(function (node) {
if (node.nodeType === 1) {
var zoomables = node.querySelectorAll('starlight-image-zoom-zoomable')
zoomables.forEach(function (el) {
var img = el.querySelector('img')
var btn = el.querySelector('button')
if (btn) btn.remove()
if (img) {
var newImg = img.cloneNode(true)
el.parentNode.replaceChild(newImg, el)
}
})
}
})
})
})
observer.observe(document.body, {
childList: true,
subtree: true,
})
})
}
})()
`,
},
{
tag: 'script',
attrs: {
src: '/js/force-light-theme.js',
},
},
{
tag: 'script',
attrs: {
src: '/js/sidebar-scroll.js',
},
},
// Pylon widget configuration (must run in head before widget loads)
{
tag: 'script',
attrs: {
src: '/js/pylon-widget.js',
},
},
// Prevent HubSpot from auto-showing chat; we load it explicitly for anonymous users
{
tag: 'script',
content: `window.hsConversationsSettings = { loadImmediately: false };`,
},
{
tag: 'script',
content: `
;(function () {
function inIframe() {
try {
return window.self !== window.top
} catch (e) {
return true
}
}
if (inIframe()) return
var script = document.createElement('script')
script.type = 'text/javascript'
script.id = 'hs-script-loader'
script.async = true
script.defer = true
script.src = '//js-na2.hs-scripts.com/44204598.js'
document.head.appendChild(script)
})()
`,
},
],
}),
react(),
vue({
jsx: true,
template: {
compilerOptions: {
isCustomElement: (tag) => tag.includes('-'),
},
},
}),
d2({
skipGeneration: !!process.env['NETLIFY'] || !!process.env['GITHUB_ACTIONS'],
theme: {
default: '1', // Light theme (Neutral default)
dark: '1',
},
sketch: true, // Clean, professional diagrams instead of hand-drawn
appendix: true, // Enable interactive elements (tooltips/links)
inline: true, // Embed SVG inline to make links clickable
layout: 'elk', // ELK layout engine for better positioning
pad: 5,
}),
openapiToMarkdown(),
],
image: {
service: sharpImageService(),
},
vite: {
resolve: {
alias: {
'@': path.resolve('./src'),
'@components': path.resolve('./src/components'),
},
},
optimizeDeps: {
include: ['vue'],
exclude: [],
},
// Provide a safe fallback for libraries that reference the CommonJS
// global `__dirname` (e.g. canvaskit-wasm used by astro-og-canvas).
// When bundling for ESM, Node doesn’t define this variable which causes
// a runtime ReferenceError during `astro build`. Re-defining it at build
// time prevents the error without affecting runtime logic.
define: {
__dirname: '"/"',
},
plugins: [pluginCollapsibleSections(), tailwindcss(), Icons({ compiler: 'astro' })],
build: {
chunkSizeWarningLimit: 2000,
// Disable source maps in CI to reduce peak memory during bundling
sourcemap: false,
// Disable gzip size reporting to save memory on large builds
reportCompressedSize: false,
rollupOptions: {
// Limit parallel file I/O to reduce memory spikes during bundling
maxParallelFileOps: 2,
output: {
manualChunks(id) {
if (id.includes('@scalar')) return 'scalar'
},
},
},
},
},
adapter: netlify({ imageCDN: !!process.env.NETLIFY }),
})