-
Notifications
You must be signed in to change notification settings - Fork 45
feat: Sidebar enhancements #745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
canerakdas
wants to merge
16
commits into
nodejs:main
Choose a base branch
from
canerakdas:feat/sidebar-groups
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e022a2e
feat: Sidebar enhancements
canerakdas 9b03c22
docs: enhance param name
canerakdas 105243b
chore: seperate ui constants
canerakdas 5383283
Update src/generators/web/ui/utils/sidebar.mjs
canerakdas 6dd889c
chore: new modules added
canerakdas 616c7a2
Merge branch 'feat/sidebar-groups' of github.com:canerakdas/api-docs-…
canerakdas b9b0ca6
chore: extracting utilities and adding more unit tests
canerakdas 52e939c
chore: move select styles into the module css
canerakdas 67c54d6
refactor: remove static group array
canerakdas 00045fe
feat: navigation list sort weight added
canerakdas 7825d33
chore: simplify weight normalization
canerakdas 40eb6fa
docs: format markdown table
canerakdas b2612f4
chore: resolve conflict
canerakdas 955bee6
chore: resolve conflict
canerakdas 3531e1b
chore: add theme mock for tests
canerakdas 4e2ad68
fix: eslint import order
canerakdas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
canerakdas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| /** | ||
| * @deprecated This is being exported temporarily during the transition period. | ||
| * For a more general solution, category information should be added to pages in | ||
| * YAML format, and this array should be removed. | ||
| * | ||
| * Defines the sidebar navigation groups and their associated page URLs. | ||
| * @type {Array<{ groupName: string, items: Array<string> }>} | ||
| */ | ||
| export const SIDEBAR_GROUPS = [ | ||
| { | ||
| groupName: 'Getting Started', | ||
| items: [ | ||
| 'documentation.html', | ||
| 'synopsis.html', | ||
| 'cli.html', | ||
| 'environment_variables.html', | ||
| 'globals.html', | ||
| ], | ||
| }, | ||
| { | ||
| groupName: 'Module System', | ||
| items: [ | ||
| 'modules.html', | ||
| 'esm.html', | ||
| 'module.html', | ||
| 'packages.html', | ||
| 'typescript.html', | ||
| ], | ||
| }, | ||
| { | ||
| groupName: 'Networking & Protocols', | ||
| items: [ | ||
| 'http.html', | ||
| 'http2.html', | ||
| 'https.html', | ||
| 'net.html', | ||
| 'dns.html', | ||
| 'dgram.html', | ||
| 'quic.html', | ||
| ], | ||
| }, | ||
| { | ||
| groupName: 'File System & I/O', | ||
| items: [ | ||
| 'fs.html', | ||
| 'path.html', | ||
| 'buffer.html', | ||
| 'stream.html', | ||
| 'string_decoder.html', | ||
| 'zlib.html', | ||
| 'readline.html', | ||
| 'tty.html', | ||
| 'zlib_iter.html', | ||
| ], | ||
| }, | ||
| { | ||
| groupName: 'Asynchronous Programming', | ||
| items: [ | ||
| 'async_context.html', | ||
| 'async_hooks.html', | ||
| 'events.html', | ||
| 'timers.html', | ||
| 'webstreams.html', | ||
| 'stream_iter.html', | ||
| ], | ||
| }, | ||
| { | ||
| groupName: 'Process & Concurrency', | ||
| items: [ | ||
| 'process.html', | ||
| 'child_process.html', | ||
| 'cluster.html', | ||
| 'worker_threads.html', | ||
| 'os.html', | ||
| ], | ||
| }, | ||
| { | ||
| groupName: 'Security & Cryptography', | ||
| items: ['crypto.html', 'webcrypto.html', 'permissions.html', 'tls.html'], | ||
| }, | ||
| { | ||
| groupName: 'Data & URL Utilities', | ||
| items: ['url.html', 'querystring.html', 'punycode.html', 'util.html'], | ||
| }, | ||
| { | ||
| groupName: 'Debugging & Diagnostics', | ||
| items: [ | ||
| 'debugger.html', | ||
| 'inspector.html', | ||
| 'console.html', | ||
| 'report.html', | ||
| 'tracing.html', | ||
| 'diagnostics_channel.html', | ||
| 'errors.html', | ||
| ], | ||
| }, | ||
| { | ||
| groupName: 'Testing & Assertion', | ||
| items: ['test.html', 'assert.html', 'repl.html'], | ||
| }, | ||
| { | ||
| groupName: 'Performance & Observability', | ||
| items: ['perf_hooks.html', 'v8.html'], | ||
| }, | ||
| { | ||
| groupName: 'Runtime & Advanced APIs', | ||
| items: [ | ||
| 'vm.html', | ||
| 'wasi.html', | ||
| 'sqlite.html', | ||
| 'single-executable-applications.html', | ||
| 'intl.html', | ||
| ], | ||
| }, | ||
| { | ||
| groupName: 'Native & Low-level Extensions', | ||
| items: ['addons.html', 'n-api.html', 'embedding.html'], | ||
| }, | ||
| { | ||
| groupName: 'Legacy & Deprecated', | ||
| items: ['deprecations.html', 'domain.html'], | ||
| }, | ||
| ]; |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| 'use strict'; | ||
|
|
||
| import assert from 'node:assert/strict'; | ||
| import { describe, it } from 'node:test'; | ||
|
|
||
| import { buildSideBarGroups } from '../sidebar.mjs'; | ||
|
|
||
| describe('buildSideBarGroups', () => { | ||
| it('groups entries by category and preserves insertion order', () => { | ||
| const frontmatter = [ | ||
| { label: 'FS', link: '/api/fs.html', category: 'File System' }, | ||
| { label: 'HTTP', link: '/api/http.html', category: 'Networking' }, | ||
canerakdas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { label: 'Path', link: '/api/path.html', category: 'File System' }, | ||
| ]; | ||
|
|
||
| const result = buildSideBarGroups(frontmatter); | ||
|
|
||
| assert.deepStrictEqual(result, [ | ||
| { | ||
| groupName: 'File System', | ||
| items: [ | ||
| { label: 'FS', link: '/api/fs.html' }, | ||
| { label: 'Path', link: '/api/path.html' }, | ||
| ], | ||
| }, | ||
| { | ||
| groupName: 'Networking', | ||
| items: [{ label: 'HTTP', link: '/api/http.html' }], | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('puts entries without category into an Others group at the end by default', () => { | ||
| const frontmatter = [ | ||
| { label: 'Buffer', link: '/api/buffer.html', category: 'Binary' }, | ||
| { label: 'Unknown', link: '/api/unknown.html' }, | ||
| { label: 'Config', link: '/api/config.html', category: '' }, | ||
| ]; | ||
|
|
||
| const result = buildSideBarGroups(frontmatter); | ||
|
|
||
| assert.equal(result.at(-1).groupName, 'Others'); | ||
| assert.deepStrictEqual(result.at(-1).items, [ | ||
| { label: 'Unknown', link: '/api/unknown.html' }, | ||
| { label: 'Config', link: '/api/config.html' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('uses a custom default group name when provided', () => { | ||
| const result = buildSideBarGroups( | ||
| [{ label: 'Unknown', link: '/api/unknown.html' }], | ||
| 'General' | ||
| ); | ||
|
|
||
| assert.deepStrictEqual(result, [ | ||
| { | ||
| groupName: 'General', | ||
| items: [{ label: 'Unknown', link: '/api/unknown.html' }], | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('returns an empty array when given no entries', () => { | ||
| assert.deepStrictEqual(buildSideBarGroups([]), []); | ||
| }); | ||
| }); | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { SIDEBAR_GROUPS } from '../constants.mjs'; | ||
|
|
||
| /** | ||
| * @deprecated This is being exported temporarily during the transition period. | ||
| * Reverse lookup: filename (e.g. 'fs.html') -> groupName, used as category | ||
| * fallback for pages without explicit category in metadata. | ||
| */ | ||
| export const fileToGroup = new Map( | ||
| SIDEBAR_GROUPS.flatMap(({ groupName, items }) => | ||
| items.map(item => [item, groupName]) | ||
| ) | ||
| ); | ||
|
|
||
| /** | ||
| * Builds grouped sidebar navigation from categorized page entries. | ||
| * Pages without a category are placed under the provided default group. | ||
| * | ||
| * @param {Array<{ label: string, link: string, category?: string }>} items | ||
| * @param {string} [defaultGroupName='Others'] | ||
| * @returns {Array<{ groupName: string, items: Array<{ label: string, link: string }> }>} | ||
| */ | ||
| export const buildSideBarGroups = (items, defaultGroupName = 'Others') => { | ||
canerakdas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const groups = new Map(); | ||
| const others = []; | ||
|
|
||
| // Group entries by category while preserving insertion order | ||
| for (const { label, link, category } of items) { | ||
| const linkFilename = link.split('/').at(-1); | ||
|
|
||
| // Skip index pages as they are typically the main entry point for a section | ||
| // and may not need to be listed separately in the sidebar. | ||
| if (linkFilename === 'index.html') { | ||
| continue; | ||
| } | ||
|
|
||
| const resolvedCategory = category ?? fileToGroup.get(linkFilename); | ||
|
|
||
| if (!resolvedCategory) { | ||
| others.push({ label, link }); | ||
| continue; | ||
| } | ||
|
|
||
| const groupItems = groups.get(resolvedCategory) ?? []; | ||
| groupItems.push({ label, link }); | ||
| groups.set(resolvedCategory, groupItems); | ||
| } | ||
|
|
||
| // Convert the groups map to an array while preserving the original order of categories | ||
| const orderedGroups = [...groups.entries()].map(([groupName, items]) => ({ | ||
| groupName, | ||
| items, | ||
| })); | ||
|
|
||
canerakdas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (others.length > 0) { | ||
| orderedGroups.push({ groupName: defaultGroupName, items: others }); | ||
| } | ||
|
|
||
| return orderedGroups; | ||
| }; | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style imports should happen after everything afaik