-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnuxt.config.ts
More file actions
113 lines (97 loc) · 3.02 KB
/
nuxt.config.ts
File metadata and controls
113 lines (97 loc) · 3.02 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
import { writeFileSync, mkdirSync } from 'fs'
import { join, dirname } from 'path'
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
components: true,
modules: ["@nuxt/content", "@nuxtjs/tailwindcss", "nuxt-headlessui"],
app: {
head: {
bodyAttrs: {
class: 'bg-background'
}
}
},
// Optionally change the default prefix.
headlessui: {
prefix: "Headless",
},
content: {
build: {
markdown: {
// Disable highlighting until interoperability with by the Tailwind Typography plugin is sorted
// highlight: false
highlight: {
theme: 'github-dark',
preload: [
'bash',
'js',
'json',
'lisp',
'lua',
'python',
'shell',
'ts',
'vue',
]
},
},
},
// https://github.com/nuxt/content/issues/3249#issuecomment-2778749735
experimental: { nativeSqlite: true }
},
nitro: {
// render server-side routes as static content
prerender: {
routes: ['/sitemap.xml', '/atom']
}
},
routeRules: {
'/articles': { redirect: { to: '/blog', statusCode: 301 } },
},
hooks: {
// Generate HTML redirect files for `/articles/**` to `/blog/**`
async 'close'() {
const { readdirSync, statSync, existsSync } = await import('fs')
const distBlogPath = join(process.cwd(), 'dist', 'blog')
const distArticlesPath = join(process.cwd(), 'dist', 'articles')
try {
if (!existsSync(distBlogPath)) {
console.log('Blog directory not found, skipping redirect generation')
return
}
if (!statSync(distBlogPath).isDirectory()) {
console.log('Blog directory path is not a directory, skipping redirect generation')
return
}
const blogDirs = readdirSync(distBlogPath, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
console.log(`Generating ${blogDirs.length} redirect files for old /articles paths...`)
for (const slug of blogDirs) {
const oldPath = `/articles/${slug}`
const newPath = `/blog/${slug}`
const redirectHtml = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Redirecting...</title>
<link rel="canonical" href="${newPath}">
<meta http-equiv="refresh" content="0; url=${newPath}">
<script>window.location.href = "${newPath}";</script>
</head>
<body>
<p>This page has moved to <a href="${newPath}">${newPath}</a>.</p>
</body>
</html>`
const outputPath = join(distArticlesPath, slug, 'index.html')
mkdirSync(dirname(outputPath), { recursive: true })
writeFileSync(outputPath, redirectHtml)
}
console.log('Redirect files generated successfully!')
} catch (error) {
console.warn('Could not generate redirect files:', error)
}
}
},
compatibilityDate: '2025-06-03'
});