Skip to content

Commit

Permalink
fix overview pages for spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
amozoss committed Aug 16, 2023
1 parent 65b3de0 commit 5d0143f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
1 change: 1 addition & 0 deletions app/learn/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ redirects:
- /dcs/storage/considerations
- /dcs/storage
pageTitle: Product overview
weight: 0
---

## Introduction
Expand Down
2 changes: 1 addition & 1 deletion app/node/page.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Overview
weight: 1
weight: 0
---

🚧
3 changes: 3 additions & 0 deletions app/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
title: Overview
pageTitle: Storj Docs
description: Make the world your datacenter
redirects:
- /dcs
weight: 0
---

Welcome to the Storj Documentation!
Expand Down
41 changes: 19 additions & 22 deletions src/markdoc/navigation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ function getFrontmatter(filepath) {
}

function walkDir(dir, space, currentPath = '') {
const filepath =
space == 'dcs' ? dir + '/../page.md' : path.join(dir, 'page.md')
let fm = getFrontmatter(filepath)
let entry = {
...fm,
links: [],
href: space == 'dcs' ? '/' : `/${space}`,
}

return [entry, ...walkDirRec(dir, space, currentPath)]
}

function walkDirRec(dir, space, currentPath) {
let results = []
const list = fs.readdirSync(dir)

Expand All @@ -97,38 +110,29 @@ function walkDir(dir, space, currentPath = '') {
const relativePath = path.join(currentPath, file)

if (stat && stat.isDirectory()) {
let indexFilepath = filepath + '/page.md'
let pageFilepath = path.join(filepath, 'page.md')
// For directories that don't have an page.md
let metaFilepath = filepath + '/_meta.json'
let metaFilepath = path.join(filepath, '_meta.json')
let title = file.charAt(0).toUpperCase() + file.slice(1)
let fm = null
if (fs.existsSync(indexFilepath)) {
fm = getFrontmatter(indexFilepath)
if (fs.existsSync(pageFilepath)) {
fm = getFrontmatter(pageFilepath)
} else if (fs.existsSync(metaFilepath)) {
const meta = fs.readFileSync(metaFilepath, 'utf8')
fm = JSON.parse(meta)
}
let entry = {
type: file,
title,
links: walkDir(filepath, space, relativePath),
links: walkDirRec(filepath, space, relativePath),
}
if (fm) {
entry = Object.assign(entry, fm)
}
if (fs.existsSync(indexFilepath)) {
if (fs.existsSync(pageFilepath)) {
entry.href = `/${space}/${relativePath}`
}
results.push(entry)
} else if (path.extname(file) === '.md' && file !== 'page.md') {
let url = `${relativePath.replace(/\.md$/, '')}` // Remove .md extension
let fm = getFrontmatter(filepath)
let entry = {
...fm,
links: [],
href: `/${space}/${url}`,
}
results.push(entry)
}
})

Expand Down Expand Up @@ -168,13 +172,6 @@ export default function (nextConfig = {}) {

let dcs = walkDir(`${dir}/dcs`, 'dcs')
sortByWeightThenTitle(dcs)
let home = {
type: '',
title: 'Overview',
links: [],
href: '/',
}
dcs.unshift(home)
let node = walkDir(`${dir}/node`, 'node')
sortByWeightThenTitle(node)
let learn = walkDir(`${dir}/learn`, 'learn')
Expand Down

0 comments on commit 5d0143f

Please sign in to comment.