forked from Die-KoMa/die-koma.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
astro.config.ts
94 lines (88 loc) · 2.35 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
import { defineConfig } from 'astro/config'
import { favicons } from 'favicons'
import { twMerge } from 'tailwind-merge'
import compress from 'astro-compress'
import mdx from '@astrojs/mdx'
import rehypeExternalLinks from 'rehype-external-links'
import tailwind from '@astrojs/tailwind'
import type { FaviconOptions } from 'favicons'
function setDefaultLayout() {
return function (_: any, file: any) {
const { frontmatter } = file.data.astro
if (!frontmatter.layout) frontmatter.layout = '@layouts/BaseLayout.astro'
}
}
function rehypeExternalLinksPlugin() {
return rehypeExternalLinks({
target: '_blank',
rel: ['noopener', 'noreferrer'],
properties: (element) => ({
className: twMerge(
element.properties.className?.toString(),
'after:external-link after:ml-1',
),
}),
})
}
async function faviconPlugin(options: FaviconOptions = {}) {
const icons = await favicons('./src/favicon.svg', options)
return {
name: 'vite-plugin-favicons',
order: 'pre',
sequential: true,
transform(src: string, id: string) {
if (id.endsWith('src/layouts/BaseLayout.astro')) {
src = src.replace('</head>', icons.html.join('') + '</head>')
}
return src
},
configureServer(server: any) {
for (const icon of icons.images) {
server.middlewares.use(`/${icon.name}`, (req: any, res: any) => {
res.end(icon.contents)
})
}
},
generateBundle(options: any, bundle: any) {
for (const icon of icons.images) {
bundle[icon.name] = {
type: 'asset',
fileName: icon.name,
source: icon.contents,
}
}
},
}
}
// https://astro.build/config
export default defineConfig({
prefetch: {
prefetchAll: true,
},
integrations: [mdx(), tailwind(), compress()],
markdown: {
remarkPlugins: [setDefaultLayout],
rehypePlugins: [rehypeExternalLinksPlugin],
},
vite: {
plugins: [
faviconPlugin({
background: '#134e4a',
icons: {
favicons: [
'favicon.svg',
'favicon.ico',
'favicon-16x16.png',
'favicon-32x32.png',
'favicon-48x48.png',
],
android: false,
appleIcon: true,
appleStartup: false,
windows: false,
yandex: false,
},
}),
],
},
})