-
Notifications
You must be signed in to change notification settings - Fork 3
/
astro.config.mjs
67 lines (57 loc) · 1.75 KB
/
astro.config.mjs
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
import mdx from "@astrojs/mdx";
import partytown from "@astrojs/partytown";
import react from "@astrojs/react";
import sitemap from "@astrojs/sitemap";
import compress from "astro-compress";
import { defineConfig } from "astro/config";
import assert from "node:assert";
import { visitParents } from "unist-util-visit-parents";
import { canonicalUrl } from "./src/data/site";
import { attributesExtensionPlugin } from "./src/plugins/remark/attributesExtension";
import { addAutomaticLayoutPlugin } from "./src/plugins/remark/collectionData";
// https://astro.build/config
export default defineConfig({
integrations: [mdx(), sitemap(), react(), partytown(), compress()],
site: canonicalUrl,
vite: {
optimizeDeps: {
exclude: ["electron"],
},
},
markdown: {
extendDefaultPlugins: true,
remarkPlugins: [addAutomaticLayoutPlugin, attributesExtensionPlugin],
rehypePlugins: [
() => root => {
visitParents(root, "element", node => {
assert(node.type === "element");
if (node.tagName !== "img") return;
node.properties ??= {};
node.properties.loading = "lazy";
});
visitParents(root, "element", (node, parents) => {
assert(node.type === "element");
if (node.tagName !== "iframe") return;
const parent = parents.at(-1);
assert(parent);
if (parent.properties.class?.split(/\s+/g).includes("embed-container")) {
return;
}
const index = parent.children.indexOf(node);
assert(index !== -1);
/** @type {import("hast").Element} */
const wrapperNode = {
tagName: "div",
type: "element",
properties: {
class: "embed-container",
},
children: [node],
};
parent.children.splice(index, 1, wrapperNode);
});
return root;
},
],
},
});