feat(generate): auto generate nested sidebar #179#209
Open
theMyth333 wants to merge 1 commit intodocsifyjs:masterfrom
Open
feat(generate): auto generate nested sidebar #179#209theMyth333 wants to merge 1 commit intodocsifyjs:masterfrom
theMyth333 wants to merge 1 commit intodocsifyjs:masterfrom
Conversation
|
Is this project still maintained? |
There was a problem hiding this comment.
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #179
Reference docsifyjs/docsify#1290
I will do another PR for documentation if this one helps :)