-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvelte.config.js
105 lines (97 loc) · 2.91 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import adapter from "@sveltejs/adapter-static";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
import { mdsvex, escapeSvelte } from "mdsvex";
import { getHighlighter } from "shiki";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import rehypeKatexSvelte from "rehype-katex-svelte";
import rehypeSlug from "rehype-slug";
import wikiLinkPlugin from "remark-wiki-link";
import remarkMath from "remark-math";
import remarkToc from "remark-toc";
const tocOptions = {
skip: "references",
};
const pageResolver = (name) => {
const fixed = name
.replace(/&(#(?:x[0-9a-f]+|\d+)|[a-z]+);?/gi, "") // Remove HTML character entities
.replace(/[^a-zA-Z0-9 ]/g, "") // Remove non alpha numeric character
.replace(/ +(?= )/g, "") // Remove multiple spaces
.replace(/ /g, "-") // Replace single space with dash
.toLowerCase();
return [fixed];
};
const hrefTemplate = (permalink) => `/blog/post/${permalink}`;
const wikiLinkOptions = {
pageResolver,
hrefTemplate,
};
/** @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", ".md"],
preprocess: [
mdsvex({
// The default mdsvex extension is .svx; this overrides that.
extensions: [".md"],
highlight: {
highlighter: async (code, lang = "text") => {
const highlighter = await getHighlighter({
themes: ["github-dark"],
langs: [
"css",
"bash",
"python",
"javascript",
"matlab",
"svelte",
"typescript",
],
});
await highlighter.loadLanguage(
"css",
"bash",
"python",
"javascript",
"matlab",
"svelte",
"typescript",
);
const html = escapeSvelte(
highlighter.codeToHtml(code, {
lang,
theme: "github-dark",
}),
);
return html;
},
},
layout: "src/lib/components/mdsvex/layouts/default.svelte",
// Adds IDs to headings, and anchor links to those IDs. Note: must stay in this order to work.
rehypePlugins: [rehypeSlug, rehypeAutolinkHeadings, rehypeKatexSvelte],
remarkPlugins: [
remarkMath,
[remarkToc, tocOptions],
[wikiLinkPlugin, wikiLinkOptions],
],
}),
vitePreprocess(),
],
kit: {
adapter: adapter({ fallback: "404.html" }),
prerender: {
handleMissingId: "warn",
entries: [
"/api/posts.json/",
"/api/posts/nav/[slug]",
"/api/posts/count/",
"/api/posts/page/[page]/",
"/api/rss.xml/",
"/blog/",
"/blog/category/",
"/blog/page",
"/blog/post",
],
},
},
};
export default config;