Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions modules/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ function resolveAuthors(authors: Author[], avatarMap: Map<string, string>): Reso
* Returns all posts (including drafts) sorted by date descending.
* Resolves Bluesky avatars at build time.
*/
async function loadBlogPosts(blogDir: string, imagesDir: string): Promise<BlogPostFrontmatter[]> {
async function loadBlogPosts(
blogDir: string,
options: {
imagesDir: string
resolveAvatars: boolean
},
): Promise<BlogPostFrontmatter[]> {
const { imagesDir, resolveAvatars } = options
const files = await Array.fromAsync(glob(join(blogDir, '**/*.md').replace(/\\/g, '/')))

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

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

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

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

if (!existsSync(blogImagesDir)) {
if (resolveAvatars && !existsSync(blogImagesDir)) {
await mkdir(blogImagesDir, { recursive: true })
}

Expand All @@ -180,7 +190,10 @@ export default defineNuxtModule({
)

// Load posts once with resolved Bluesky avatars (shared across template + route rules)
const allPosts = await loadBlogPosts(blogDir, blogImagesDir)
const allPosts = await loadBlogPosts(blogDir, {
imagesDir: blogImagesDir,
resolveAvatars,
})

// Expose frontmatter for the `/blog` listing page.
const showDrafts = nuxt.options.dev || !isProduction
Expand Down
Loading