aboutsummaryrefslogtreecommitdiff
path: root/src/services/matcher/matcher.service.js
blob: 54f02d312502d616fbc6f664f87584d6ef27fc5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
export const mentionMatchesUrl = (attention, url) => {
  if (url === attention.statusnet_profile_url) {
    return true
  }
  const [namepart, instancepart] = attention.screen_name.split('@')
  const matchstring = new RegExp('://' + instancepart + '/.*' + namepart + '$', 'g')

  return !!url.match(matchstring)
}

/**
 * Extract tag name from pleroma or mastodon url.
 * i.e https://bikeshed.party/tag/photo or https://quey.org/tags/sky
 * @param {string} url
 */
export const extractTagFromUrl = (url) => {
  const decoded = decodeURI(url)
  // https://git.pleroma.social/pleroma/elixir-libraries/linkify/-/blob/master/lib/linkify/parser.ex
  // https://www.pcre.org/original/doc/html/pcrepattern.html
  const regex = /tag[s]*\/([\p{L}\p{N}_]*[\p{Alphabetic}_·\u{200c}][\p{L}\p{N}_·\p{M}\u{200c}]*)$/ug
  const result = regex.exec(decoded)
  if (!result) {
    return false
  }
  return result[1]
}