-
Notifications
You must be signed in to change notification settings - Fork 2
/
svelte.config.js
67 lines (56 loc) · 1.74 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
import adapter from '@sveltejs/adapter-auto';
import preprocess from 'svelte-preprocess';
import { mdsvex } from "mdsvex";
import { fdir } from 'fdir';
import { defineConfig } from 'vite';
import { viteStaticCopy } from 'vite-plugin-static-copy'
/** @type {import('@sveltejs/kit').Config} */
const config = {
paths: {
},
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
extensions: ['.svelte', ".svelte.md", ".md", ".svx"],
preprocess: [
preprocess(),
mdsvex({
"extensions": [".svelte.md", ".md", ".svx"],
"smartypants": {
"dashes": "oldschool"
},
"remarkPlugins": [],
"rehypePlugins": []
}),
{
markup: ({ content, filename }) => {
if (![".svelte.md", ".md", ".svx"].some(extension => filename.includes(extension))) return { code: content }
const obsidianLinkRegex = /\[\[(.+?(\|.+?)?)\]\]([\W])/g
const transformedContent = content.replace(obsidianLinkRegex, (_, p1, p2, p3) => {
const slug = p1.includes("|") ? p1.slice(0, p1.indexOf("|")) : p1
const filePathArr = new fdir().glob(`./**/${slug}.md`).withRelativePaths().crawl('./src/sveltekit-vault').sync();
const href = `/` + (filePathArr.length === 1) ? filePathArr[0].slice(0, -3) : slug
const linkText = (p2) ? p2.slice(1) : p1
const linkHtml = `<a href="/${ href }">${ linkText }</a>` + p3
return linkHtml
})
return {
code: transformedContent,
}
}
}
],
kit: {
adapter: adapter(),
vite: defineConfig({
plugins: [
viteStaticCopy({
targets: [
{ src: './src/sveltekit-vault/_assets/*', dest: './static/assets/' },
]
})
],
// assetsInclude: ['./src/sveltekit-vault/_assets/*'],
})
}
};
export default config;