Something in the paragraphs from daring fireball feed broke the output, build in a tiny tiny bit more secure parsing

This commit is contained in:
Berry de Vos 2023-10-19 18:15:08 +02:00
parent 22d628a661
commit 99e3795619
3 changed files with 3 additions and 3 deletions

View file

@ -20,7 +20,7 @@ export default ({ content, href, paragraphStyle, blockquoteStyle }: Props) => {
return (
<>
<Text style={elements[0].localName === 'blockquote' ? blockquoteStyle : paragraphStyle}>{elements[0].text}</Text>
<Text style={elements.at(0)?.localName === 'blockquote' ? blockquoteStyle : paragraphStyle}>{elements.at(0)?.text}</Text>
{elements.length > 1 && (
<Text style={paragraphStyle}>
<Link href={href}></Link>

View file

@ -30,7 +30,7 @@ export default ({ content, href }: Props) => {
const paragraphs = element.querySelectorAll('> p')
return (
<Fragment key="blockquote">
<Text style={blockquote}>{paragraphs[0].text ?? ''}</Text>
<Text style={blockquote}>{paragraphs.at(0)?.text ?? ''}</Text>
{blockquoteHasMore && (
<Text style={blockquote}>
<Link style={link} href={href}>

View file

@ -16,5 +16,5 @@ export const parseLinks = (links: ItemLink[]) => {
return `${links[0]}`
}
return hrefByRel(links, 'related') ?? hrefByRel(links, 'alternate') ?? links[0].$.href
return hrefByRel(links, 'related') ?? hrefByRel(links, 'alternate') ?? links.at(0)?.$.href
}