svgl/svelte.config.js

71 lines
1.8 KiB
JavaScript
Raw Normal View History

2023-12-16 17:07:44 +00:00
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
2023-03-14 21:08:22 +00:00
2024-09-23 10:47:26 +01:00
// ☁️ Adapter:
import adapter from '@sveltejs/adapter-node';
2024-09-23 10:47:26 +01:00
// 📦 Extensions:
2023-12-13 23:42:17 +00:00
import { mdsvex, escapeSvelte } from 'mdsvex';
import { createHighlighter, makeSingletonHighlighter } from 'shiki';
2024-10-01 10:49:43 +01:00
// 🎨 Markdown Plugins:
import remarkGfm from 'remark-gfm';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import rehypeSlug from 'rehype-slug';
2024-09-23 10:47:26 +01:00
// 📄 Markdown config:
const getHighlighter = makeSingletonHighlighter(createHighlighter);
2023-12-13 23:42:17 +00:00
/** @type {import('mdsvex').MdsvexOptions} */
const mdsvexOptions = {
2024-10-01 10:49:43 +01:00
remarkPlugins: [[remarkGfm]],
rehypePlugins: [
[rehypeSlug],
[
rehypeAutolinkHeadings,
{
behavior: 'wrap',
properties: {
className: [
`before:content-['#'] before:absolute before:-ml-[1em] before:text-neutral-100/0 hover:before:text-neutral-200/50 pl-[1em] -ml-[1em]`
]
}
}
]
],
2023-12-13 23:42:17 +00:00
extensions: ['.md'],
highlight: {
highlighter: async (code, lang = 'text') => {
2024-03-09 12:46:38 +00:00
const highlighter = await getHighlighter({
2025-01-15 16:05:41 +00:00
themes: ['github-light', 'github-dark'],
2024-03-09 12:46:38 +00:00
langs: ['javascript', 'typescript', 'bash', 'json']
});
await highlighter.loadLanguage('javascript', 'typescript', 'bash');
2025-01-15 16:05:41 +00:00
const html = escapeSvelte(
highlighter.codeToHtml(code, {
lang,
themes: {
light: 'github-light',
dark: 'github-dark'
}
})
);
2023-12-13 23:42:17 +00:00
return `{@html \`${html}\` }`;
}
}
};
// 🧡 Svelte config:
2023-03-14 21:08:22 +00:00
/** @type {import('@sveltejs/kit').Config} */
const config = {
2023-12-13 23:42:17 +00:00
extensions: ['.svelte', '.md'],
preprocess: [vitePreprocess(), mdsvex(mdsvexOptions)],
2023-03-15 11:29:15 +00:00
kit: {
2023-03-19 14:53:31 +00:00
adapter: adapter(),
alias: {
2023-12-13 23:42:17 +00:00
'@': './src/*'
2023-03-19 14:53:31 +00:00
}
2023-03-15 11:29:15 +00:00
}
2023-03-14 21:08:22 +00:00
};
export default config;