-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvelte.config.ts
More file actions
57 lines (52 loc) · 1.62 KB
/
svelte.config.ts
File metadata and controls
57 lines (52 loc) · 1.62 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
import { type Config } from '@sveltejs/kit'
import adapter from '@sveltejs/adapter-auto'
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
import { markdocPreprocess } from 'markdoc-svelte'
import { glob } from 'node:fs/promises'
import { isKeystaticRoute } from './src/lib/index.js'
import { sep, posix } from 'node:path'
export async function getPrerenderEntries() {
const posts = (await Array.fromAsync(glob('src/content/posts/**/*.{mdoc,md}'))).flatMap(
(file: string) =>
file
// Ensure paths are posix `/` rather than Windows `\`
.replaceAll(sep, posix.sep)
// We only need the final part of the file path
.split('/content')[1]
// Replace the file extension to get a clean file URL
.replace(/\.md(?:oc)/, ''),
)
// Add loaders for more prerenderable content types here
return [posts].flat()
}
const config = {
extensions: ['.svelte', '.mdoc', '.md'],
preprocess: [
vitePreprocess(),
markdocPreprocess({
components: '$components/markdoc',
tags: {
Counter: {
render: 'Counter',
selfClosing: true,
},
},
}),
],
kit: {
adapter: adapter(),
prerender: {
entries: ['*', await getPrerenderEntries()].flat(),
handleHttpError({ path, message }) {
// Ignore prerendering errors for Keystatic CMS since it's a SPA that only supports CSR.
if (isKeystaticRoute(path)) return
// Fail the build in other cases.
throw new Error(message)
},
},
alias: {
'$components/*': './src/components/*',
},
},
} satisfies Config
export default config