From fe8d9f62218528fe5384406c825edd562a93ca3f Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 16 Aug 2023 11:47:59 +0200 Subject: [PATCH] [Glitch] Fix hashtag bar sometimes including tags that appear in the post's body Port f0862bcf984d994b9f0b0bbea82431e5a1812351 Signed-off-by: Claire --- app/javascript/flavours/glitch/components/hashtag_bar.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/javascript/flavours/glitch/components/hashtag_bar.jsx b/app/javascript/flavours/glitch/components/hashtag_bar.jsx index 6a39005e16..3ad6362551 100644 --- a/app/javascript/flavours/glitch/components/hashtag_bar.jsx +++ b/app/javascript/flavours/glitch/components/hashtag_bar.jsx @@ -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);