mirror of
https://github.com/zhigang1992/docz.git
synced 2026-03-26 10:14:33 +08:00
fix(docz-core): try catch on get repo info
This commit is contained in:
@@ -29,18 +29,22 @@ export const getRepoUrl = () => {
|
||||
}
|
||||
|
||||
export const getRepoEditUrl = (src: string): string | null => {
|
||||
const project = path.parse(findup.sync('.git')).dir
|
||||
const root = path.join(paths.root, src)
|
||||
const relative = path.relative(project, root)
|
||||
const tree = path.join('/edit/master', relative)
|
||||
const repo = parseRepo()
|
||||
try {
|
||||
const project = path.parse(findup.sync('.git')).dir
|
||||
const root = path.join(paths.root, src)
|
||||
const relative = path.relative(project, root)
|
||||
const tree = path.join('/edit/master', relative)
|
||||
const repo = parseRepo()
|
||||
|
||||
return (
|
||||
repo &&
|
||||
repo.browsetemplate
|
||||
.replace('{domain}', repo.domain)
|
||||
.replace('{user}', repo.user)
|
||||
.replace('{project}', repo.project)
|
||||
.replace('{/tree/committish}', tree)
|
||||
)
|
||||
return (
|
||||
repo &&
|
||||
repo.browsetemplate
|
||||
.replace('{domain}', repo.domain)
|
||||
.replace('{user}', repo.user)
|
||||
.replace('{project}', repo.project)
|
||||
.replace('{/tree/committish}', tree)
|
||||
)
|
||||
} catch (err) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user