forked from tanhauhau/svelte-json-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvelte.config.js
57 lines (51 loc) · 1.32 KB
/
svelte.config.js
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 preprocess from 'svelte-preprocess';
import adapter from '@sveltejs/adapter-static';
import { mdsvex } from 'mdsvex';
import mm from 'micromatch';
import { readFileSync } from 'fs';
import shiki from 'shiki';
const dev = process.env.NODE_ENV === 'development';
let highlighter;
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: [
preprocess(),
mdsvex({
extensions: ['.md'],
highlight: {
highlighter: async (code, lang) => {
if (!highlighter) {
highlighter = await shiki.getHighlighter({
theme: 'dracula-soft',
});
}
return escape_svelty(highlighter.codeToHtml(code, { lang }));
},
},
}),
],
kit: {
paths: {
assets: 'https://lihautan.com/svelte-json-tree',
base: dev ? '' : '/svelte-json-tree',
},
adapter: adapter({
pages: 'docs',
assets: 'docs',
fallback: null,
}),
package: {
files: mm.matcher('!doc-components/**/*'),
},
prerender: {
default: true,
entries: ['*'],
crawl: false,
},
},
extensions: ['.svelte', '.md'],
};
export default config;
function escape_svelty(str) {
return str.replace(/[{}`]/g, (c) => ({ '{': '{', '}': '}', '`': '`' }[c])).replace(/\\([trn])/g, '\$1');
}