Skip to content

Commit c65a356

Browse files
Merge remote-tracking branch 'origin/main'
2 parents adcde50 + 1e92e74 commit c65a356

File tree

7 files changed

+14
-10
lines changed

7 files changed

+14
-10
lines changed

lib/node/plugins/transformers/commit.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import { regex } from '../regex.js';
22
import { template } from '../template.js';
33
import { url } from '../url.js';
44
export const commitCompact = (text, repo) => {
5-
const replacer = (value, item) => value.replace(item[0], template('commit', `${item[1]}/${item[2]}`, item[3]));
6-
text = regex(text, /\[[\w\d\s`]+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/commit\/([\w\d]{40})\)/g, replacer);
7-
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/commit\/([\w\d]{40})/g, replacer);
5+
const replacerFull = (value, item) => value.replace(item[0], template('commit', `${item[1]}/${item[2]}`, item[3]));
6+
const replacerShort = (value, item) => value.replace(item[0], template('commit', repo, item[1]));
7+
text = regex(text, /<a.*href\s?=\s?"?https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/commit\/([\w\d]{40})"?.*>.*<\/a>/g, replacerFull);
8+
text = regex(text, /\[[\w\d\s`]+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/commit\/([\w\d]{40})\)/g, replacerFull);
9+
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/commit\/([\w\d]{40})/g, replacerFull);
10+
text = regex(text, /[^\D\W\S:]*([\w\d]{40})[^:]/g, replacerShort);
811
return text;
912
};
1013
export const commitExpand = (text, repo) => {
11-
const replacer = (value, item) => value.replace(item[0], url(`${item[1]}#${item[2].substring(0, 7)}`, `${item[1]}/commit/${item[2]}`));
14+
const replacer = (value, item) => value.replace(item[0], url(repo, `${item[1].includes(repo) ? '' : item[1] + '#'}${item[2].substring(0, 7)}`, `${item[1]}/commit/${item[2]}`));
1215
text = regex(text, /::commit::([\w\d\-_\/]+)::([\w\d]+)::/g, replacer);
1316
return text;
1417
};

lib/node/plugins/transformers/compare.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const compareCompact = (text, repo) => {
1010
return text;
1111
};
1212
export const compareExpand = (text, repo) => {
13-
const replacer = (value, item) => value.replace(item[0], url(`${item[2]}...${item[3]}`, `${item[1]}/compare/${item[2]}...${item[3]}`));
13+
const replacer = (value, item) => value.replace(item[0], url(repo, `${item[1].includes(repo) ? '' : item[1] + '#'}${item[2]}...${item[3]}`, `${item[1]}/compare/${item[2]}...${item[3]}`));
1414
text = regex(text, /::compare::([\w\d.\-\/]+)::([\w\d.\-]+)::([\w\d.\-]+)::/g, replacer);
1515
return text;
1616
};

lib/node/plugins/transformers/pull-request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const pullRequestCompact = (text, repo) => {
1010
return text;
1111
};
1212
export const pullRequestExpand = (text, repo) => {
13-
const replacer = (value, item) => value.replace(item[0], url(`${item[1]}#${item[2]}`, `${item[1]}/pull/${item[2]}`));
13+
const replacer = (value, item) => value.replace(item[0], url(repo, `${item[1]}#${item[2]}`, `${item[1]}/pull/${item[2]}`));
1414
text = regex(text, /::pull_request::([\w\d\-_\/]+)::([\w\d\-_]+)::/g, replacer);
1515
return text;
1616
};

lib/node/plugins/transformers/username.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const usernameCompact = (text, repo) => {
99
return text;
1010
};
1111
export const usernameExpand = (text, repo) => {
12-
const replacer = (value, item) => value.replace(item[0], url(`@${item[1]}`, item[1]));
12+
const replacer = (value, item) => value.replace(item[0], url(repo, `@${item[1]}`, item[1]));
1313
text = regex(text, /::username::([\w\d\-_]+)::/g, replacer);
1414
return text;
1515
};

lib/node/plugins/url.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export declare const url: (value: string, link?: string) => string;
1+
export declare const url: (repo: string, value: string, link?: string) => string;

lib/node/plugins/url.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export const url = (value, link) => {
1+
export const url = (repo, value, link) => {
22
link = (link || value).replace('https://github.com/', '');
3+
value = value.replace(repo + '/', '').replace(repo, '');
34
return `<a href="https://github.com/${link}" target="_blank" rel="noopener noreferrer">${value} <ExternalLinkIcon /></a>`;
45
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vuepress-plugin-github-linkify",
3-
"version": "1.0.11",
3+
"version": "1.0.12",
44
"description": "Fix display of GitHub links for Vuepress 2",
55
"author": {
66
"name": "Andrey Helldar",

0 commit comments

Comments
 (0)