Svelte & MDSveX config

This commit is contained in:
matthieu42morin 2024-04-28 13:53:57 +02:00
parent a9ce9291e5
commit 5c6dcf7bae
2 changed files with 37 additions and 18 deletions

View File

@ -15,6 +15,7 @@ import remarkFootnotes from 'remark-footnotes'
import { escapeSvelte } from 'mdsvex'
import { lex, parse as parseFence } from 'fenceparser'
import { renderCodeToHTML, runTwoSlash, createShikiHighlighter } from 'shiki-twoslash'
import readingTime from 'mdsvex-reading-time'
const remarkUraraFm =
() =>
@ -60,7 +61,7 @@ export default {
dashes: 'oldschool'
},
layout: {
_: './src/lib/components/post_layout.svelte'
_: './src/lib/components/blog/post_layout.svelte'
},
highlight: {
highlighter: async (code, lang, meta) => {
@ -76,8 +77,8 @@ export default {
code,
lang,
fence ?? {},
{ themeName: 'material-default' },
await createShikiHighlighter({ theme: 'material-default' }),
{ themeName: 'github-dark-dimmed' },
await createShikiHighlighter({ theme: 'github-dark-dimmed' }),
twoslash
)
)}\` }`
@ -101,6 +102,7 @@ export default {
}
}
],
[readingTime, { wpm: 200 }],
remarkUraraFm,
remarkUraraSpoiler,
[remarkFootnotes, { inlineNotes: true }]

View File

@ -5,7 +5,8 @@ import adapterStatic from '@sveltejs/adapter-static'
// svelte preprocessor
import { mdsvex } from 'mdsvex'
import mdsvexConfig from './mdsvex.config.js'
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
// import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
import preprocess from 'svelte-preprocess'
const adapter = {
auto: adapterAuto(),
@ -19,22 +20,38 @@ const adapter = {
/** @type {import("@svletejs/kit".Config)} */
export default {
extensions: ['.svelte', ...mdsvexConfig.extensions],
preprocess: [mdsvex(mdsvexConfig), vitePreprocess()],
extensions: ['.svelte', ...(mdsvexConfig.extensions || [])],
preprocess: [preprocess({ postcss: true }), mdsvex(mdsvexConfig) /*, vitePreprocess()*/],
vitePlugin: {
inspector: true
},
kit: {
adapter:
process.env.ADAPTER
? adapter[process.env.ADAPTER.toLowerCase()]
: Object.keys(process.env).some(key => ['VERCEL', 'NETLIFY'].includes(key))
? adapter['auto']
: adapter['static'],
prerender: {
handleMissingId: 'warn'
adapter: process.env.ADAPTER
? adapter[process.env.ADAPTER.toLowerCase()]
: Object.keys(process.env).some(key => ['VERCEL', 'NETLIFY'].includes(key))
? adapter['auto']
: adapter['static'],
alias: {
$lib: './src/lib',
$root: './',
$src: './src',
$routes: './src/routes',
$content: './content'
},
csp: {
mode: 'auto',
directives: {
'style-src': ['self', 'unsafe-inline', 'https://giscus.app']
csrf: {
checkOrigin: process.env.NODE_ENV === 'development' ? false : true
},
prerender: {
crawl: true,
handleMissingId: 'warn',
handleHttpError: details => {
// Handle blog trying to prerender relative links that it can't
if (details.status == 404 && details.path.startsWith('/blog' && '/projects') && details.referenceType == 'linked') {
console.warn(`PRERENDER ignored route ${details.path}`)
return
}
throw new Error(`${details.status} ${details.path} from ${details.referrer}`)
}
}
}