@@ -26,6 +26,7 @@ import crypto from 'node:crypto'
2626 */
2727async function fetchBlueskyAvatars (
2828 imagesDir : string ,
29+ publicAvatarBasePath : string ,
2930 handles : string [ ] ,
3031) : Promise < Map < string , string > > {
3132 const avatarMap = new Map < string , string > ( )
@@ -53,22 +54,20 @@ async function fetchBlueskyAvatars(
5354 const hash = crypto . createHash ( 'sha256' ) . update ( profile . avatar ) . digest ( 'hex' )
5455 const dest = join ( imagesDir , `${ hash } .jpg` )
5556
56- console . log ( 'fetch bluesky avatars 1' , dest )
5757 if ( ! existsSync ( dest ) ) {
5858 const res = await fetch ( profile . avatar )
59- console . log ( 'fetch bluesky avatars 2' , profile . avatar )
6059 await writeFile ( join ( imagesDir , `${ hash } .jpg` ) , res . body ! )
61- console . log ( 'fetch bluesky avatars 3' , join ( imagesDir , `${ hash } .jpg` ) )
6260 }
6361
64- console . log ( 'fetch bluesky avatars 4' , `/blog/avatar/${ hash } .jpg` )
65- avatarMap . set ( profile . handle , `/blog/avatar/${ hash } .jpg` )
62+ avatarMap . set ( profile . handle , join ( publicAvatarBasePath , `${ hash } .jpg` ) )
6663 }
6764 }
6865 } catch ( error ) {
6966 console . warn ( `[blog] Failed to fetch Bluesky avatars:` , error )
7067 }
7168
69+ console . log ( 'avatarMap' , avatarMap ) ;
70+
7271 return avatarMap
7372}
7473
@@ -88,7 +87,11 @@ function resolveAuthors(authors: Author[], avatarMap: Map<string, string>): Reso
8887 * Returns all posts (including drafts) sorted by date descending.
8988 * Resolves Bluesky avatars at build time.
9089 */
91- async function loadBlogPosts ( blogDir : string , imagesDir : string ) : Promise < BlogPostFrontmatter [ ] > {
90+ async function loadBlogPosts (
91+ blogDir : string ,
92+ imagesDir : string ,
93+ publicAvatarBasePath : string ,
94+ ) : Promise < BlogPostFrontmatter [ ] > {
9295 const files : string [ ] = globSync ( join ( blogDir , '*.md' ) )
9396
9497 // First pass: extract raw frontmatter and collect all Bluesky handles
@@ -122,8 +125,7 @@ async function loadBlogPosts(blogDir: string, imagesDir: string): Promise<BlogPo
122125 }
123126
124127 // Batch-fetch all Bluesky avatars in a single request
125- const avatarMap = await fetchBlueskyAvatars ( imagesDir , [ ...allHandles ] )
126- console . log ( 'load blog posts 1' , avatarMap )
128+ const avatarMap = await fetchBlueskyAvatars ( imagesDir , publicAvatarBasePath , [ ...allHandles ] )
127129
128130 // Second pass: validate with raw schema, then enrich authors with avatars
129131 const posts : BlogPostFrontmatter [ ] = [ ]
@@ -152,6 +154,7 @@ export default defineNuxtModule({
152154 const resolver = createResolver ( import . meta. url )
153155 const blogDir = resolver . resolve ( '../app/pages/blog' )
154156 const blogImagesDir = resolver . resolve ( '../public/blog/avatar' )
157+ const publicAvatarBasePath = join ( nuxt . options . app . baseURL || '/' , 'blog/avatar' )
155158
156159 nuxt . options . extensions . push ( '.md' )
157160 nuxt . options . vite . vue = defu ( nuxt . options . vite . vue , {
@@ -182,7 +185,7 @@ export default defineNuxtModule({
182185 )
183186
184187 // Load posts once with resolved Bluesky avatars (shared across template + route rules)
185- const allPosts = await loadBlogPosts ( blogDir , blogImagesDir )
188+ const allPosts = await loadBlogPosts ( blogDir , blogImagesDir , publicAvatarBasePath )
186189
187190 // Expose frontmatter for the `/blog` listing page.
188191 const showDrafts = nuxt . options . dev || ! isProduction
0 commit comments