Skip to content

Commit 96d6a34

Browse files
committed
chore: check orig avatar usage
1 parent ba2f1f9 commit 96d6a34

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

app/components/OgImage/BlogPost.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const formattedAuthorNames = computed(() => {
108108
>
109109
<img
110110
v-if="author.avatar"
111-
:src="author.avatar"
111+
:src="author.origAvatar ?? author.avatar"
112112
:alt="author.name"
113113
class="w-full h-full object-cover"
114114
/>

modules/blog.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import crypto from 'node:crypto'
2727
async function fetchBlueskyAvatars(
2828
imagesDir: string,
2929
handles: string[],
30-
): Promise<Map<string, string>> {
31-
const avatarMap = new Map<string, string>()
30+
): Promise<Map<string, { localPath: string; remotePath: string }>> {
31+
const avatarMap = new Map<string, { localPath: string; remotePath: string }>()
3232
if (handles.length === 0) return avatarMap
3333

3434
try {
@@ -58,7 +58,10 @@ async function fetchBlueskyAvatars(
5858
await writeFile(join(imagesDir, `${hash}.jpg`), res.body!)
5959
}
6060

61-
avatarMap.set(profile.handle, `/blog/avatar/${hash}.jpg`)
61+
avatarMap.set(profile.handle, {
62+
localPath: `/blog/avatar/${hash}.jpg`,
63+
remotePath: profile.avatar,
64+
})
6265
}
6366
}
6467
} catch (error) {
@@ -71,10 +74,16 @@ async function fetchBlueskyAvatars(
7174
/**
7275
* Resolves authors with their Bluesky avatars and profile URLs.
7376
*/
74-
function resolveAuthors(authors: Author[], avatarMap: Map<string, string>): ResolvedAuthor[] {
77+
function resolveAuthors(
78+
authors: Author[],
79+
avatarMap: Map<string, { localPath: string; remotePath: string }>,
80+
): ResolvedAuthor[] {
7581
return authors.map(author => ({
7682
...author,
77-
avatar: author.blueskyHandle ? (avatarMap.get(author.blueskyHandle) ?? null) : null,
83+
avatar: author.blueskyHandle ? (avatarMap.get(author.blueskyHandle)?.localPath ?? null) : null,
84+
origAvatar: author.blueskyHandle
85+
? (avatarMap.get(author.blueskyHandle)?.remotePath ?? null)
86+
: null,
7887
profileUrl: author.blueskyHandle ? `https://bsky.app/profile/${author.blueskyHandle}` : null,
7988
}))
8089
}
@@ -195,7 +204,6 @@ export default defineNuxtModule({
195204
})
196205

197206
nuxt.options.alias['#blog/posts'] = join(nuxt.options.buildDir, 'blog/posts')
198-
nuxt.options.alias['/blog/avatar'] = join(nuxt.options.dir.public, 'blog/avatar')
199207

200208
// Add X-Robots-Tag header for draft posts to prevent indexing
201209
for (const post of allPosts) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export default defineCachedEventHandler(
6262
const resolvedAuthors: ResolvedAuthor[] = authors.map(author =>
6363
Object.assign(author, {
6464
avatar: author.blueskyHandle ? avatarMap.get(author.blueskyHandle) || null : null,
65+
origAvatar: author.blueskyHandle ? avatarMap.get(author.blueskyHandle) || null : null,
6566
profileUrl: author.blueskyHandle
6667
? `https://bsky.app/profile/${author.blueskyHandle}`
6768
: null,

shared/schemas/blog.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const ResolvedAuthorSchema = object({
3131
),
3232
),
3333
avatar: nullable(string()),
34+
origAvatar: nullable(string()),
3435
profileUrl: nullable(string()),
3536
})
3637

0 commit comments

Comments
 (0)