Skip to content

Commit

Permalink
Allow to set empty slug in sidebar.json
Browse files Browse the repository at this point in the history
  • Loading branch information
psdcoder committed Mar 19, 2020
1 parent 0381090 commit 69ec1e8
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/utils/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
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'

function validateRawItem({ slug, source, children }) {
const isSourceDisabled = source === false

if (!slug) {
if (typeof slug !== 'string') {
throw Error("'slug' field is required in objects in sidebar.json")
}

Expand Down Expand Up @@ -81,7 +81,7 @@ function normalizeItem({ rawItem, parentPath, resultRef, prevRef }) {
const sourcePath = FILE_ROOT + parentPath + sourceFileName

return {
path: PATH_ROOT + parentPath + slug,
path: PATH_ROOT + (parentPath || slug ? '/' : '') + parentPath + slug,
source: source === false ? false : sourcePath,
label: label ? label : startCase(slug),
tutorials: tutorials || {},
Expand Down Expand Up @@ -152,7 +152,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)
Expand All @@ -173,10 +173,14 @@ function getPathWithSoruce(path) {
}

function getParentsListFromPath(path) {
let currentPath = PATH_ROOT.slice(0, -1)
let currentPath = PATH_ROOT

if (path === PATH_ROOT) {
return [PATH_ROOT]
}

return path
.replace(PATH_ROOT, '')
.replace(`${PATH_ROOT}/`, '')
.split('/')
.map(part => {
const path = `${currentPath}/${part}`
Expand Down

0 comments on commit 69ec1e8

Please sign in to comment.