-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathastro.config.ts
More file actions
155 lines (153 loc) · 4.59 KB
/
astro.config.ts
File metadata and controls
155 lines (153 loc) · 4.59 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import type { Element } from 'hast'
import mdx from '@astrojs/mdx'
import partytown from '@astrojs/partytown'
import sitemap from '@astrojs/sitemap'
import Compress from 'astro-compress'
import robotsTxt from 'astro-robots-txt'
import { defineConfig } from 'astro/config'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypeExternalLinks from 'rehype-external-links'
import rehypeKatex from 'rehype-katex'
import rehypeSlug from 'rehype-slug'
import remarkDirective from 'remark-directive'
import remarkMath from 'remark-math'
import { visit } from 'unist-util-visit'
import UnoCSS from 'unocss/astro'
import { themeConfig } from './src/config'
import { langMap } from './src/i18n/config'
import { rehypeCodeCopyButton } from './src/plugins/rehype-code-copy-button.mjs'
import { rehypeImgToFigure } from './src/plugins/rehype-img-to-figure.mjs'
import { rehypeUnwrapImg } from './src/plugins/rehype-unwrap-img.mjs'
import { remarkAdmonitions } from './src/plugins/remark-admonitions.mjs'
import { remarkGithubCard } from './src/plugins/remark-github-card.mjs'
import { remarkReadingTime } from './src/plugins/remark-reading-time.mjs'
const url = themeConfig.site.url
const locale = themeConfig.global.locale
const linkPrefetch = themeConfig.preload.linkPrefetch
const imageHostURL = themeConfig.preload.imageHostURL
// Configure domains and remotePatterns to optimize remote images in Markdown files using  syntax
// Docs: https://docs.astro.build/en/guides/images/#authorizing-remote-images
const imageConfig = imageHostURL
? { image: { domains: [imageHostURL], remotePatterns: [{ protocol: 'https' }] } }
: {}
export default defineConfig({
site: url,
base: '/',
trailingSlash: 'always',
prefetch: {
prefetchAll: true,
defaultStrategy: linkPrefetch,
},
...imageConfig,
i18n: {
locales: Object.entries(langMap).map(([path, codes]) => ({
path,
codes: codes as [string, ...string[]],
})),
defaultLocale: locale,
},
integrations: [
UnoCSS({
injectReset: true,
}),
mdx(),
partytown({
config: {
forward: ['dataLayer.push', 'gtag'],
},
}),
sitemap(),
robotsTxt(),
Compress({
CSS: true,
HTML: true,
Image: false,
JavaScript: true,
SVG: false,
}),
],
markdown: {
remarkPlugins: [
remarkDirective,
remarkMath,
remarkAdmonitions,
remarkGithubCard,
remarkReadingTime,
],
rehypePlugins: [
rehypeKatex,
rehypeSlug,
rehypeCodeCopyButton,
rehypeImgToFigure,
rehypeUnwrapImg, // Must be after rehypeImgToFigure
[
rehypeAutolinkHeadings,
{
behavior: 'append',
test: ['h1', 'h2', 'h3', 'h4'],
content: {
type: 'element',
tagName: 'svg',
properties: {
'viewBox': '0 0 24 24',
'aria-hidden': 'true',
'fill': 'currentColor',
},
children: [
{
type: 'element',
tagName: 'path',
properties: {
d: 'M2.6 21.4c2 2 5.9 2.9 8.9 0l3.5-3.5-1-1-3.5 3.5c-1.4 1.4-4.2 1.9-6.4-.3s-1.8-5-.3-6.4l3.5-3.5-1-1-3.5 3.5c-3 3-2 6.9 0 8.9ZM21.4 2.6c2 2 2.9 5.9 0 8.9L17.9 15l-1-1 3.5-3.5c1.4-1.4 1.9-4.2-.3-6.4s-5-1.8-6.4-.3l-3.5 3.5-1-1 3.5-3.5c3-3 6.9-2 8.9 0Z',
},
},
{
type: 'element',
tagName: 'path',
properties: {
d: 'm8.01 14.97 6.93-6.93 1.061 1.06-6.93 6.93z',
},
},
],
},
properties: (el: Element) => {
let text = ''
visit(el, 'text', (textNode) => {
text += textNode.value
})
return {
className: ['heading-anchor-link'],
ariaLabel: text
? `Link to ${text.replace(/["']/g, char => char === '"' ? '"' : ''')}`
: undefined,
}
},
},
],
[
rehypeExternalLinks,
{
target: '_blank',
rel: ['nofollow', 'noopener', 'noreferrer', 'external'],
protocols: ['http', 'https', 'mailto'],
},
],
],
shikiConfig: {
// Available themes: https://shiki.style/themes
themes: {
light: 'github-light',
dark: 'github-dark',
},
},
},
devToolbar: {
enabled: false,
},
// For local development
// server: {
// headers: {
// 'Access-Control-Allow-Origin': 'https://giscus.app',
// },
// },
})