Skip to content

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

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

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

Conversation

@theMyth333
Copy link

fixes #179
Reference docsifyjs/docsify#1290

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

@angelodias-appno
Copy link

Is this project still maintained?

Copy link

Copilot AI left a comment

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.

} else if (!hasChildContent && isReadmePresent) {
content.push(`- [${filename}](${filePath}/README.md)`)
} else {
content.push(`- [${filename}](${filePath})`)
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 on lines +74 to +76
const filename = file.split('-')
const fileWithExtension = filename.length > 1 ? filename[1] : filename[0]
return path.basename(fileWithExtension, '.md')
Comment on lines +61 to +62
} else {
content.push(`- [${filename}](${filePath})`)
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}`)
}
})
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

I would like to know why generating multi-level directories is not supported

3 participants