-
Notifications
You must be signed in to change notification settings - Fork 1
/
astro.config.ts
88 lines (77 loc) · 2.39 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
import { defineConfig } from "astro/config";
import { SITE_URL } from "./src/constants/site";
// https://astro.build/config
import mdx from "@astrojs/mdx";
// https://astro.build/config
import tailwind from "@astrojs/tailwind";
// https://astro.build/config
import react from "@astrojs/react";
// https://astro.build/config
import sitemap from "@astrojs/sitemap";
// https://astro.build/config
import partytown from "@astrojs/partytown";
// https://astro.build/config
import rehypeRewrite, { RehypeRewriteOptions } from "rehype-rewrite";
import { classnames } from 'hast-util-classnames'
const shouldIgnore = (url: string): boolean => {
const regex = /(\/404$|\/tag(s$|s\/)|\/categorie(s$|s\/)|\/[0-9]{1,}$)/;
return regex.test(url);
};
const isInternalLink = (url: string | undefined): boolean => /^[\/\.]/.test(url ?? "");
const isExternalLink = (url: string | undefined): boolean => url?.startsWith("https://") ?? false;
const toHrefType = (href: string | undefined): "internal" | "external" | "unknown" => {
if (isExternalLink(href)) return "external"
if (isInternalLink(href)) return "internal"
return "unknown"
}
const rehypeRewriteOption: RehypeRewriteOptions = {
selector: "a",
rewrite: (node: any, index, parent) => {
const href: string | undefined = (node as any)?.properties?.href;
switch (toHrefType(href)) {
case "internal": {
classnames(node, "custom-anchor custom-anchor-internal")
return
}
case "external": {
classnames(node, "custom-anchor custom-anchor-external")
return;
}
case "unknown": {
console.info("Cannot identify unknown href type.", { href })
return
}
default: {
console.info("Cannot identify invalid href type.", { href })
return
}
}
},
};
export default defineConfig({
experimental: {
// REF: https://astro.build/blog/astro-340/
devOverlay: true
},
prefetch: true,
site: SITE_URL,
markdown: {
rehypePlugins: [[rehypeRewrite, rehypeRewriteOption]],
// syntaxHighlight: "prism",
},
integrations: [
mdx(),
tailwind(),
react(),
sitemap({ filter: (url) => !shouldIgnore(url) }),
partytown({
/**
* @link https://www.kevinzunigacuellar.com/blog/google-analytics-in-astro/
* Adds dataLayer.push as a forwarding-event.
*/
config: {
forward: ["dataLayer.push"],
},
}),
],
});