« get me outta code hell

external-links: quick spec tweaks - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-11-24 14:14:27 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-11-24 14:18:35 -0400
commitad1ae12ab182dd50cf3ca6ec653d371d77b5fabb (patch)
tree57487c30a3ed5c6618549e8fc402727f10100a43 /src
parent4507d7a8e42d3f7fd8c6cf4b1d9f270370078b08 (diff)
external-links: quick spec tweaks
Diffstat (limited to 'src')
-rw-r--r--src/util/external-links.js77
1 files changed, 55 insertions, 22 deletions
diff --git a/src/util/external-links.js b/src/util/external-links.js
index dee65cc5..0a4a77cf 100644
--- a/src/util/external-links.js
+++ b/src/util/external-links.js
@@ -4,6 +4,7 @@ import {
   is,
   isObject,
   isStringNonEmpty,
+  oneOf,
   optional,
   validateArrayItems,
   validateInstanceOf,
@@ -60,7 +61,10 @@ export const isExternalLinkSpec =
         query: optional(isRegExp),
         queries: optional(validateArrayItems(isRegExp)),
 
-        context: optional(isExternalLinkContext),
+        context:
+          optional(oneOf(
+            isExternalLinkContext,
+            validateArrayItems(isExternalLinkContext))),
       }),
 
       platform: isStringNonEmpty,
@@ -132,6 +136,21 @@ export const externalLinkSpec = [
 
   {
     match: {
+      domain: 'patreon.com',
+      context: 'artist',
+    },
+
+    platform: 'patreon',
+
+    normal: 'handle',
+    compact: 'handle',
+    icon: 'globe',
+
+    handle: /([^/]*)\/?$/,
+  },
+
+  {
+    match: {
       context: 'artist',
       domain: 'youtube.com',
     },
@@ -210,7 +229,7 @@ export const externalLinkSpec = [
   // Generic domains, sorted alphabetically (by string)
 
   {
-    match: {domains: ['bc.s3m.us', 'music.solatrux.com']},
+    match: {domains: ['bc.s3m.us', 'music.solatrus.com']},
 
     platform: 'bandcamp',
 
@@ -220,7 +239,7 @@ export const externalLinkSpec = [
   },
 
   {
-    match: {domain: 'bandcamp.com'},
+    match: {domain: '.bandcamp.com'},
 
     platform: 'bandcamp',
 
@@ -232,54 +251,57 @@ export const externalLinkSpec = [
 
   {
     match: {domain: 'deviantart.com'},
-
     platform: 'deviantart',
-
     icon: 'deviantart',
   },
 
   {
-    match: {domain: 'instagram.com'},
-
-    platform: 'instagram',
-
-    icon: 'instagram',
-  },
-
-  {
     match: {domain: 'homestuck.com'},
-
     platform: 'homestuck',
-
     icon: 'globe',
   },
 
   {
     match: {domain: 'hsmusic.wiki'},
-
     platform: 'local',
-
     icon: 'globe',
   },
 
   {
+    match: {domain: 'instagram.com'},
+    platform: 'instagram',
+    icon: 'instagram',
+  },
+
+  {
     match: {domains: ['types.pl']},
 
     platform: 'mastodon',
 
+    normal: 'domain',
     compact: 'domain',
     icon: 'mastodon',
   },
 
   {
     match: {domain: 'newgrounds.com'},
-
     platform: 'newgrounds',
-
     icon: 'newgrounds',
   },
 
   {
+    match: {domain: 'patreon.com'},
+    platform: 'patreon',
+    icon: 'globe',
+  },
+
+  {
+    match: {domain: 'poetryfoundation.org'},
+    platform: 'poetryFoundation',
+    icon: 'globe',
+  },
+
+  {
     match: {domain: 'soundcloud.com'},
 
     platform: 'soundcloud',
@@ -291,7 +313,13 @@ export const externalLinkSpec = [
   },
 
   {
-    match: {domain: 'tumblr.com'},
+    match: {domain: 'spotify.com'},
+    platform: 'spotify',
+    icon: 'globe',
+  },
+
+  {
+    match: {domain: '.tumblr.com'},
 
     platform: 'tumblr',
 
@@ -316,10 +344,14 @@ export const externalLinkSpec = [
   },
 
   {
-    match: {domains: ['youtube.com', 'youtu.be']},
+    match: {domain: 'wikipedia.org'},
+    platform: 'wikipedia',
+    icon: 'misc',
+  },
 
+  {
+    match: {domains: ['youtube.com', 'youtu.be']},
     platform: 'youtube',
-
     icon: 'youtube',
   },
 ];
@@ -355,6 +387,7 @@ export function getMatchingDescriptorsForExternalLink(url, descriptors, {
         return false;
       })
       .filter(({match}) => {
+        if (Array.isArray(match.context)) return match.context.includes(context);
         if (match.context) return context === match.context;
         return true;
       })