-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathastro.config.mjs
More file actions
133 lines (129 loc) · 4.47 KB
/
Copy pathastro.config.mjs
File metadata and controls
133 lines (129 loc) · 4.47 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// @ts-check
import { defineConfig } from "astro/config";
import mdx from "@astrojs/mdx";
import react from "@astrojs/react";
import { h } from "hastscript";
import rehypeTypeset from "./src/lib/rehype-typeset";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import rehypeSlug from "rehype-slug";
import remarkDecorations from "./src/lib/remark-decorations";
import remarkSectionize from "remark-sectionize";
import { fromHtml } from "hast-util-from-html";
import {
transformerNotationDiff,
transformerMetaWordHighlight,
transformerNotationWordHighlight,
transformerRemoveNotationEscape,
} from "@shikijs/transformers";
import shakuCodeAnnotateShikiTransformer from "shaku-code-annotate-shiki-transformer";
import tailwindcss from "@tailwindcss/vite";
import { optimizeCssModules } from "vite-plugin-optimize-css-modules";
import browserslist from "browserslist";
import { browserslistToTargets } from "lightningcss";
import rename from "astro-rename";
import wasm from "vite-plugin-wasm";
import topLevelAwait from "vite-plugin-top-level-await";
import postcssRename from "postcss-rename";
import { fileURLToPath } from "node:url";
import { readdir, readFile, writeFile } from "node:fs/promises";
import cssnano from "cssnano";
import { shield } from "@kindspells/astro-shield";
let classMap = {};
const escapeRegExp = (string) => string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const hToLevel = (node) => {
switch (node.tagName) {
case "h1":
return 1;
case "h2":
return 2;
case "h3":
return 3;
}
};
// https://astro.build/config
export default defineConfig({
site: "https://skyeto.com",
vite: {
plugins: [wasm(), topLevelAwait(), tailwindcss()],
css: {
transformer: "postcss",
},
},
integrations: [
shield({}),
mdx({
rehypePlugins: [
rehypeTypeset,
rehypeSlug,
[
rehypeAutolinkHeadings,
{
behavior: "prepend",
content: (node) => {
const level = hToLevel(node);
return h(
"span.heading-link",
fromHtml(
`<svg class="inline w-2 h-2 text-gray-800 dark:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.213 9.787a3.391 3.391 0 0 0-4.795 0l-3.425 3.426a3.39 3.39 0 0 0 4.795 4.794l.321-.304m-.321-4.49a3.39 3.39 0 0 0 4.795 0l3.424-3.426a3.39 3.39 0 0 0-4.794-4.795l-1.028.961"/></svg>`
)
);
},
},
],
],
remarkPlugins: [remarkDecorations, remarkSectionize],
}),
react(),
{
name: "rename-classes",
hooks: {
"astro:build:done": async ({ dir }) => {
// /* The problem with this is that it replaces not just classes, but words that match the class names. */
// const dist = fileURLToPath(dir);
// for await (const file of await readdir(dist, { recursive: true })) {
// if (!["html", "js"].some((ext) => file.endsWith(ext))) continue;
// const fileName = dist + file;
// let content = await readFile(fileName, "utf-8");
// Object.keys(classMap).forEach((key) => {
// const regex = new RegExp(
// `(:^|[^-&;:_])(${escapeRegExp(key)})(?![a-zA-Z0-9_-])(:$|[^-&;:_\./])`,
// "g"
// );
// content = content.replaceAll(regex, `$1${classMap[key]}$3`);
// });
// await writeFile(fileName, content, {
// encoding: "utf8",
// flag: "w",
// });
// }
},
},
},
],
markdown: {
shikiConfig: {
theme: "catppuccin-frappe",
transformers: [
transformerMetaWordHighlight(),
transformerNotationWordHighlight(),
{
name: "shiki:inline-decorations",
preprocess(code, options) {
const reg = /^\/\/ @decorations:(.*)\n/;
code = code.replace(reg, (match, decorations) => {
options.decorations ||= [];
options.decorations.push(...JSON.parse(decorations));
return "";
});
return code;
},
},
transformerNotationDiff(),
shakuCodeAnnotateShikiTransformer({
shakuTrigger: /annotate/,
theme: "astro-code",
}),
],
},
},
});