-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathsvelte.config.ts
More file actions
80 lines (71 loc) · 3.07 KB
/
Copy pathsvelte.config.ts
File metadata and controls
80 lines (71 loc) · 3.07 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
68
69
70
71
72
73
74
75
76
77
78
79
80
// Kept separate from vite.config.ts on purpose: @sveltejs/package only reads
// svelte.config.{js,ts} (node_modules/@sveltejs/package/src/config.js), so moving this into
// an inline config passed to sveltekit() would leave `pnpm package:dist` with no
// preprocessors, extensions or aliases. Kit itself resolves inline config fine.
import adapter from '@sveltejs/adapter-static'
import type { Config } from '@sveltejs/kit'
import { common } from '@wooorm/starry-night'
import svelte_grammar from '@wooorm/starry-night/source.svelte'
import tsx_grammar from '@wooorm/starry-night/source.tsx'
import vue_grammar from '@wooorm/starry-night/text.html.vue'
import { mdsvex } from 'mdsvex'
import type { PreprocessorGroup } from 'svelte/compiler'
import { heading_ids } from 'svelte-widgets/heading-anchors'
import { mdsvex_transform } from 'svelte-widgets/live-examples'
import {
create_highlighter,
render_block,
} from 'svelte-widgets/live-examples/create-highlighter'
const { default: pkg } = await import(`./package.json`, {
with: { type: `json` },
})
const defaults = {
Wrapper: [`svelte-widgets`, `CodeExample`],
repo: pkg.repository,
hideStyle: true,
collapsible: true,
}
// svelte-widgets' default highlighter only knows starry-night's `common` bundle plus
// Svelte, which would leave the tsx/vue fences in the framework-interop docs unstyled
const grammars = [...common, svelte_grammar, tsx_grammar, vue_grammar]
const starry_night = await create_highlighter(grammars).ready()
// Heading anchors are a docs-site feature, but preprocessors run over src/lib too, where
// the injected ids end up in the published package: nothing references them, and a heading
// inside an {#each} (ChemPotDiagram's per-projection <h4>) repeats one id per iteration.
// Site pages lose nothing - the heading_anchors attachment slugifies missing ids at runtime
// with document-wide deduping.
const heading_id_injector = heading_ids()
const site_heading_ids: PreprocessorGroup = {
name: heading_id_injector.name,
// Separators normalized first: on Windows `input.filename` arrives back-slashed, so a
// `/`-only pattern misses src\lib and injects ids into packaged library components.
markup: (input) =>
/(?:^|\/)src\/lib\//.test(input.filename?.replaceAll(`\\`, `/`) ?? ``)
? undefined
: heading_id_injector.markup(input),
}
export default {
extensions: [`.svelte`, `.svx`, `.md`],
preprocess: [
mdsvex({
remarkPlugins: [[mdsvex_transform, { defaults }]],
extensions: [`.svx`, `.md`],
highlight: { highlighter: (code, lang) => render_block(starry_night, code, lang) },
}),
site_heading_ids, // runs after mdsvex converts markdown to HTML
],
kit: {
adapter: adapter({
strict: false, // don't fail on symlinks
}),
alias: { $site: `src/site`, $root: `.`, matterviz: `src/lib` },
prerender: {
handleHttpError: ({ path, message }) => {
// ignore missing element photos
if (path.startsWith(`/elements/`)) return
// fail the build for other errors
throw new Error(message)
},
},
},
} satisfies Config