verified_badge.tsx 826 B

1234567891011121314151617181920212223242526272829
  1. import CheckIcon from '@/material-icons/400-24px/check.svg?react';
  2. import { Icon } from './icon';
  3. const domParser = new DOMParser();
  4. const stripRelMe = (html: string) => {
  5. const document = domParser.parseFromString(html, 'text/html').documentElement;
  6. document.querySelectorAll<HTMLAnchorElement>('a[rel]').forEach((link) => {
  7. link.rel = link.rel
  8. .split(' ')
  9. .filter((x: string) => x !== 'me')
  10. .join(' ');
  11. });
  12. const body = document.querySelector('body');
  13. return body ? { __html: body.innerHTML } : undefined;
  14. };
  15. interface Props {
  16. link: string;
  17. }
  18. export const VerifiedBadge: React.FC<Props> = ({ link }) => (
  19. <span className='verified-badge'>
  20. <Icon id='check' icon={CheckIcon} className='verified-badge__mark' />
  21. <span dangerouslySetInnerHTML={stripRelMe(link)} />
  22. </span>
  23. );