Skip to content

Commit 32f705a

Browse files
committed
refactor: move blog configuration into module
1 parent f64aa74 commit 32f705a

2 files changed

Lines changed: 36 additions & 26 deletions

File tree

modules/blog.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import Markdown from 'unplugin-vue-markdown/vite'
2+
import { addVitePlugin, defineNuxtModule, useNuxt } from 'nuxt/kit'
3+
import shiki from '@shikijs/markdown-it'
4+
import { defu } from 'defu'
5+
6+
export default defineNuxtModule({
7+
meta: {
8+
name: 'blog',
9+
},
10+
setup() {
11+
const nuxt = useNuxt()
12+
13+
nuxt.options.extensions.push('.md')
14+
nuxt.options.vite.vue = defu(nuxt.options.vite.vue, {
15+
include: [/\.vue($|\?)/, /\.(md|markdown)($|\?)/],
16+
})
17+
18+
addVitePlugin(() =>
19+
Markdown({
20+
include: [/\.(md|markdown)($|\?)/],
21+
wrapperComponent: 'BlogPostWrapper',
22+
wrapperClasses: 'text-fg-muted leading-relaxed',
23+
async markdownItSetup(md) {
24+
md.use(
25+
await shiki({
26+
themes: {
27+
dark: 'github-dark',
28+
light: 'github-light',
29+
},
30+
}),
31+
)
32+
},
33+
}),
34+
)
35+
},
36+
})

nuxt.config.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import process from 'node:process'
22
import { currentLocales } from './config/i18n'
3-
import Markdown from 'unplugin-vue-markdown/vite'
43
import { isCI, isTest, provider } from 'std-env'
5-
import type { ViteOptions } from 'nuxt/schema'
64

75
const isStorybook = process.env.STORYBOOK === 'true' || process.env.VITEST_STORYBOOK === 'true'
86

97
export default defineNuxtConfig({
10-
extensions: ['.md'],
118
modules: [
129
'@unocss/nuxt',
1310
'@nuxtjs/html-validator',
@@ -351,29 +348,6 @@ export default defineNuxtConfig({
351348
},
352349

353350
vite: {
354-
vue: {
355-
include: [/\.vue($|\?)/, /\.(md|markdown)($|\?)/],
356-
},
357-
plugins: [
358-
Markdown({
359-
include: [/\.(md|markdown)($|\?)/],
360-
wrapperComponent: 'BlogPostWrapper',
361-
wrapperClasses: 'text-fg-muted leading-relaxed',
362-
async markdownItSetup(md) {
363-
const shiki = await import('@shikijs/markdown-it')
364-
md.use(
365-
await shiki.default({
366-
themes: {
367-
dark: 'github-dark',
368-
light: 'github-light',
369-
},
370-
}),
371-
)
372-
},
373-
// important for types compatibility
374-
}) as Exclude<ViteOptions['plugins'], undefined>[number],
375-
],
376-
377351
optimizeDeps: {
378352
include: [
379353
'@vueuse/core',

0 commit comments

Comments
 (0)