Skip to content

feat(generate): auto generate nested sidebar #179 - #209

Open
theMyth333 wants to merge 1 commit into
docsifyjs:masterfrom
theMyth333:generate-nested-sidebar
Open

feat(generate): auto generate nested sidebar #179#209
theMyth333 wants to merge 1 commit into
docsifyjs:masterfrom
theMyth333:generate-nested-sidebar

Conversation

@theMyth333

Copy link
Copy Markdown

fixes #179
Reference docsifyjs/docsify#1290

I will do another PR for documentation if this one helps :)

@angelodias-appno

Copy link
Copy Markdown

Is this project still maintained?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds recursive sidebar generation to support multi-level directory structures (Issue #179), with directory entries optionally linking to a folder README when present (aligned with docsifyjs/docsify#1290).

Changes:

  • Replaces the flat file-walk sidebar generator with a recursive generateContent() implementation.
  • Adds README-aware directory entries and indentation for nested content.
  • Introduces modifyFileName() for displayed sidebar labels.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread lib/commands/generate.js
} else if (!hasChildContent && isReadmePresent) {
content.push(`- [${filename}](${filePath}/README.md)`)
} else {
content.push(`- [${filename}](${filePath})`)
Comment thread lib/commands/generate.js
Comment on lines +52 to +60
const isReadmePresent = fs.existsSync(path.join(cwdPath, 'README.md'))
const hasChildContent = childContent.length > 0

if (hasChildContent && isReadmePresent) {
content.push(`- [${filename}](${filePath}/README.md)`, ...childContent.map(item => ` ${item}`))
} else if (hasChildContent && !isReadmePresent) {
content.push(`- ${filename}`, ...childContent.map(item => ` ${item}`))
} else if (!hasChildContent && isReadmePresent) {
content.push(`- [${filename}](${filePath}/README.md)`)
Comment thread lib/commands/generate.js
Comment on lines +74 to +76
const filename = file.split('-')
const fileWithExtension = filename.length > 1 ? filename[1] : filename[0]
return path.basename(fileWithExtension, '.md')
Comment thread lib/commands/generate.js
Comment on lines +61 to +62
} else {
content.push(`- [${filename}](${filePath})`)
Comment thread lib/commands/generate.js
Comment on lines +34 to 38
fs.writeFileSync(sidebarPath, sidebarContent, 'utf8', err => {
if (err) {
logger.error(`Couldn't generate the sidebar file, error: ${err.message}`)
}
})
Comment thread lib/commands/generate.js
fs.readdirSync(directory).forEach(file => {
const cwdPath = path.join(directory, file)
const relativePath = path.relative(rootPath, cwdPath)
const filePath = relativePath.replace(/\s/g, '%20')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants