1
0
Fork 0
forked from fedi/mastodon

Fix hashtag bar sometimes including tags that appear in the post's body (#26506)

This commit is contained in:
Claire 2023-08-16 11:47:59 +02:00 committed by GitHub
parent 26eaf058e2
commit f0862bcf98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,11 +15,11 @@ const VISIBLE_HASHTAGS = 7;
export const HashtagBar = ({ hashtags, text }) => {
const renderedHashtags = useMemo(() => {
const body = domParser.parseFromString(text, 'text/html').documentElement;
return [].map.call(body.querySelectorAll('[rel=tag]'), node => node.textContent.toLowerCase());
return [].filter.call(body.querySelectorAll('a[href]'), link => link.textContent[0] === '#' || (link.previousSibling?.textContent?.[link.previousSibling.textContent.length - 1] === '#')).map(node => node.textContent.toLowerCase());
}, [text]);
const invisibleHashtags = useMemo(() => (
hashtags.filter(hashtag => !renderedHashtags.some(textContent => textContent === `#${hashtag.get('name')}` || textContent === hashtag.get('name')))
hashtags.filter(hashtag => !renderedHashtags.some(textContent => textContent === `#${hashtag.get('name').toLowerCase()}` || textContent === hashtag.get('name').toLowerCase()))
), [hashtags, renderedHashtags]);
const [expanded, setExpanded] = useState(false);