-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsvelte.config.js
104 lines (96 loc) · 2.56 KB
/
svelte.config.js
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import adapter from "@sveltejs/adapter-static";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
import { mdsvex } from "mdsvex";
import { visit } from "unist-util-visit";
import rehypeTitleFigure from 'rehype-title-figure'
import smartypants from "remark-smartypants";
import classNames from "rehype-class-names";
const classNamesOptions = {
h2: "section",
h3: "subsection",
h4: "subsubsection",
a: "link",
figure: "figure"
};
const blogImages = () => {
return (tree, file) => {
visit(tree, "image", (node) => {
if (node.url.startsWith("./")) {
const route = file.filename
.split("routes")[1]
.split("/")
.slice(0, -1)
.join("/");
node.url = `${route}/${node.url.slice(2)}`;
}
});
};
};
const escapeQuotes = () => {
return (tree) => {
visit(tree, 'image', (node) => {
if (node.alt) {
node.alt = node.alt.replace(/"/g, '"');
}
});
};
}
const mdsvexOptions = {
extensions: [".md"],
remarkPlugins: [
smartypants,
escapeQuotes
],
rehypePlugins: [
blogImages,
rehypeTitleFigure,
[classNames, classNamesOptions],
],
layout: {
blog: "src/lib/blocks/Post.svelte",
},
};
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter(),
prerender: {
handleHttpError: "warn",
handleMissingId: "ignore",
entries: ["*"],
},
paths: {
base: process.env.NODE_ENV === "production" ? "" : "",
},
alias: {
$static: 'static'
}
},
extensions: [".svelte", ".md"],
preprocess: [
vitePreprocess(),
mdsvex(mdsvexOptions)
],
vitePlugin: {
inspector: true
},
// Omit warning about screenreaders announcing <img> elements as an image
onwarn: (warning, handler) => {
// Fail the build on production if we have redundant words in the alt text
//if (process.env.NODE_ENV === 'production' &&
// warning.code === 'a11y-img-redundant-alt' &&
// warning.message.includes('Screenreaders already announce')) {
// throw new Error(
// `Build failed: Image alt text contains redundant terms (${warning.filename})\n` +
// 'Remove words like "image", "photo", or "picture" from alt text as screen readers already announce these.'
// );
//}
// Omit the warning about redundant alt text if we are on development mode
if (warning.code === 'a11y-img-redundant-alt' &&
warning.message.includes('Screenreaders already announce')) {
return;
}
handler(warning);
}
};
export default config;