-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathastro.config.mjs
More file actions
59 lines (57 loc) · 1.84 KB
/
Copy pathastro.config.mjs
File metadata and controls
59 lines (57 loc) · 1.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
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';
import tailwind from '@astrojs/tailwind';
import sitemap from '@astrojs/sitemap';
import { execSync } from 'child_process';
/** Return the last git-commit ISO timestamp for a source file, or build time as fallback. */
function getGitLastmod(filePath) {
try {
const ts = execSync(`git log --format="%aI" -1 -- "${filePath}"`, {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'ignore'],
}).trim();
return ts || new Date().toISOString();
} catch {
return new Date().toISOString();
}
}
export default defineConfig({
site: 'https://docs.stackbilder.com',
output: 'static',
integrations: [
mdx(),
tailwind(),
sitemap({
// Split into named chunks by content type — docs-0.xml, with room for future types
chunks: {
docs: (item) => {
const pathname = new URL(item.url).pathname;
// Exclude schema endpoints and raw file routes from the main sitemap
if (pathname.startsWith('/schema/') || pathname.endsWith('.md') || pathname.endsWith('.json')) {
return undefined;
}
return item;
},
},
// Map git-commit timestamps to <lastmod>
serialize(item) {
const pathname = new URL(item.url).pathname;
// Derive the source file slug from the URL path (strip leading/trailing slashes)
const slug = pathname.replace(/^\/|\/$/g, '');
const filePath = slug ? `src/content/docs/${slug}.md` : null;
const lastmod = filePath ? getGitLastmod(filePath) : new Date().toISOString();
return {
...item,
lastmod,
changefreq: slug ? 'weekly' : 'daily',
priority: slug ? 0.8 : 1.0,
};
},
}),
],
markdown: {
shikiConfig: {
theme: 'github-dark-default',
},
},
});