Repository navigation
Expand file tree
/
Copy pathsvelte.config.js
More file actions
67 lines (56 loc) · 2.03 KB
/
Copy pathsvelte.config.js
File metadata and controls
67 lines (56 loc) · 2.03 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
66
67
import adapter from "@sveltejs/adapter-static";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
import { mdsvex } from "mdsvex";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import rehypeSlug from "rehype-slug";
function get_headings() {
let visit;
let tree_to_string;
let GithubSlugger;
return async function transformer(tree, vFile) {
if (!visit || !GithubSlugger) {
tree_to_string = (await import("mdast-util-to-string")).toString;
visit = (await import("unist-util-visit")).visit;
GithubSlugger = (await import("github-slugger")).default;
}
const slugger = new GithubSlugger();
const headings = [];
const fileName = vFile.filename.split(/[\\\/]/).pop();
if (fileName !== "+page.svx") return;
visit(tree, "heading", (node) => {
const title = tree_to_string(node);
headings.push({
level: node.depth,
title,
slug: slugger.slug(title),
});
});
if (!vFile.data.fm) vFile.data.fm = {};
vFile.data.fm.headings = headings;
};
}
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Ensures both .svelte and .md files are treated as components (can be imported and used anywhere, or used as pages)
extensions: [".svelte", ".svx"],
// Consult https://svelte.dev/docs/kit/integrations
// for more information about preprocessors
preprocess: [
vitePreprocess(),
mdsvex({
// Adds IDs to headings, and anchor links to those IDs. Note: must stay in this order to work.
rehypePlugins: [
rehypeSlug,
[rehypeAutolinkHeadings, { behavior: "wrap" }],
],
remarkPlugins: [get_headings],
}),
],
kit: {
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
adapter: adapter(),
},
};
export default config;