Skip to content

Commit 2fc09b3

Browse files
authored
Merge branch 'main' into main
2 parents 6b5ec24 + f5bb3ed commit 2fc09b3

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

modules/blog.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,14 @@ function resolveAuthors(authors: Author[], avatarMap: Map<string, string>): Reso
8787
* Returns all posts (including drafts) sorted by date descending.
8888
* Resolves Bluesky avatars at build time.
8989
*/
90-
async function loadBlogPosts(blogDir: string, imagesDir: string): Promise<BlogPostFrontmatter[]> {
90+
async function loadBlogPosts(
91+
blogDir: string,
92+
options: {
93+
imagesDir: string
94+
resolveAvatars: boolean
95+
},
96+
): Promise<BlogPostFrontmatter[]> {
97+
const { imagesDir, resolveAvatars } = options
9198
const files = await Array.fromAsync(glob(join(blogDir, '**/*.md').replace(/\\/g, '/')))
9299

93100
// First pass: extract raw frontmatter and collect all Bluesky handles
@@ -120,8 +127,10 @@ async function loadBlogPosts(blogDir: string, imagesDir: string): Promise<BlogPo
120127
rawPosts.push({ frontmatter })
121128
}
122129

123-
// Batch-fetch all Bluesky avatars in a single request
124-
const avatarMap = await fetchBlueskyAvatars(imagesDir, [...allHandles])
130+
// Batch-fetch all Bluesky avatars in a single request when avatar resolution is enabled.
131+
const avatarMap = resolveAvatars
132+
? await fetchBlueskyAvatars(imagesDir, [...allHandles])
133+
: new Map<string, string>()
125134

126135
// Second pass: validate with raw schema, then enrich authors with avatars
127136
const posts: BlogPostFrontmatter[] = []
@@ -150,13 +159,14 @@ export default defineNuxtModule({
150159
const resolver = createResolver(import.meta.url)
151160
const blogDir = resolver.resolve('../app/pages/blog')
152161
const blogImagesDir = resolver.resolve('../public/blog/avatar')
162+
const resolveAvatars = !nuxt.options._prepare
153163

154164
nuxt.options.extensions.push('.md')
155165
nuxt.options.vite.vue = defu(nuxt.options.vite.vue, {
156166
include: [/\.vue($|\?)/, /\.(md|markdown)($|\?)/],
157167
})
158168

159-
if (!existsSync(blogImagesDir)) {
169+
if (resolveAvatars && !existsSync(blogImagesDir)) {
160170
await mkdir(blogImagesDir, { recursive: true })
161171
}
162172

@@ -180,7 +190,10 @@ export default defineNuxtModule({
180190
)
181191

182192
// Load posts once with resolved Bluesky avatars (shared across template + route rules)
183-
const allPosts = await loadBlogPosts(blogDir, blogImagesDir)
193+
const allPosts = await loadBlogPosts(blogDir, {
194+
imagesDir: blogImagesDir,
195+
resolveAvatars,
196+
})
184197

185198
// Expose frontmatter for the `/blog` listing page.
186199
const showDrafts = nuxt.options.dev || !isProduction

nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ export default defineNuxtConfig({
192192
'/translation-status': { prerender: true },
193193
'/recharging': { prerender: true },
194194
'/pds': { isr: 86400 }, // revalidate daily
195-
// proxy for insights
196195
'/blog/**': { prerender: true },
196+
// proxy for insights
197197
'/_v/script.js': {
198198
proxy: 'https://npmx.dev/_vercel/insights/script.js',
199199
},

0 commit comments

Comments
 (0)