Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sidebar support for empty links (/doc/ trailing slash issue) #1265

Merged
merged 2 commits into from
May 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/utils/shared/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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 || {},
Expand Down Expand Up @@ -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)
Expand All @@ -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}`
Expand Down