speice.io/vite.config.ts

50 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-04-15 12:56:22 -04:00
import { defineConfig } from "vite";
import blog from "@bspeice/vite-plugin-blog";
import mdx from "@mdx-js/rollup";
import react from "@vitejs/plugin-react-swc";
2023-04-21 21:39:53 -04:00
import rehypeHighlight from "rehype-highlight";
2023-04-15 12:55:22 -04:00
2023-04-21 21:39:53 -04:00
import { Root, Element } from "hast";
import { Plugin } from "unified";
import { visit } from "unist-util-visit";
// Add the `hljs` class to `pre` so it picks up the highlight background color
const highlightPre: Plugin<[], Root> = () => {
return (tree) => {
visit(tree, (node, _, parent) => {
if (
!parent ||
(parent as Element).tagName !== "pre" ||
(node as Element).tagName !== "code"
) {
return;
}
const parentElement = parent as Element;
const parentProperties = parentElement.properties;
if (!parentProperties) {
return;
}
if (!Array.isArray(parentProperties["className"])) {
parentProperties["className"] = ["hljs"];
} else {
parentProperties["className"].unshift("hljs");
}
});
};
};
2023-04-16 20:10:40 -04:00
2023-04-15 12:55:22 -04:00
export default defineConfig({
plugins: [
blog({
2023-04-16 20:10:40 -04:00
"/": "/pages/index.tsx",
"/about": "/pages/about.mdx",
"/2019/02/the-whole-world": "/posts/2019/02/the-whole-world.mdx",
2023-04-15 12:55:22 -04:00
}),
2023-04-21 21:39:53 -04:00
mdx({ rehypePlugins: [rehypeHighlight, highlightPre] }),
2023-04-15 12:56:22 -04:00
react(),
2023-04-15 12:55:22 -04:00
],
2023-04-15 12:56:22 -04:00
});