From 79f5a5595a76e50aa457147cc942677402fb0011 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Wed, 30 May 2018 21:26:14 +0800 Subject: [PATCH] refactor(URLHelper): modify parse logic Close #9 --- src/utils/URLHelper.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/utils/URLHelper.js b/src/utils/URLHelper.js index 71296c7..b5be2a6 100644 --- a/src/utils/URLHelper.js +++ b/src/utils/URLHelper.js @@ -1,7 +1,7 @@ function parseRaw() { const { pathname } = window.location let [ - /* ignore content before the first '/' */, + , // ignore content before the first '/' userName, repoName, type, @@ -19,21 +19,29 @@ function parseRaw() { function parse() { const parsedData = parseRaw() if (!isInCodePage()) { - delete parsedData.type delete parsedData.branchName } return parsedData } const RESERVED_NAME = ['blog'] +// route types related to determining if sidebar should show +const TYPES = { + TREE: 'tree', + BLOB: 'blob', + COMMIT: 'commit', + // known but not related types: issues, pulls, wiki, insight, + // TODO: record more types +} function isInCodePage(metaData = {}) { - const { userName, repoName, type, branchName } = {...parseRaw(), ...metaData} + const { userName, repoName, type, branchName } = { ...parseRaw(), ...metaData } return ( userName && !RESERVED_NAME.find(_ => _ === userName) && repoName && - (!type || type === 'tree' || type === 'blob') && - (branchName || !type && !branchName) + (!type || type === TYPES.TREE || type === TYPES.BLOB) && + type !== TYPES.COMMIT && + (branchName || (!type && !branchName)) ) }