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

View File

@ -5,7 +5,8 @@ import adapterStatic from '@sveltejs/adapter-static'
// svelte preprocessor // svelte preprocessor
import { mdsvex } from 'mdsvex' import { mdsvex } from 'mdsvex'
import mdsvexConfig from './mdsvex.config.js' 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 = { const adapter = {
auto: adapterAuto(), auto: adapterAuto(),
@ -19,22 +20,38 @@ const adapter = {
/** @type {import("@svletejs/kit".Config)} */ /** @type {import("@svletejs/kit".Config)} */
export default { export default {
extensions: ['.svelte', ...mdsvexConfig.extensions], extensions: ['.svelte', ...(mdsvexConfig.extensions || [])],
preprocess: [mdsvex(mdsvexConfig), vitePreprocess()], preprocess: [preprocess({ postcss: true }), mdsvex(mdsvexConfig) /*, vitePreprocess()*/],
vitePlugin: {
inspector: true
},
kit: { kit: {
adapter: adapter: process.env.ADAPTER
process.env.ADAPTER ? adapter[process.env.ADAPTER.toLowerCase()]
? adapter[process.env.ADAPTER.toLowerCase()] : Object.keys(process.env).some(key => ['VERCEL', 'NETLIFY'].includes(key))
: Object.keys(process.env).some(key => ['VERCEL', 'NETLIFY'].includes(key)) ? adapter['auto']
? adapter['auto'] : adapter['static'],
: adapter['static'], alias: {
prerender: { $lib: './src/lib',
handleMissingId: 'warn' $root: './',
$src: './src',
$routes: './src/routes',
$content: './content'
}, },
csp: { csrf: {
mode: 'auto', checkOrigin: process.env.NODE_ENV === 'development' ? false : true
directives: { },
'style-src': ['self', 'unsafe-inline', 'https://giscus.app'] 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}`)
} }
} }
} }