-
Notifications
You must be signed in to change notification settings - Fork 2
/
astro.config.ts
147 lines (139 loc) · 3.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
import process from 'node:process'
import { readFile } from 'node:fs/promises'
import { defineConfig } from 'astro/config'
import unocss from 'unocss/astro'
import sitemap from '@astrojs/sitemap'
import vercel from '@astrojs/vercel/serverless'
import rehypeExternalLinks from 'rehype-external-links'
import remarkDirective from 'remark-directive'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypeSlug from 'rehype-slug'
import icon from 'astro-icon'
import solid from '@astrojs/solid-js'
import { FontaineTransform } from 'fontaine'
import mdx from '@astrojs/mdx'
import type { AstroIntegration } from 'astro'
import {
rehypeCopy,
remarkAsides,
} from './mdx-plugins'
const astroHTMX: AstroIntegration = {
name: 'astro-htmx',
hooks: {
'astro:config:setup': ({ injectScript }) => {
injectScript(
'page',
`import * as htmx from "htmx.org";
document.addEventListener('astro:after-swap', () => {
htmx.process(document.body)
})`,
)
},
},
}
const site = process.env.SITE_HOST === 'luxass.com' ? 'https://luxass.com' : 'https://luxass.dev'
// eslint-disable-next-line no-console
console.log('site', site)
// https://astro.build/config
export default defineConfig({
site,
integrations: [
sitemap({
lastmod: new Date(),
changefreq: 'daily',
async serialize(item) {
if (item.url !== `${site}/posts/` && item.url.includes('/posts/')) {
const url = item.url.replace('https://luxass.dev', '')
const content = await readFile(`./src/content${url.slice(0, url.length - 1)}.mdx`, 'utf-8')
// parse front matter in content file.
const frontMatterEndIndex = content.indexOf('---', 3)
if (frontMatterEndIndex === -1) {
throw new Error(`Front matter not found in ${url}`)
}
const frontMatter = content.slice(3, frontMatterEndIndex).trim()
const isDraft = frontMatter.includes('draft: true')
// If draft is set to true, do not include in sitemap.
if (isDraft) {
return undefined
}
}
return {
url: item.url,
lastmod: item.lastmod,
changefreq: item.changefreq,
priority: item.priority,
}
},
// filter(page) {
// return !page.startsWith("/posts")
// },
}),
astroHTMX,
solid(),
unocss({
injectReset: true,
}),
icon({
include: {
logos: ['npm-icon'],
lucide: ['clipboard', 'clipboard-check', 'search'],
tabler: ['mail'],
mdi: [
'github',
'arrow-top-right-thin',
'rss',
'sitemap',
'linkedin',
'arrow-right-thin',
],
},
}),
mdx(),
],
experimental: {
contentCollectionCache: true,
contentCollectionJsonSchema: true,
directRenderScript: true,
},
prefetch: {
prefetchAll: true,
defaultStrategy: 'load',
},
markdown: {
shikiConfig: {
themes: {
dark: 'vitesse-dark',
light: 'vitesse-light',
},
},
rehypePlugins: [
rehypeSlug,
rehypeAutolinkHeadings,
[rehypeExternalLinks, {
target: '_blank',
rel: ['noopener', 'noreferrer'],
}],
rehypeCopy,
],
remarkPlugins: [
remarkDirective,
remarkAsides,
],
},
output: 'hybrid',
adapter: vercel({
webAnalytics: {
enabled: true,
},
edgeMiddleware: true,
functionPerRoute: false,
}),
vite: {
plugins: [
FontaineTransform.vite({
fallbacks: ['Arial'],
resolvePath: (id) => new URL(`./public${id}`, import.meta.url), // id is the font src value in the CSS
}),
],
},
})