Fix a few bugs with entity/link parsing

This commit is contained in:
Jonathan Staab 2023-04-12 14:32:41 -05:00
parent c30b0d069e
commit 4b30c890a2
2 changed files with 9 additions and 6 deletions

View File

@ -118,11 +118,11 @@
<br />
{/each}
{:else if type === "link"}
<Anchor external href={value} class="ml-1">
<Anchor external href={value}>
{value.replace(/https?:\/\/(www\.)?/, "")}
</Anchor>
{:else if type.startsWith("nostr:")}
<Anchor href={"/" + value.entity} class="ml-1">
<Anchor href={"/" + value.entity}>
{#if value.pubkey}
{displayPerson(getPersonWithFallback(value.pubkey))}
{:else}
@ -132,6 +132,7 @@
{:else}
{value}
{/if}
{' '}
{/each}
</p>
{#if showMedia && links.length > 0}

View File

@ -202,11 +202,11 @@ export const parseContent = ({content, tags = []}) => {
if (bech32) {
try {
const entity = bech32[0].replace("nostr:", "")
const entity = bech32.replace("nostr:", "")
const {type, data} = nip19.decode(entity) as {type: string; data: object}
const value = type === "note" ? {id: data} : data
return [`nostr:${type}`, bech32[0], {...value, entity}]
return [`nostr:${type}`, bech32, {...value, entity}]
} catch (e) {
console.log(e)
// pass
@ -216,7 +216,9 @@ export const parseContent = ({content, tags = []}) => {
const parseUrl = () => {
const raw = first(
text.match(/^((http|ws)s?:\/\/)?[-a-z0-9:%_\+~#=\.]+\.[a-z]{1,6}[-a-z0-9:%_\+~#\?&\/=;\.]*/gi)
text.match(
/^((http|ws)s?:\/\/)?[-a-z0-9:%_\+~#=\.\*]+\.[a-z]{1,6}[-a-z0-9:%_\+~#\?&\/=;\.\*]*/gi
)
)
// Skip url if it's just the end of a filepath
@ -269,7 +271,7 @@ export const parseContent = ({content, tags = []}) => {
}
if (buffer) {
result.push({type: 'text', value: buffer})
result.push({type: "text", value: buffer})
}
return result