-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathastro.config.ts
More file actions
179 lines (163 loc) · 4.84 KB
/
Copy pathastro.config.ts
File metadata and controls
179 lines (163 loc) · 4.84 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
import type { IncomingMessage, ServerResponse } from 'node:http';
import type { ViteDevServer } from 'vite';
import { satteri } from '@astrojs/markdown-satteri';
import mdx from '@astrojs/mdx';
import sitemap from '@astrojs/sitemap';
import starlight from '@astrojs/starlight';
import { defineConfig, fontProviders } from 'astro/config';
import { existsSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import {
getSidebarCrateLinks,
getSidebarFacadeLinks,
rustuseCrates,
} from './src/data/catalog.js';
import { renderKatexMath } from './src/markdown/render-katex-math.mjs';
const workspaceRoot = fileURLToPath(new URL('.', import.meta.url));
const publicRoot = path.join(workspaceRoot, 'public');
type MiddlewareNext = (err?: unknown) => void;
const handleRustdocDirectoryIndex = (
req: IncomingMessage,
_res: ServerResponse,
next: MiddlewareNext,
): void => {
if (!req.url) {
return next();
}
const requestUrl = new URL(req.url, 'http://localhost');
const { pathname, search } = requestUrl;
if (!pathname.startsWith('/api/') || !pathname.endsWith('/')) {
return next();
}
const candidate = path.join(
publicRoot,
...pathname.split('/').filter(Boolean),
'index.html',
);
if (!existsSync(candidate)) {
return next();
}
req.url = `${pathname}index.html${search}`;
return next();
};
const rustdocDirectoryIndexPlugin = {
name: 'rustuse-rustdoc-directory-index',
configureServer(server: ViteDevServer): void {
server.middlewares.use(handleRustdocDirectoryIndex);
},
};
function getCrateSlugRedirects(): Record<string, string> {
const redirects: Record<string, string> = {};
for (const crate of rustuseCrates) {
if (
!crate.name.startsWith('use-') ||
crate.name === crate.facade ||
typeof crate.pagePath !== 'string' ||
crate.pagePath.length === 0
) {
continue;
}
const from = `/${crate.name}`;
const fromWithSlash = `${from}/`;
if (redirects[from] && redirects[from] !== crate.pagePath) {
throw new Error(
`Duplicate RustUse crate redirect for ${from}: ${redirects[from]} and ${crate.pagePath}`,
);
}
redirects[from] = crate.pagePath;
redirects[fromWithSlash] = crate.pagePath;
}
return redirects;
}
export default defineConfig({
site: 'https://rustuse.org/',
redirects: getCrateSlugRedirects(),
vite: {
plugins: [rustdocDirectoryIndexPlugin],
},
fonts: [
{
provider: fontProviders.fontsource(),
name: 'Alfa Slab One',
cssVariable: '--font-alfa-slab-one',
weights: [400],
styles: ['normal'],
},
{
provider: fontProviders.fontsource(),
name: 'Fira Sans',
cssVariable: '--font-fira-sans',
weights: [400, 500, 600, 700],
styles: ['normal', 'italic'],
},
],
markdown: {
processor: satteri({
features: {
gfm: true,
frontmatter: true,
directive: true,
math: true,
},
mdastPlugins: [renderKatexMath],
}),
},
integrations: [
starlight({
title: 'RustUse',
titleDelimiter: '|',
description:
'RustUse provides composable facades of primitive Rust utility crates.',
favicon: '/favicon.ico',
disable404Route: true,
customCss: ['./src/styles/katex.css', './src/styles/rustuse.css'],
components: {
Head: './src/components/Head.astro',
Hero: './src/components/Hero.astro',
Header: './src/components/Header.astro',
Footer: './src/components/Footer.astro',
SocialIcons: './src/components/SocialIcons.astro',
ThemeProvider: './src/components/ThemeProvider.astro',
ThemeSelect: './src/components/ThemeSelect.astro',
},
social: [
{ icon: 'github', label: 'GitHub', href: 'https://github.com/rustuse' },
],
sidebar: [
{ label: 'Onboarding', link: '/onboarding' },
{
label: 'Facades',
collapsed: true,
items: [
{ label: 'Overview', link: '/facades' },
...getSidebarFacadeLinks(),
],
},
{
label: 'Crates',
collapsed: true,
items: [
{ label: 'Overview', link: '/crates' },
...getSidebarCrateLinks(),
],
},
{ label: 'CLI', link: '/cli' },
{
label: 'Using AI',
collapsed: true,
items: [
{ label: 'Overview', link: '/using-ai' },
{ label: 'LLM text files', link: '/using-ai/llms-txt' },
{ label: 'RustUse MCP Server', link: '/using-ai/mcp' },
{ label: 'AI usage recipes', link: '/using-ai/recipes' },
{ label: 'Reference', link: '/using-ai/reference' },
],
},
{ label: 'Contributing', link: '/contributing' },
],
}),
mdx(),
sitemap(),
],
});