svelte config readability update => Mdsvex.config.js
This commit is contained in:
parent
b04624c7ed
commit
417b2d5c35
139
svelte.config.js
139
svelte.config.js
|
@ -1,88 +1,19 @@
|
||||||
import adapter from '@sveltejs/adapter-auto';
|
import adapter from '@sveltejs/adapter-cloudflare';
|
||||||
import { vitePreprocess } from '@sveltejs/kit/vite';
|
import { vitePreprocess } from '@sveltejs/kit/vite';
|
||||||
import preprocess from 'svelte-preprocess';
|
import preprocess from 'svelte-preprocess';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { mdsvex } from 'mdsvex';
|
|
||||||
import headings from 'remark-autolink-headings';
|
|
||||||
import remarkExternalLinks from 'remark-external-links';
|
|
||||||
import slug from 'remark-slug';
|
|
||||||
import remarkSetImagePath from './src/lib/utils/remark-set-image-path.js';
|
|
||||||
import remarkEmbedVideo from './src/lib/utils/remark-embed-video.js';
|
|
||||||
import remarkLinkWithImageAsOnlyChild from './src/lib/utils/remark-link-with-image-as-only-child.js';
|
|
||||||
import remarkHeadingsPermaLinks from './src/lib/utils/remark-headings-permalinks.js';
|
|
||||||
import { toString } from 'mdast-util-to-string';
|
|
||||||
import rehypeWrap from 'rehype-wrap-all';
|
|
||||||
import rehypeImgSize from 'rehype-img-size';
|
|
||||||
import { highlightCode } from './src/lib/utils/highlight.js';
|
|
||||||
import { mdsvexGlobalComponents } from './src/lib/utils/mdsvex-global-components.js';
|
|
||||||
import { h } from 'hastscript';
|
|
||||||
import { visit } from 'unist-util-visit';
|
|
||||||
import getHeadings from './src/lib/utils/get-headings.js';
|
|
||||||
|
|
||||||
const mdsvexOptions = {
|
// import { mdsvexGlobalComponents } from './src/lib/utils/mdsvexGlobalComponents.js/index.js';
|
||||||
extensions: ['.md'],
|
import { mdsvex } from 'mdsvex';
|
||||||
highlight: {
|
import mdsvexConfig from './mdsvex.config.js';
|
||||||
highlighter: highlightCode,
|
/* Not using
|
||||||
},
|
// import { mdsvexGlobalComponents } from './src/lib/utils/mdsvex-global-components.js';
|
||||||
rehypePlugins: [
|
|
||||||
[
|
|
||||||
rehypeWrap,
|
|
||||||
{ selector: 'table', wrapper: 'div.overflow-auto' },
|
|
||||||
],
|
|
||||||
[rehypeImgSize, { dir: './static' }],
|
|
||||||
[
|
|
||||||
/** Custom rehype plugin to add loading="lazy" to all images */
|
|
||||||
() => {
|
|
||||||
return (tree) => {
|
|
||||||
visit(tree, 'element', (node) => {
|
|
||||||
if (node.tagName === 'img') {
|
|
||||||
node.properties.loading = 'lazy';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
},
|
|
||||||
],
|
|
||||||
],
|
|
||||||
remarkPlugins: [
|
|
||||||
[
|
|
||||||
remarkExternalLinks,
|
|
||||||
{
|
|
||||||
target: '_blank',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
slug,
|
|
||||||
[
|
|
||||||
headings,
|
|
||||||
{
|
|
||||||
behavior: 'append',
|
|
||||||
linkProperties: {},
|
|
||||||
content: function (node) {
|
|
||||||
return [
|
|
||||||
h('span.icon.icon-link header-anchor', {
|
|
||||||
ariaLabel: toString(node) + ' permalink',
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
remarkSetImagePath,
|
|
||||||
remarkLinkWithImageAsOnlyChild,
|
|
||||||
remarkHeadingsPermaLinks,
|
|
||||||
getHeadings,
|
|
||||||
[
|
|
||||||
remarkEmbedVideo,
|
|
||||||
{
|
|
||||||
width: 800,
|
|
||||||
height: 400,
|
|
||||||
noIframeBorder: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/** @type {import('@sveltejs/kit').Config} */
|
/** @type {import('@sveltejs/kit').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
extensions: ['.svelte', '.md'],
|
extensions: ['.svelte', ...(mdsvexConfig.extensions || [])],
|
||||||
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
|
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
|
||||||
// for more information about preprocessors
|
// for more information about preprocessors
|
||||||
preprocess: [
|
preprocess: [
|
||||||
|
@ -90,43 +21,61 @@ const config = {
|
||||||
preprocess({
|
preprocess({
|
||||||
postcss: true
|
postcss: true
|
||||||
}),
|
}),
|
||||||
mdsvexGlobalComponents({
|
// No neeed rn unless using mdsvex highlighter with svelte components
|
||||||
dir: `$lib/components`,
|
//mdsvexGlobalComponents({
|
||||||
list: [['CodeFence', 'code-fence.svelte']],
|
// dir: `$lib/components/blog`,
|
||||||
extensions: ['.md'],
|
// list: ['CodeFence.svelte'],
|
||||||
}),
|
// extensions: ['.md']
|
||||||
mdsvex(mdsvexOptions)
|
// }),
|
||||||
|
mdsvex(mdsvexConfig)
|
||||||
],
|
],
|
||||||
|
|
||||||
vitePlugin: {
|
vitePlugin: {
|
||||||
inspector: true,
|
inspector: true
|
||||||
},
|
},
|
||||||
kit: {
|
kit: {
|
||||||
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
|
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
|
||||||
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
|
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
|
||||||
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
|
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
|
||||||
|
|
||||||
adapter: adapter({
|
adapter: adapter({}),
|
||||||
runtime: 'nodejs18.x'
|
// sometimes problems with
|
||||||
}),
|
|
||||||
alias: {
|
alias: {
|
||||||
$lib: path.resolve('src', 'lib'),
|
$lib: path.resolve('src', 'lib'),
|
||||||
$root: path.resolve('/'),
|
$root: path.resolve('/'),
|
||||||
$src: path.resolve('src'),
|
$src: path.resolve('src'),
|
||||||
$routes: path.resolve('src', 'routes'),
|
$routes: path.resolve('src', 'routes')
|
||||||
$content: path.resolve('src', 'content')
|
},
|
||||||
|
// TODO: FIX Banning external malware scripts for security and privacy of users, threw errors,
|
||||||
|
// csp: {
|
||||||
|
// directives: {
|
||||||
|
// 'script-src': ['self']
|
||||||
|
// },
|
||||||
|
// reportOnly: {
|
||||||
|
// 'script-src': ['self']
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
csrf: {
|
||||||
|
checkOrigin: process.env.NODE_ENV === 'development' ? false : true
|
||||||
},
|
},
|
||||||
prerender: {
|
prerender: {
|
||||||
handleHttpError: ({ path, referrer, message }) => {
|
crawl: true,
|
||||||
// ignore deliberate link to shiny 404 page
|
handleMissingId: 'warn',
|
||||||
if (path === '/not-found' && referrer === '/404') {
|
handleHttpError: (details) => {
|
||||||
|
// Handle blog trying to prerender relative links that it can't
|
||||||
|
if (
|
||||||
|
details.status == 404 &&
|
||||||
|
details.path.startsWith('/blog') &&
|
||||||
|
details.referenceType == 'linked'
|
||||||
|
) {
|
||||||
|
console.warn(`PRERENDER ignored route ${details.path}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise fail the build
|
throw new Error(`${details.status} ${details.path} from ${details.referrer}`);
|
||||||
throw new Error(message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
Loading…
Reference in New Issue