Skip to content

Commit

Permalink
chore(regex config): organize regex config and use primitive types in…
Browse files Browse the repository at this point in the history
… interface
  • Loading branch information
josephmcg committed Dec 27, 2021
1 parent a9d0f57 commit 09a2ccb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ export default Vue.extend({
*/
parseEmbeddableVideoContentFromText(messagetext: string) {
// parse incoming text for links
const arrayOfLinks = messagetext.match(
/(\b(https?):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gi,
)
const arrayOfLinks = messagetext.match(this.$Config.regex.link)
// this.settings.embeddedLinks is the global set in the networks panel. Without this, it just shows up as a normal link
if (arrayOfLinks && this.settings.embeddedLinks === true) {
Expand All @@ -44,8 +42,8 @@ export default Vue.extend({
Parsing Youtube links, if we need to modify the regex do it in here.
*/
if (
link.match(/^https?:\/\/([a-z0-9-]+[.])*youtube.com?/g) ||
link.match(/^https?:\/\/([a-z0-9-]+[.])*youtu.be?/g)
link.match(this.$Config.regex.youtube) ||
link.match(this.$Config.regex.youtubeShort)
) {
let youtubeOutSource: string = ''
if (link.includes('youtube')) {
Expand All @@ -68,7 +66,7 @@ export default Vue.extend({
/*
Parsing Vimeo links, if we need to modify the regex do it in here. Right now it parses regular links and links to videos that are in collections
*/
if (link.match(/^https?:\/\/([a-z0-9-]+[.])*vimeo.com?/g)) {
if (link.match(this.$Config.regex.vimeo)) {
// vimeo makes their video id potentially available in several different places in the url
const videoID: string = link
.split('/')
Expand All @@ -83,7 +81,7 @@ export default Vue.extend({
}
if (
link.match(/^https?:\/\/([a-z0-9-]+[.])*facebook.com?/g) &&
link.match(this.$Config.regex.facebook) &&
link.includes('videos')
) {
// hacky workaround to make facebook embed more mobile responsive.
Expand All @@ -102,7 +100,7 @@ export default Vue.extend({
}
}
if (link.match(/^https?:\/\/([a-z0-9-]+[.])twitch[.]tv\/?/g)) {
if (link.match(this.$Config.regex.twitch)) {
let videoId: string = ''
// check to see if it's an individual video
if (link.includes('/videos/')) {
Expand All @@ -126,11 +124,7 @@ export default Vue.extend({
}
}
if (
link.match(
/^https?:\/\/([a-z0-9-]+[.])spotify[.]com\/(playlist|embed)?/g,
)
) {
if (link.match(this.$Config.regex.spotify)) {
// get type and id
// https://open.spotify.com/playlist/46ffmNKBTEakwz0t625bbC?si=e878040ce04c460f => playlist/46ffmNKBTEakwz0t625bbC
// https://open.spotify.com/track/3s2RFp5hU6jEvAmfZrnrAi?si=a9bf555ede314a19 => track/3s2RFp5hU6jEvAmfZrnrAi
Expand Down
8 changes: 8 additions & 0 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ export const Config = {
isEmoji: /\w*[{Emoji_Presentation}\u200d]+/gu,
// Regex to wrap emoji's in spans. Note: Doesn't yet support emoji modifiers
emojiWrapper: /[\p{Emoji_Presentation}\u200d]+/gu,
// check for link
link: /(\b(https?):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gi,
youtube: /^https?:\/\/([a-z0-9-]+[.])*youtube.com?/g,
youtubeShort: /^https?:\/\/([a-z0-9-]+[.])*youtu.be?/g,
vimeo: /^https?:\/\/([a-z0-9-]+[.])*vimeo.com?/g,
facebook: /^https?:\/\/([a-z0-9-]+[.])*facebook.com?/g,
twitch: /^https?:\/\/([a-z0-9-]+[.])twitch[.]tv\/?/g,
spotify: /^https?:\/\/([a-z0-9-]+[.])spotify[.]com\/(playlist|embed)?/g,
},
webrtc: {
constraints: {
Expand Down
6 changes: 3 additions & 3 deletions store/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ export interface EnhancerInfo {
}

export interface EmojiUsage {
code: String
code: string
count: number
content: String
content: string
}

export interface RecentGlyph {
pack: Glyph
url: String
url: string
count: number
}

Expand Down

0 comments on commit 09a2ccb

Please sign in to comment.