Gitako/src/utils/urlHelper.js
2018-01-07 12:45:27 +08:00

39 lines
755 B
JavaScript

function parse() {
const { pathname } = window.location
const [
,
// ignore content before the first '/'
userName,
repoName,
type,
branchName,
] = pathname.split('/')
return {
userName,
repoName,
type,
branchName,
}
}
const RESERVED_NAME = ['blog']
function isInCodePage() {
const { userName, repoName, type, branchName } = parse()
return !!(
userName &&
!RESERVED_NAME.find(_ => _ === userName) &&
repoName &&
(!type || type === 'tree' || type === 'blob') &&
((type && branchName) || !(type || branchName))
)
}
function detectShouldShow(metaData) {
return isInCodePage() && (!metaData || metaData.repoName)
}
export default {
detectShouldShow,
isInCodePage,
parse,
}