vuepress-theme-hope
Version:
A light vuepress theme with tons of features
25 lines • 1.11 kB
JavaScript
import { isLinkHttp, removeEndingSlash, removeLeadingSlash, } from "@vuepress/helper/client";
import { resolveRepoType } from "vuepress-shared/client";
export const editLinkPatterns = {
GitHub: ":repo/edit/:branch/:path",
GitLab: ":repo/-/edit/:branch/:path",
Gitee: ":repo/edit/:branch/:path",
Bitbucket: ":repo/src/:branch/:path?mode=edit&spa=0&at=:branch&fileviewer=file-view-default",
};
export const resolveEditLink = ({ docsRepo, docsBranch, docsDir, filePathRelative, editLinkPattern, }) => {
if (!filePathRelative)
return null;
const repoType = resolveRepoType(docsRepo);
let pattern;
if (editLinkPattern)
pattern = editLinkPattern;
else if (repoType !== null)
pattern = editLinkPatterns[repoType];
if (!pattern)
return null;
return pattern
.replace(/:repo/u, isLinkHttp(docsRepo) ? docsRepo : `https://github.com/${docsRepo}`)
.replace(/:branch/u, docsBranch)
.replace(/:path/u, removeLeadingSlash(`${removeEndingSlash(docsDir)}/${filePathRelative}`));
};
//# sourceMappingURL=resolveEditLink.js.map