mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: handle non-branch blob pages
This commit is contained in:
parent
bbe26aed67
commit
0d91379281
2 changed files with 22 additions and 12 deletions
|
|
@ -16,7 +16,8 @@ const init = dispatch => async () => {
|
|||
let detectedBranchName
|
||||
const metaData = URLHelper.parse()
|
||||
if (DOMHelper.isInCodePage()) {
|
||||
detectedBranchName = DOMHelper.getCurrentBranch()
|
||||
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
|
||||
}
|
||||
metaData.branchName = detectedBranchName || 'master'
|
||||
dispatch(setMetaData, metaData)
|
||||
|
|
@ -67,12 +68,14 @@ const init = dispatch => async () => {
|
|||
}
|
||||
})
|
||||
}
|
||||
getTreeData.then(treeData => {
|
||||
if (treeData) {
|
||||
// in an unknown rare case this NOT happen
|
||||
dispatch({ treeData })
|
||||
}
|
||||
}).catch(err => dispatch(handleError, err))
|
||||
getTreeData
|
||||
.then(treeData => {
|
||||
if (treeData) {
|
||||
// in an unknown rare case this NOT happen
|
||||
dispatch({ treeData })
|
||||
}
|
||||
})
|
||||
.catch(err => dispatch(handleError, err))
|
||||
Object.assign(metaData, { api: metaDataFromAPI })
|
||||
dispatch(setMetaData, metaData)
|
||||
const shouldShow = URLHelper.isInCodePage(metaData)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import { raiseError } from "analytics";
|
||||
import { raiseError } from 'analytics'
|
||||
|
||||
function parse() {
|
||||
const { pathname } = window.location
|
||||
let [
|
||||
, // ignore content before the first '/'
|
||||
,
|
||||
// ignore content before the first '/'
|
||||
userName,
|
||||
repoName,
|
||||
type,
|
||||
|
|
@ -17,6 +18,11 @@ function parse() {
|
|||
}
|
||||
}
|
||||
|
||||
function parseBlobSHA() {
|
||||
const { type, path } = parse()
|
||||
return type === 'blob' ? path[0] : false
|
||||
}
|
||||
|
||||
function isInRepoPage() {
|
||||
const repoHeaderSelector = '.repohead'
|
||||
return Boolean(document.querySelector(repoHeaderSelector))
|
||||
|
|
@ -36,9 +42,9 @@ function isInCodePage(metaData = {}) {
|
|||
const { type, branchName } = mergedRepo
|
||||
return Boolean(
|
||||
isInRepoPage(mergedRepo) &&
|
||||
(!type || type === TYPES.TREE || type === TYPES.BLOB) &&
|
||||
type !== TYPES.COMMIT &&
|
||||
(branchName || (!type && !branchName))
|
||||
(!type || type === TYPES.TREE || type === TYPES.BLOB) &&
|
||||
type !== TYPES.COMMIT &&
|
||||
(branchName || (!type && !branchName))
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -75,4 +81,5 @@ export default {
|
|||
isInRepoPage,
|
||||
isInCodePage,
|
||||
parse,
|
||||
parseBlobSHA,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue