UNPKG

@vuepress-reco/style-default

Version:
30 lines (29 loc) 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveEditLink = exports.editLinkPatterns = void 0; const shared_1 = require("@vuepress/shared"); const resolveRepoType_1 = require("./resolveRepoType"); exports.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', }; const resolveEditLink = ({ docsRepo, docsBranch, docsDir, path, editLinkPattern, }) => { const repoType = resolveRepoType_1.resolveRepoType(docsRepo); let pattern; if (editLinkPattern) { pattern = editLinkPattern; } else if (repoType !== null) { pattern = exports.editLinkPatterns[repoType]; } if (!pattern) return null; const filePathRelative = path.replace(/\.html$/, '.md'); return pattern .replace(/:repo/, shared_1.isLinkHttp(docsRepo) ? docsRepo : `https://github.com/${docsRepo}`) .replace(/:branch/, docsBranch) .replace(/:path/, shared_1.removeLeadingSlash(`${shared_1.removeEndingSlash(docsDir)}/${filePathRelative}`)); }; exports.resolveEditLink = resolveEditLink;