blog post and other fixes/additions #124

Merged
freakoverse merged 55 commits from staging into master 2024-11-14 18:26:41 +00:00
2 changed files with 19 additions and 3 deletions
Showing only changes of commit 169ab37304 - Show all commits

View File

@ -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<BlogDetails> => ({
@ -17,7 +17,7 @@ export const extractBlogDetails = (event: NDKEvent): Partial<BlogDetails> => ({
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 = (

View File

@ -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
}