[Glitch] Fix hashtag bar sometimes including tags that appear in the post's body
Port f0862bcf98
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
a81ed84453
commit
fe8d9f6221
|
@ -15,11 +15,11 @@ const VISIBLE_HASHTAGS = 7;
|
||||||
export const HashtagBar = ({ hashtags, text }) => {
|
export const HashtagBar = ({ hashtags, text }) => {
|
||||||
const renderedHashtags = useMemo(() => {
|
const renderedHashtags = useMemo(() => {
|
||||||
const body = domParser.parseFromString(text, 'text/html').documentElement;
|
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]);
|
}, [text]);
|
||||||
|
|
||||||
const invisibleHashtags = useMemo(() => (
|
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]);
|
), [hashtags, renderedHashtags]);
|
||||||
|
|
||||||
const [expanded, setExpanded] = useState(false);
|
const [expanded, setExpanded] = useState(false);
|
||||||
|
|
Loading…
Reference in New Issue