diff --git a/src/utils/shared/sidebar.js b/src/utils/shared/sidebar.js index f77a1691d9..1e8c1f3854 100644 --- a/src/utils/shared/sidebar.js +++ b/src/utils/shared/sidebar.js @@ -21,7 +21,7 @@ const startCase = require('lodash/startCase') const sidebar = require('../../../content/docs/sidebar.json') -const PATH_ROOT = '/doc/' +const PATH_ROOT = '/doc' const FILE_ROOT = '/docs/' const FILE_EXTENSION = '.md' @@ -80,8 +80,10 @@ function normalizeItem({ rawItem, parentPath, resultRef, prevRef }) { const sourceFileName = source ? source : slug + FILE_EXTENSION const sourcePath = FILE_ROOT + parentPath + sourceFileName + const relativePath = parentPath + slug + return { - path: PATH_ROOT + parentPath + slug, + path: relativePath ? `${PATH_ROOT}/${relativePath}` : PATH_ROOT, source: source === false ? false : sourcePath, label: label ? label : startCase(slug), tutorials: tutorials || {}, @@ -152,7 +154,7 @@ function getFirstPage() { function getItemByPath(path) { const normalizedPath = path.replace(/\/$/, '') - const isRoot = normalizedPath === PATH_ROOT.slice(0, -1) + const isRoot = normalizedPath === PATH_ROOT const item = isRoot ? normalizedSidebar[0] : findItemByField(normalizedSidebar, 'path', normalizedPath) @@ -171,12 +173,11 @@ function getItemBySource(source) { function getPathWithSource(path) { return getItemByPath(path).path } - function getParentsListFromPath(path) { - let currentPath = PATH_ROOT.slice(0, -1) + let currentPath = PATH_ROOT return path - .replace(PATH_ROOT, '') + .replace(PATH_ROOT + '/', '') .split('/') .map(part => { const path = `${currentPath}/${part}`