()
| 155 | name: 'blog', |
| 156 | }, |
| 157 | async setup() { |
| 158 | const nuxt = useNuxt() |
| 159 | const resolver = createResolver(import.meta.url) |
| 160 | const blogDir = resolver.resolve('../app/pages/blog') |
| 161 | const blogImagesDir = resolver.resolve('../public/blog/avatar') |
| 162 | const resolveAvatars = !nuxt.options._prepare |
| 163 | |
| 164 | nuxt.options.extensions.push('.md') |
| 165 | nuxt.options.vite.vue = defu(nuxt.options.vite.vue, { |
| 166 | include: [/\.vue($|\?)/, /\.(md|markdown)($|\?)/], |
| 167 | }) |
| 168 | |
| 169 | if (resolveAvatars && !existsSync(blogImagesDir)) { |
| 170 | await mkdir(blogImagesDir, { recursive: true }) |
| 171 | } |
| 172 | |
| 173 | addVitePlugin(() => |
| 174 | Markdown({ |
| 175 | include: [/\.(md|markdown)($|\?)/], |
| 176 | wrapperComponent: 'BlogPostWrapper', |
| 177 | wrapperClasses: 'text-fg-muted leading-relaxed', |
| 178 | async markdownSetup(md) { |
| 179 | md.use( |
| 180 | await shiki({ |
| 181 | themes: { |
| 182 | dark: 'github-dark', |
| 183 | light: 'github-light', |
| 184 | }, |
| 185 | }), |
| 186 | ) |
| 187 | md.use(MarkdownItAnchor as any) |
| 188 | }, |
| 189 | }), |
| 190 | ) |
| 191 | |
| 192 | // Load posts once with resolved Bluesky avatars (shared across template + route rules) |
| 193 | const allPosts = await loadBlogPosts(blogDir, { |
| 194 | imagesDir: blogImagesDir, |
| 195 | resolveAvatars, |
| 196 | }) |
| 197 | |
| 198 | // Expose frontmatter for the `/blog` listing page. |
| 199 | const showDrafts = nuxt.options.dev || !isProduction |
| 200 | addTemplate({ |
| 201 | filename: 'blog/posts.ts', |
| 202 | write: true, |
| 203 | getContents: () => { |
| 204 | const posts = allPosts.filter(p => showDrafts || !p.draft) |
| 205 | return [ |
| 206 | `import type { BlogPostFrontmatter } from '#shared/schemas/blog'`, |
| 207 | ``, |
| 208 | `export const posts: BlogPostFrontmatter[] = ${JSON.stringify(posts, null, 2)}`, |
| 209 | ].join('\n') |
| 210 | }, |
| 211 | }) |
| 212 | |
| 213 | nuxt.options.alias['#blog/posts'] = join(nuxt.options.buildDir, 'blog/posts') |
| 214 |
nothing calls this directly
no test coverage detected