From 784efa68406e363be8b24e22887181f181ef39e9 Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Mon, 21 Aug 2023 01:19:13 +0000 Subject: [PATCH 1/6] Add (wiki) --- index.js | 6 ++++++ test.js | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/index.js b/index.js index e46f9ec..703fb0b 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,7 @@ const releaseArchiveRegex = /^archive[/](.+)([.]zip|[.]tar[.]gz)/; const releaseDownloadRegex = /^releases[/]download[/]([^/]+)[/](.+)/; const dependentsRegex = /^network[/]dependents[/]?$/; const dependenciesRegex = /^network[/]dependencies[/]?$/; +const wikiRegex = /^wiki[/](.+)?$/; function styleRevision(revision) { if (!revision) { @@ -112,6 +113,7 @@ function shortenURL(href, currentUrl = 'https://github.com') { const [, pull, pullPage, pullPartialStart, pullPartialEnd] = repoPath.match(pullRegex) || []; const [, issue] = isRedirection ? repoPath.match(issueRegex) || [] : []; const [, commit] = isRedirection ? repoPath.match(commitRegex) || [] : []; + const [, wiki] = repoPath.match(wikiRegex) || []; const isFileOrDir = revision && [ 'raw', 'tree', @@ -200,6 +202,10 @@ function shortenURL(href, currentUrl = 'https://github.com') { return `${partial}${search}${hash} (compare)`; } + if (wiki) { + return `${repoUrl} (wiki) ${decodeURIComponent((wiki + (hash ? ' (' + hash.substring(1) + ')' : '')).replace(/-/g, ' ')).trim()}` + } + // Shorten URLs that would otherwise be natively shortened if (isRedirection) { if (issue) { diff --git a/test.js b/test.js index 7721384..03b1bfb 100644 --- a/test.js +++ b/test.js @@ -482,4 +482,16 @@ test('GitHub.com URLs', urlMatcherMacro, new Map([ 'https://togithub.com/refined-github/refined-github/commit/e81a9646b448d90c7e02ab41332cab0507dccbbd#commitcomment-60089354', 'refined-github/refined-github@e81a964 (comment)', ], + [ + 'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22#3-it-doesnt-require-options', + 'refined-github/refined-github (wiki) "Can you add this feature?" (3 it doesnt require options)' + ], + [ + 'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22#', + 'refined-github/refined-github (wiki) "Can you add this feature?"' + ], + [ + 'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22', + 'refined-github/refined-github (wiki) "Can you add this feature?"' + ], ])); From 594ec7beeb89366652482b6bb0f159a98aa022c9 Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Mon, 21 Aug 2023 01:33:48 +0000 Subject: [PATCH 2/6] remove unnecessary trim --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 703fb0b..cd72979 100644 --- a/index.js +++ b/index.js @@ -203,7 +203,7 @@ function shortenURL(href, currentUrl = 'https://github.com') { } if (wiki) { - return `${repoUrl} (wiki) ${decodeURIComponent((wiki + (hash ? ' (' + hash.substring(1) + ')' : '')).replace(/-/g, ' ')).trim()}` + return `${repoUrl} (wiki) ${decodeURIComponent((wiki + (hash ? ' (' + hash.substring(1) + ')' : '')).replace(/-/g, ' '))}` } // Shorten URLs that would otherwise be natively shortened From d426341167b85f6c6a7497b2a9f67fa9e2877c00 Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Mon, 21 Aug 2023 01:53:54 +0000 Subject: [PATCH 3/6] remove unnecessary quantifier --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index cd72979..3eb6bd7 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ const releaseArchiveRegex = /^archive[/](.+)([.]zip|[.]tar[.]gz)/; const releaseDownloadRegex = /^releases[/]download[/]([^/]+)[/](.+)/; const dependentsRegex = /^network[/]dependents[/]?$/; const dependenciesRegex = /^network[/]dependencies[/]?$/; -const wikiRegex = /^wiki[/](.+)?$/; +const wikiRegex = /^wiki[/](.+)$/; function styleRevision(revision) { if (!revision) { From 27f11123c9eaf3a4bd3010ae456101f3a53373bc Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Mon, 21 Aug 2023 19:37:21 +0000 Subject: [PATCH 4/6] lint --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 3eb6bd7..487678f 100644 --- a/index.js +++ b/index.js @@ -203,7 +203,7 @@ function shortenURL(href, currentUrl = 'https://github.com') { } if (wiki) { - return `${repoUrl} (wiki) ${decodeURIComponent((wiki + (hash ? ' (' + hash.substring(1) + ')' : '')).replace(/-/g, ' '))}` + return `${repoUrl} (wiki) ${decodeURIComponent((wiki + (hash ? ' (' + hash.substring(1) + ')' : '')).replaceAll(/-/g, ' '))}` } // Shorten URLs that would otherwise be natively shortened From 75a214b987463b51d80087341e5222dcc5716c78 Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Mon, 21 Aug 2023 22:12:17 +0000 Subject: [PATCH 5/6] lint --- index.js | 2 +- test.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index dd9106e..e217300 100644 --- a/index.js +++ b/index.js @@ -203,7 +203,7 @@ function shortenURL(href, currentUrl = 'https://github.com') { } if (wiki) { - return `${repoUrl} (wiki) ${decodeURIComponent((wiki + (hash ? ' (' + hash.substring(1) + ')' : '')).replaceAll(/-/g, ' '))}` + return `${repoUrl} (wiki) ${decodeURIComponent((wiki + (hash ? ' (' + hash.slice(1) + ')' : '')).replaceAll('-', ' '))}`; } // Shorten URLs that would otherwise be natively shortened diff --git a/test.js b/test.js index 03b1bfb..1ca9a95 100644 --- a/test.js +++ b/test.js @@ -484,14 +484,14 @@ test('GitHub.com URLs', urlMatcherMacro, new Map([ ], [ 'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22#3-it-doesnt-require-options', - 'refined-github/refined-github (wiki) "Can you add this feature?" (3 it doesnt require options)' + 'refined-github/refined-github (wiki) "Can you add this feature?" (3 it doesnt require options)', ], [ 'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22#', - 'refined-github/refined-github (wiki) "Can you add this feature?"' + 'refined-github/refined-github (wiki) "Can you add this feature?"', ], [ 'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22', - 'refined-github/refined-github (wiki) "Can you add this feature?"' + 'refined-github/refined-github (wiki) "Can you add this feature?"', ], ])); From 28656b04e0e83c26388133e68243f8330ad3960d Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Tue, 12 Sep 2023 02:15:26 +0000 Subject: [PATCH 6/6] Adjust wiki format --- index.js | 2 +- test.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index e217300..46b0739 100644 --- a/index.js +++ b/index.js @@ -203,7 +203,7 @@ function shortenURL(href, currentUrl = 'https://github.com') { } if (wiki) { - return `${repoUrl} (wiki) ${decodeURIComponent((wiki + (hash ? ' (' + hash.slice(1) + ')' : '')).replaceAll('-', ' '))}`; + return `Wiki: ${decodeURIComponent((wiki + (hash ? ' (' + hash.slice(1) + ')' : '')).replaceAll('-', ' '))} (${repoUrl})`; } // Shorten URLs that would otherwise be natively shortened diff --git a/test.js b/test.js index 1ca9a95..d86b660 100644 --- a/test.js +++ b/test.js @@ -484,14 +484,14 @@ test('GitHub.com URLs', urlMatcherMacro, new Map([ ], [ 'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22#3-it-doesnt-require-options', - 'refined-github/refined-github (wiki) "Can you add this feature?" (3 it doesnt require options)', + 'Wiki: "Can you add this feature?" (3 it doesnt require options) (refined-github/refined-github)', ], [ 'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22#', - 'refined-github/refined-github (wiki) "Can you add this feature?"', + 'Wiki: "Can you add this feature?" (refined-github/refined-github)', ], [ 'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22', - 'refined-github/refined-github (wiki) "Can you add this feature?"', + 'Wiki: "Can you add this feature?" (refined-github/refined-github)', ], ]));