-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
61 lines (55 loc) · 2.05 KB
/
Copy pathvite.config.ts
File metadata and controls
61 lines (55 loc) · 2.05 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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import mdx from '@mdx-js/rollup'
import remarkGfm from 'remark-gfm'
import remarkFrontmatter from 'remark-frontmatter'
import remarkMdxFrontmatter from 'remark-mdx-frontmatter'
import remarkMath from 'remark-math'
import rehypeKatex from 'rehype-katex'
import { toString } from 'mdast-util-to-string'
import { readdirSync, writeFileSync } from 'node:fs'
const ORIGIN = 'https://intellycode.dev'
function slugsIn(kind: string) {
return readdirSync(`src/content/${kind}`)
.filter((file) => file.endsWith('.mdx'))
.map((file) => `/${kind}/${file.replace('.mdx', '')}`)
}
function writeSitemap(dir: string) {
const paths = ['/', '/blog', ...slugsIn('case-studies'), ...slugsIn('blog')]
const urls = paths.map((path) => ` <url><loc>${ORIGIN}${path}</loc></url>`).join('\n')
writeFileSync(
`${dir}/sitemap.xml`,
`<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls}\n</urlset>\n`,
)
writeFileSync(dir + '/robots.txt', `User-agent: *\nAllow: /\n\nSitemap: ${ORIGIN}/sitemap.xml\n`)
}
function remarkReadingMinutes() {
return (tree: any) => {
const yaml = tree.children.find((node: any) => node.type === 'yaml')
const body = tree.children.filter((node: any) => node.type !== 'yaml')
const words = toString({ type: 'root', children: body }).split(/\s+/).length
yaml.value += `\nminutes: ${Math.max(1, Math.round(words / 230))}`
}
}
export default defineConfig({
plugins: [
{
enforce: 'pre',
...mdx({
providerImportSource: '@mdx-js/react',
remarkPlugins: [remarkGfm, remarkMath, remarkFrontmatter, remarkReadingMinutes, remarkMdxFrontmatter],
rehypePlugins: [rehypeKatex],
}),
},
react({ include: /\.(mdx|tsx)$/ }),
],
css: {
preprocessorOptions: {
scss: { quietDeps: true, silenceDeprecations: ['import', 'global-builtin', 'color-functions', 'if-function'] },
},
},
ssgOptions: {
dirStyle: 'flat',
onFinished: writeSitemap,
},
})