diff --git a/src/utils/blog.ts b/src/utils/blog.ts index 0de30db..df11b63 100644 --- a/src/utils/blog.ts +++ b/src/utils/blog.ts @@ -1,6 +1,6 @@ import { NDKEvent } from '@nostr-dev-kit/ndk' import { BlogCardDetails, BlogDetails } from 'types' -import { getFirstTagValue, getFirstTagValueAsInt, getTagValue } from './nostr' +import { getFirstTagValue, getFirstTagValueAsInt, getTagValues } from './nostr' import { kinds, nip19 } from 'nostr-tools' export const extractBlogDetails = (event: NDKEvent): Partial => ({ @@ -17,7 +17,7 @@ export const extractBlogDetails = (event: NDKEvent): Partial => ({ rTag: getFirstTagValue(event, 'r') || 'N/A', dTag: getFirstTagValue(event, 'd'), aTag: getFirstTagValue(event, 'a'), - tTags: getTagValue(event, 't') || [] + tTags: getTagValues(event, 't') || [] }) export const extractBlogCardDetails = ( diff --git a/src/utils/nostr.ts b/src/utils/nostr.ts index b1fd0e1..772c37b 100644 --- a/src/utils/nostr.ts +++ b/src/utils/nostr.ts @@ -65,11 +65,27 @@ export const getTagValue = ( return null } +export const getTagValues = ( + event: Event | NDKEvent, + tagIdentifier: string +): string[] | null => { + // Find the tag in the event's tags array where the first element matches the tagIdentifier. + const tags = event.tags.filter((item) => item[0] === tagIdentifier) + + // If a matching tag is found, return the rest of the elements in the tag (i.e., the values). + if (tags && tags.length) { + return tags.map((item) => item[1]) // Returning only the values + } + + // Return null if no matching tag is found. + return null +} + export const getFirstTagValue = ( event: Event | NDKEvent, tagIdentifier: string ) => { - const tags = getTagValue(event, tagIdentifier) + const tags = getTagValues(event, tagIdentifier) return tags && tags.length ? tags[0] : undefined }