logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

matcher.service.js (903B)


  1. export const mentionMatchesUrl = (attention, url) => {
  2. if (url === attention.statusnet_profile_url) {
  3. return true
  4. }
  5. const [namepart, instancepart] = attention.screen_name.split('@')
  6. const matchstring = new RegExp('://' + instancepart + '/.*' + namepart + '$', 'g')
  7. return !!url.match(matchstring)
  8. }
  9. /**
  10. * Extract tag name from pleroma or mastodon url.
  11. * i.e https://bikeshed.party/tag/photo or https://quey.org/tags/sky
  12. * @param {string} url
  13. */
  14. export const extractTagFromUrl = (url) => {
  15. const decoded = decodeURI(url)
  16. // https://git.pleroma.social/pleroma/elixir-libraries/linkify/-/blob/master/lib/linkify/parser.ex
  17. // https://www.pcre.org/original/doc/html/pcrepattern.html
  18. const regex = /tag[s]*\/([\p{L}\p{N}_]*[\p{Alphabetic}_·\u{200c}][\p{L}\p{N}_·\p{M}\u{200c}]*)$/ug
  19. const result = regex.exec(decoded)
  20. if (!result) {
  21. return false
  22. }
  23. return result[1]
  24. }