-
Notifications
You must be signed in to change notification settings - Fork 4
/
astro.config.ts
197 lines (185 loc) · 4.7 KB
/
astro.config.ts
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import { defineConfig } from "astro/config";
// astro
// import node from '@astrojs/node';
// heading ids
import { rehypeHeadingIds } from "@astrojs/markdown-remark";
import rehypeAutolinkHeadings from "./src/scripts/rehype/anchor.ts";
// icon
import icon from "astro-icon";
// frameworks
import mdx from "@astrojs/mdx";
// sitemap
import sitemap from "@astrojs/sitemap";
// math
import remarkMath from "remark-math";
import { typst } from "astro-typst";
// code
// @ts-ignore
import remarkSampKbd from "remark-samp-kbd";
// https://sat0shi.dev/posts/highlight-line-on-codeblock-with-astro/
import { manjuify } from "./src/scripts/manju.ts";
import remarkRuby from "remark-ruby";
import remarkDirect from "remark-directive";
import { h } from "hastscript";
import { visit } from "unist-util-visit";
import type { Node } from "mdast";
function myRemarkPlugin() {
return (tree: Node) => {
visit(tree, (node) => {
if (
node.type === "containerDirective" ||
node.type === "leafDirective" ||
node.type === "textDirective"
) {
const data = node.data || (node.data = {});
const hast = h(node.name, node.attributes || {});
let name = hast.tagName;
let props = hast.properties;
switch (name) {
case "j":
if (props) {
name = "abbr";
props = {
title: props.m || props.e || props.p,
lang: "zh-juai",
};
}
break;
case "m": // Möllendorff
name = "span";
// console.log(node);
/*
{
type: 'textDirective',
name: 'm',
attributes: {},
children: [ { type: 'text', value: 'ilha -i', position: [Object] } ],
position: {
start: { line: 18, column: 87, offset: 1237 },
end: { line: 18, column: 98, offset: 1248 }
},
data: {}
}
*/
// @ts-ignore
node.children?.forEach((child) => {
if (child.type === "text") child.value = manjuify(child.value);
});
// console.log(node);
props = {
lang: "mnc",
};
break;
case "de":
name = "span";
props = {
lang: "de",
};
break;
case "en":
name = "span";
props = {
lang: "en",
};
break;
case "up":
name = "span";
props = {
className: ["upright"],
};
break;
case "yoko":
name = "span";
props = {
className: ["yoko"],
};
break;
}
data.hName = name;
data.hProperties = props;
}
});
};
}
// @ts-ignore
import remarkFigureCaption from "gridsome-remark-figure-caption"; // "@microflash/remark-figure-caption";
// Atomic CSS
import unocss from "unocss/astro";
import react from "@astrojs/react";
// import qwik from "@qwikdev/astro";
import { rehypePipe } from "./src/scripts/rehype/common.ts";
// https://astro.build/config
export default defineConfig({
site: "https://blog.xinshijiededa.men",
// redirects: { "/atom.xml": "/feed" },
build: {
// format: "preserve",
},
// output: "server",
// adapter: node({
// mode: 'standalone',
// }),
image: {
domains: [
"github.com",
"githubusercontent.com",
"wikimedia.org",
"xkcd.in",
],
},
vite: {
ssr: {
external: ["prismjs", "@myriaddreamin/typst-ts-node-compiler"],
noExternal: [
"xp.css",
"98.css",
"@shikijs/twoslash/style-rich.css",
"rehype-remnote/style/*",
],
},
},
markdown: {
remarkRehype: {
footnoteLabel: "---",
footnoteBackLabel: "返回内容",
},
syntaxHighlight: false,
remarkPlugins: [
remarkMath,
remarkRuby,
remarkFigureCaption,
remarkSampKbd,
remarkDirect,
myRemarkPlugin,
],
rehypePlugins: [
/**
* You can customize these heading IDs by adding a rehype plugin that
* injects id attributes (e.g. rehype-slug). Your custom IDs, instead
* of Astro’s defaults, will be reflected in the HTML output and the
* items returned by getHeadings().
*
* By default, Astro injects idattributes after your rehype plugins
* have run. If one of your custom rehype plugins needs to access the
* IDs injected by Astro, you can import and use Astro’s
* `rehypeHeadingIds` plugin directly. Be sure to add `rehypeHeadingIds`
* before any plugins that rely on it:
*/
rehypeHeadingIds,
// @ts-ignore
rehypeAutolinkHeadings,
// @ts-expect-error
].concat(rehypePipe),
},
integrations: [
unocss(),
icon(),
// qwik({ include: ["**/qwik/*", "**/*.qwik.*sx"] }),
react(
// { include: ["**/react/*", "**/*.tsx*", "spoiled"] }
),
mdx(),
typst(),
sitemap(),
],
});