-
Notifications
You must be signed in to change notification settings - Fork 0
/
svelte.config.js
68 lines (57 loc) · 1.66 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
58
59
60
61
62
63
64
65
66
67
68
import adapter from '@sveltejs/adapter-cloudflare';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import { mdsvex } from 'mdsvex'; // Markdown preprocessor for svelte
import examples from 'mdsvexamples'; // Remark plugin: renders svelte code blocks in MDSveX
/* Remark plugin function: parses the markdown AST and extract
* the headings from it, to create TOC. */
function getHeading() {
let visit;
let tree_to_string;
return async function transformer(tree, vFile) {
if (!visit) {
tree_to_string = (await import('mdast-util-to-string')).toString;
visit = (await import('unist-util-visit')).visit;
}
vFile.data.headings = [];
function getSlug(title) {
return title
.toLowerCase()
.replace(/ /g, '-')
.replace(/[^\w-]+/g, '');
}
visit(tree, 'heading', (node) => {
vFile.data.headings.push({
level: node.depth,
title: tree_to_string(node),
slug: getSlug(tree_to_string(node))
});
});
if (!vFile.data.fm) vFile.data.fm = {};
vFile.data.fm.headings = vFile.data.headings;
};
}
/** @type {import('mdsvex').MdsvexCompileOptions}. */
const mdsvexOptions = {
extensions: ['.svelte.md', '.md', '.svx'],
smartypants: true,
layout: '/src/lib/customComponent/componentLayout.svelte',
remarkPlugins: [
getHeading,
[examples, { defaults: { Wrapper: '/src/lib/components/ExampleWrapper.svelte' } }]
],
rehypePlugins: []
};
/** @type {import('@sveltejs/kit').Config} */
const config = {
extensions: ['.svelte', ...mdsvexOptions.extensions],
preprocess: [vitePreprocess(), mdsvex(mdsvexOptions)],
vitePlugin: {
inspector: {
holdMode: true
}
},
kit: {
adapter: adapter()
}
};
export default config;