fix: handle blob and tree URL

This commit is contained in:
EnixCoda 2018-12-03 14:23:57 +08:00
parent 3da6082f7e
commit e36aa412d0
No known key found for this signature in database
GPG key ID: 6825847C88AA329A
2 changed files with 4 additions and 4 deletions

View file

@ -17,7 +17,7 @@ const init = dispatch => async () => {
const metaData = URLHelper.parse()
if (DOMHelper.isInCodePage()) {
detectedBranchName = DOMHelper.getCurrentBranch() // not working well with non-branch blob
|| URLHelper.parseBlobSHA() // cannot handle '/' split branch name, should not use when possibly on branch page
|| URLHelper.parseSHA() // cannot handle '/' split branch name, should not use when possibly on branch page
}
metaData.branchName = detectedBranchName || 'master'
dispatch(setMetaData, metaData)

View file

@ -18,9 +18,9 @@ function parse() {
}
}
function parseBlobSHA() {
function parseSHA() {
const { type, path } = parse()
return type === 'blob' ? path[0] : false
return (type === 'blob' || type === 'tree') ? path[0] : false
}
function isInRepoPage() {
@ -81,5 +81,5 @@ export default {
isInRepoPage,
isInCodePage,
parse,
parseBlobSHA,
parseSHA,
}