Skip to content

Commit 8381129

Browse files
committed
chore: check baseurl on images generation time
1 parent 88729be commit 8381129

3 files changed

Lines changed: 13 additions & 28 deletions

File tree

app/components/OgImage/BlogPost.vue

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<script setup lang="ts">
22
import type { ResolvedAuthor } from '#shared/schemas/blog'
33
4-
console.log('blog post 1')
5-
64
const props = withDefaults(
75
defineProps<{
86
title: string
@@ -16,10 +14,8 @@ const props = withDefaults(
1614
primaryColor: '#60a5fa',
1715
},
1816
)
19-
console.log('blog post 2', props)
2017
2118
const formattedDate = computed(() => {
22-
console.log('blog post 3', props.date)
2319
if (!props.date) return ''
2420
try {
2521
return new Date(props.date).toLocaleDateString('en-US', {
@@ -28,7 +24,6 @@ const formattedDate = computed(() => {
2824
day: 'numeric',
2925
})
3026
} catch {
31-
console.log('blog post 4', props.date)
3227
return props.date
3328
}
3429
})
@@ -44,22 +39,16 @@ const getInitials = (name: string) =>
4439
.slice(0, 2)
4540
4641
const visibleAuthors = computed(() => {
47-
console.log('blog post 5')
48-
props.authors.map(author => {
49-
console.log('blog post 5', author.avatar, author.name, typeof author.avatar, typeof author.name)
50-
})
5142
if (props.authors.length <= 3) return props.authors
5243
return props.authors.slice(0, MAX_VISIBLE_AUTHORS)
5344
})
5445
5546
const extraCount = computed(() => {
56-
console.log('blog post 6', props.authors)
5747
if (props.authors.length <= 3) return 0
5848
return props.authors.length - MAX_VISIBLE_AUTHORS
5949
})
6050
6151
const formattedAuthorNames = computed(() => {
62-
console.log('blog post 7', props.authors)
6352
const allNames = props.authors.map(a => a.name)
6453
if (allNames.length === 0) return ''
6554
if (allNames.length === 1) return allNames[0]
@@ -119,7 +108,7 @@ const formattedAuthorNames = computed(() => {
119108
>
120109
<img
121110
v-if="author.avatar"
122-
:src="`${useRuntimeConfig().app.baseURL}${author.avatar.replace(/^\//, '')}`"
111+
:src="author.avatar"
123112
:alt="author.name"
124113
class="w-full h-full object-cover"
125114
/>

modules/blog.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import crypto from 'node:crypto'
2626
*/
2727
async 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

server/api/atproto/bluesky-author-profiles.get.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ import * as app from '#shared/types/lexicons/app'
77

88
export default defineCachedEventHandler(
99
async event => {
10-
console.log('bluesky author profiles 1')
1110
const query = getQuery(event)
1211
const authorsParam = query.authors
13-
console.log('bluesky author profiles 2', authorsParam)
1412

1513
if (!authorsParam || typeof authorsParam !== 'string') {
16-
console.log('bluesky author profiles 3')
1714
throw createError({
1815
statusCode: 400,
1916
statusMessage: 'authors query parameter is required (JSON array)',
@@ -25,7 +22,6 @@ export default defineCachedEventHandler(
2522
const parsed = JSON.parse(authorsParam)
2623
authors = v.parse(v.array(AuthorSchema), parsed)
2724
} catch (error) {
28-
console.log('bluesky author profiles 4', error)
2925
if (error instanceof v.ValiError) {
3026
throw createError({
3127
statusCode: 400,
@@ -37,14 +33,12 @@ export default defineCachedEventHandler(
3733
statusMessage: 'authors must be valid JSON',
3834
})
3935
}
40-
console.log('bluesky author profiles 5', authors)
4136

4237
if (!Array.isArray(authors) || authors.length === 0) {
4338
return { authors: [] }
4439
}
4540

4641
const handles = authors.map(a => a.blueskyHandle).filter(v => v != null)
47-
console.log('bluesky author profiles 6', handles)
4842

4943
if (handles.length === 0) {
5044
return {
@@ -73,7 +67,6 @@ export default defineCachedEventHandler(
7367
: null,
7468
}),
7569
)
76-
console.log('bluesky author profiles 7', resolvedAuthors)
7770

7871
return { authors: resolvedAuthors }
7972
},

0 commit comments

Comments
 (0)