Skip to content

Commit

Permalink
Add shorten wiki (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
Katsute committed Sep 12, 2023
1 parent 2c44c2f commit 083517d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -200,6 +202,10 @@ function shortenURL(href, currentUrl = 'https://github.com') {
return `${partial}${search}${hash} (compare)`;
}

if (wiki) {
return `Wiki: ${decodeURIComponent((wiki + (hash ? ' (' + hash.slice(1) + ')' : '')).replaceAll('-', ' '))} (${repoUrl})`;
}

// Shorten URLs that would otherwise be natively shortened
if (isRedirection) {
if (issue) {
Expand Down
12 changes: 12 additions & 0 deletions test.js
Expand Up @@ -486,4 +486,16 @@ test('GitHub.com URLs', urlMatcherMacro, new Map([
'https://togithub.com/refined-github/refined-github/commit/e81a9646b448d90c7e02ab41332cab0507dccbbd#commitcomment-60089354',
'refined-github/refined-github@<code>e81a964</code> (comment)',
],
[
'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22#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#',
'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',
'Wiki: "Can you add this feature?" (refined-github/refined-github)',
],
]));

0 comments on commit 083517d

Please sign in to comment.