-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsvelte.config.js
More file actions
65 lines (59 loc) · 1.89 KB
/
svelte.config.js
File metadata and controls
65 lines (59 loc) · 1.89 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
import openworkersAdapter from '@openworkers/adapter-sveltekit';
import adapter from '@sveltejs/adapter-static';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import { mdsvex } from 'mdsvex';
import { createHighlighter } from 'shiki';
import rehypeSlug from 'rehype-slug';
const highlighter = await createHighlighter({
themes: ['github-light'],
langs: ['javascript', 'typescript', 'bash', 'json', 'html', 'css', 'svelte', 'rust', 'sql', 'yaml', 'toml']
});
// Toggle between Openworkers adapter and static adapter
// with arg --openworkers
const useOpenworkersAdapter = process.argv.includes('--openworkers');
console.log(`Using ${useOpenworkersAdapter ? 'Openworkers Sveltekit' : 'Sveltekit Static'} adapter`);
/** @type {import('@sveltejs/kit').Config} */
const config = {
extensions: ['.svelte', '.md'],
preprocess: [
vitePreprocess(),
mdsvex({
extensions: ['.md'],
rehypePlugins: [rehypeSlug],
highlight: {
highlighter: (code, lang) => {
let html = highlighter.codeToHtml(code, {
lang: lang || 'text',
theme: 'github-light'
});
// Replace white background with slate-50 (#f8fafc)
html = html.replace(/background-color:#fff/g, 'background-color:#f8fafc');
// Escape backticks and ${} to prevent Svelte template interpretation
const escaped = html.replace(/`/g, '\\`').replace(/\$\{/g, '\\${');
return `{@html \`${escaped}\`}`;
}
}
})
],
kit: {
adapter: useOpenworkersAdapter
? openworkersAdapter({
out: 'dist',
functions: true
})
: adapter({
pages: 'build',
assets: 'build',
fallback: '404.html',
precompress: false,
strict: true
}),
paths: {
base: ''
},
prerender: {
handleHttpError: 'warn'
}
}
};
export default config;