Skip to content

Commit

Permalink
Fix sidebar support for empty links (/doc/ trailing slash issue) (#1265)
Browse files Browse the repository at this point in the history
* Fix sidebar support for empty links

There was a hard-coded `/doc/` prepended to every path before, but now we start
with `/doc` and add a second slash only if something comes after.

* Adjust sidebar helpers to work with new PATH_ROOT
  • Loading branch information
rogermparent authored May 8, 2020
1 parent 14db49b commit 3431b82
Showing 1 changed file with 7 additions and 6 deletions.
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

0 comments on commit 3431b82

Please sign in to comment.