Skip to content

Commit

Permalink
Release v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Mar 1, 2023
1 parent 99a5b56 commit ad5ec2d
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 19 deletions.
1 change: 1 addition & 0 deletions lib/node/plugins/helpers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const replace: (text: string, match: Array<string>, to: string) => string;
7 changes: 7 additions & 0 deletions lib/node/plugins/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const replace = (text, match, to) => {
return text.replace(match[0], to);
// const index: number = match['index']
// const from: string = match[0]
//
// return text.slice(0, index) + to + text.slice(index + from.length)
};
3 changes: 3 additions & 0 deletions lib/node/plugins/transformers/blobs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { GitHubLinkifyTransformer } from '../../types/transformer.js';
export declare const blobsCompact: GitHubLinkifyTransformer;
export declare const blobsExpand: GitHubLinkifyTransformer;
15 changes: 15 additions & 0 deletions lib/node/plugins/transformers/blobs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { replace } from '../helpers.js';
import { template } from '../template.js';
import { regex } from '../regex';
import { url } from '../url';
export const blobsCompact = (text, repo) => {
const replacer = (value, item) => replace(value, item, template('blob', `${item[1]}/${item[2]}`, item[3]));
text = regex(text, /\[[\w\d\s`]+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/blob\/([\w\d\/\.\-_]+)\)/g, replacer);
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/blob\/([\w\d\/\.\-_]+)/g, replacer);
return text;
};
export const blobsExpand = (text, repo) => {
const replacer = (value, item) => value.replace(item[0], url(repo, `${item[1].includes(repo) ? '' : item[1] + '#'}${item[2]}`, `${item[1]}/blob/${item[2]}`));
text = regex(text, /::blob::([\w\d\-_\/]+)::([\w\d\/\.\-_]+)::/g, replacer);
return text;
};
5 changes: 3 additions & 2 deletions lib/node/plugins/transformers/commit.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { regex } from '../regex.js';
import { replace } from '../helpers.js';
import { template } from '../template.js';
import { url } from '../url.js';
export const commitCompact = (text, repo) => {
const replacerFull = (value, item) => value.replace(item[0], template('commit', `${item[1]}/${item[2]}`, item[3]));
const replacerShort = (value, item) => value.replace(item[0], template('commit', repo, item[1]));
const replacerFull = (value, item) => replace(value, item, template('commit', `${item[1]}/${item[2]}`, item[3]));
const replacerShort = (value, item) => replace(value, item, template('commit', repo, item[1]));
text = regex(text, /<a.*href\s?=\s?"?https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/commit\/([\w\d]{40})"?.*>.*<\/a>/g, replacerFull);
text = regex(text, /\[[\w\d\s`]+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/commit\/([\w\d]{40})\)/g, replacerFull);
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/commit\/([\w\d]{40})/g, replacerFull);
Expand Down
9 changes: 5 additions & 4 deletions lib/node/plugins/transformers/compare.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { regex } from '../regex.js';
import { replace } from '../helpers.js';
import { template } from '../template.js';
import { url } from '../url.js';
export const compareCompact = (text, repo) => {
const replacerFull = (value, item) => value.replace(item[0], template('compare', `${item[1]}/${item[2]}`, item[3], item[4]));
const replacerShort = (value, item) => value.replace(item[0], template('compare', repo, item[1], item[2]));
text = regex(text, /\[[\s\w\d`.\-]+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/compare\/([\w\d.\-]+)\.\.\.([\w\d.\-]+)\)/g, replacerFull);
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/compare\/([\w\d.\-]+)\.\.\.([\w\d.\-]+)/g, replacerFull);
const replacerFull = (value, item) => replace(value, item, template('compare', `${item[1]}/${item[2]}`, item[3], item[4]));
const replacerShort = (value, item) => replace(value, item, template('compare', repo, item[1], item[2]));
text = regex(text, /\[[\s\w\d`.\-]+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/compare\/([\w\d.\-]+)\.{3}([\w\d.\-]+)\)/g, replacerFull);
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/compare\/([\w\d.\-]+)\.{3}([\w\d.\-]+)/g, replacerFull);
text = regex(text, /([\w\d.\-]+)\.{3}([\w\d.\-]+)/g, replacerShort);
return text;
};
Expand Down
19 changes: 13 additions & 6 deletions lib/node/plugins/transformers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@ import { mentionCompact, mentionExpand } from './mention.js';
import { pullRequestCompact, pullRequestExpand } from './pull-request.js';
import { compareCompact, compareExpand } from './compare.js';
import { commitCompact, commitExpand } from './commit.js';
import { tagsCompact, tagsExpand } from './tags.js';
import { treesCompact, treesExpand } from './trees.js';
import { blobsCompact, blobsExpand } from './blobs.js';
const compact = [
mentionCompact,
pullRequestCompact,
compareCompact,
commitCompact
commitCompact,
treesCompact,
blobsCompact,
tagsCompact
];
const expand = [
mentionExpand,
pullRequestExpand,
compareExpand,
commitExpand
commitExpand,
treesExpand,
blobsExpand,
tagsExpand
];
const resolveRepoUrl = (url) => url.replace('https://github.com/', '');
export const transform = (text, repo) => {
// compact
Array.from(compact, (tranformer) => text = tranformer(text, resolveRepoUrl(repo)));
// expand
Array.from(expand, (tranformer) => text = tranformer(text, resolveRepoUrl(repo)));
Array.from(compact, (transformer) => text = transformer(text, resolveRepoUrl(repo)));
Array.from(expand, (transformer) => text = transformer(text, resolveRepoUrl(repo)));
return text;
};
3 changes: 2 additions & 1 deletion lib/node/plugins/transformers/mention.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { regex } from '../regex.js';
import { replace } from '../helpers.js';
import { template } from '../template.js';
import { url } from '../url.js';
export const mentionCompact = (text, repo) => {
const replacer = (value, item) => value.replace(item[0], template('mention', item[1]));
const replacer = (value, item) => replace(value, item, template('mention', item[1]));
text = regex(text, /<\s*a.+@([a-zA-Z][\w\d\-_]*).+<\/\s*a\s*>/g, replacer);
text = regex(text, /\[[\s`@]*[\w\d\-]+[\s`]*]\(https:\/\/github\.com\/([\w\d\-]+)\/?\)/g, replacer);
text = regex(text, /@([a-zA-Z][\w\d\-_]*)/g, replacer);
Expand Down
7 changes: 4 additions & 3 deletions lib/node/plugins/transformers/pull-request.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { regex } from '../regex.js';
import { replace } from '../helpers.js';
import { template } from '../template.js';
import { url } from '../url.js';
export const pullRequestCompact = (text, repo) => {
const replacerFull = (value, item) => value.replace(item[0], template('pull_request', `${item[1]}/${item[2]}`, item[3]));
const replacerShort = (value, item) => value.replace(item[0], template('pull_request', repo, item[1]));
const replacerFull = (value, item) => replace(value, item, template('pull_request', `${item[1]}/${item[2]}`, item[3]));
const replacerShort = (value, item) => replace(value, item, template('pull_request', repo, item[1]));
text = regex(text, /\[[\s`#@]*\d+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/pull\/(\d+)\)/g, replacerFull);
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/pull\/(\d+)/g, replacerFull);
text = regex(text, /#(\d+)/g, replacerShort);
return text;
};
export const pullRequestExpand = (text, repo) => {
const replacer = (value, item) => value.replace(item[0], url(repo, `${item[1]}#${item[2]}`, `${item[1]}/pull/${item[2]}`));
text = regex(text, /::pull_request::([\w\d\-_\/]+)::([\w\d\-_]+)::/g, replacer);
text = regex(text, /::pull_request::([\d\w.\-_\/]+)::([\d\w.\-_\/]+)::/g, replacer);
return text;
};
3 changes: 3 additions & 0 deletions lib/node/plugins/transformers/tags.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { GitHubLinkifyTransformer } from '../../types/transformer.js';
export declare const tagsCompact: GitHubLinkifyTransformer;
export declare const tagsExpand: GitHubLinkifyTransformer;
17 changes: 17 additions & 0 deletions lib/node/plugins/transformers/tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { regex } from '../regex.js';
import { replace } from '../helpers.js';
import { template } from '../template.js';
import { url } from '../url.js';
export const tagsCompact = (text, repo) => {
const replacerFull = (value, item) => replace(value, item, template('tag', `${item[1]}/${item[2]}`, item[3]));
const replacerShort = (value, item) => replace(value, item, template('tag', repo, item[1]));
text = regex(text, /\[[\s\w\d`.\-]+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/releases\/tag\/(v?\d+\.\d+\.\d+-?\w*\.?\d*)\)/g, replacerFull);
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/releases\/tag\/(v?\d+\.\d+\.\d+-?\w*\.?\d*)/g, replacerFull);
// text = regex(text, /(?<!:)(?<=^|\s)(v?\d+\.\d+\.\d+-?\w*\.?\d*)(?<!:)/g, replacerShort)
return text;
};
export const tagsExpand = (text, repo) => {
const replacer = (value, item) => value.replace(item[0], url(repo, `${item[1].includes(repo) ? '' : item[1] + '#'}${item[2].replace('v', '')}`, `${item[1]}/releases/tag/${item[2]}`));
text = regex(text, /::tag::([\w\d.\-\/]+)::([\w\d.\-]+)::/g, replacer);
return text;
};
3 changes: 3 additions & 0 deletions lib/node/plugins/transformers/trees.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { GitHubLinkifyTransformer } from '../../types/transformer.js';
export declare const treesCompact: GitHubLinkifyTransformer;
export declare const treesExpand: GitHubLinkifyTransformer;
15 changes: 15 additions & 0 deletions lib/node/plugins/transformers/trees.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { regex } from '../regex.js';
import { replace } from '../helpers.js';
import { template } from '../template.js';
import { url } from '../url.js';
export const treesCompact = (text, repo) => {
const replacer = (value, item) => replace(value, item, template('tree', `${item[1]}/${item[2]}`, `${item[3]}`));
text = regex(text, /\[[\s`#@]*\d+]\(https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/tree\/([\d\w.\-_\/]+)\)/g, replacer);
text = regex(text, /https:\/\/github\.com\/([\w\d\-_]+)\/([\w\d\-_]+)\/tree\/([\d\w.\-_\/]+)/g, replacer);
return text;
};
export const treesExpand = (text, repo) => {
const replacer = (value, item) => replace(value, item, url(repo, `${item[1].includes(repo) ? '' : item[1] + '#'}${item[2]}`, `${item[1]}/tree/${item[2]}`));
text = regex(text, /::tree::([\d\w.\-_\/]+)::([\d\w.\-_\/]+)::/g, replacer);
return text;
};
4 changes: 2 additions & 2 deletions lib/node/plugins/url.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const url = (repo, value, link) => {
link = (link || value).replace('https://github.com/', '');
value = value.replace(repo + '/', '').replace(repo, '');
return `<a href="https://github.com/${link}" target="_blank" rel="noopener noreferrer">${value} <ExternalLinkIcon /></a>`;
value = value.replace(repo + '/', '').replace(repo, '').trim();
return `<a href="https://github.com/${link}" target="_blank" rel="noopener noreferrer">${value}<ExternalLinkIcon /></a>`;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vuepress-plugin-github-linkify",
"version": "1.0.13",
"version": "1.1.0",
"description": "Fix display of GitHub links for Vuepress 2",
"author": {
"name": "Andrey Helldar",
Expand Down

0 comments on commit ad5ec2d

Please sign in to comment.