|
| 1 | +# Hiding Modules from Navigation |
| 2 | + |
| 3 | +The Nimiq VitePress theme allows you to hide specific modules from the navigation while keeping them accessible for legacy reasons and SEO purposes. |
| 4 | + |
| 5 | +## Basic Usage |
| 6 | + |
| 7 | +To hide a module from both the sidebar and header navigation, add the `hidden: true` property to the module configuration: |
| 8 | + |
| 9 | +```ts |
| 10 | +// .vitepress/config.ts |
| 11 | +export default defineNimiqVitepressConfig({ |
| 12 | + themeConfig: { |
| 13 | + modules: [ |
| 14 | + { |
| 15 | + text: 'Visible Module', |
| 16 | + subpath: 'visible-module', |
| 17 | + defaultPageLink: '/visible-module/', |
| 18 | + description: 'This module appears in navigation', |
| 19 | + sidebar: [ |
| 20 | + // ... sidebar config |
| 21 | + ], |
| 22 | + }, |
| 23 | + { |
| 24 | + text: 'Hidden Module', |
| 25 | + subpath: 'hidden-module', |
| 26 | + defaultPageLink: '/hidden-module/', |
| 27 | + description: 'This module is hidden from navigation', |
| 28 | + hidden: true, // This module won't appear in navigation |
| 29 | + sidebar: [ |
| 30 | + // ... sidebar config |
| 31 | + ], |
| 32 | + }, |
| 33 | + ], |
| 34 | + }, |
| 35 | +}) |
| 36 | +``` |
| 37 | + |
| 38 | +## What Gets Hidden |
| 39 | + |
| 40 | +When a module is marked as `hidden: true`, it will be filtered out from: |
| 41 | + |
| 42 | +- **Sidebar module selector** - The dropdown list in the sidebar |
| 43 | +- **Header navigation** - The navigation links in the home layout header |
| 44 | +- **Module grid** - The grid of modules displayed on the home page |
| 45 | +- **404 page modules** - The module list shown on the 404 page |
| 46 | + |
| 47 | +## Hiding Sidebar Items |
| 48 | + |
| 49 | +You can also hide individual sidebar items (submodules) within a module's sidebar by adding the `hidden: true` property to specific sidebar items: |
| 50 | + |
| 51 | +```ts |
| 52 | +// .vitepress/config.ts |
| 53 | +export default defineNimiqVitepressConfig({ |
| 54 | + themeConfig: { |
| 55 | + modules: [ |
| 56 | + { |
| 57 | + text: 'API Documentation', |
| 58 | + subpath: 'api', |
| 59 | + defaultPageLink: '/api/', |
| 60 | + sidebar: [ |
| 61 | + { |
| 62 | + label: 'Core API', |
| 63 | + items: [ |
| 64 | + { text: 'Getting Started', link: '/api/getting-started', icon: 'i-tabler:rocket' }, |
| 65 | + { text: 'Authentication', link: '/api/auth', icon: 'i-tabler:lock' }, |
| 66 | + // This item will be hidden from the sidebar |
| 67 | + { text: 'Legacy Methods', link: '/api/legacy', icon: 'i-tabler:archive', hidden: true }, |
| 68 | + { |
| 69 | + text: 'Advanced Features', |
| 70 | + icon: 'i-tabler:settings', |
| 71 | + items: [ |
| 72 | + { text: 'Webhooks', link: '/api/webhooks' }, |
| 73 | + // This nested item will be hidden |
| 74 | + { text: 'Deprecated Endpoints', link: '/api/deprecated', hidden: true }, |
| 75 | + { text: 'Rate Limiting', link: '/api/rate-limiting' }, |
| 76 | + ], |
| 77 | + }, |
| 78 | + ], |
| 79 | + }, |
| 80 | + ], |
| 81 | + }, |
| 82 | + ], |
| 83 | + }, |
| 84 | +}) |
| 85 | +``` |
| 86 | + |
| 87 | +Hidden sidebar items are also filtered from: |
| 88 | + |
| 89 | +- **Sidebar navigation** - The nested navigation items won't appear |
| 90 | +- **Previous/Next navigation** - Hidden items are skipped in page navigation |
| 91 | + |
| 92 | +## What Remains Accessible |
| 93 | + |
| 94 | +Hidden modules remain fully accessible through: |
| 95 | + |
| 96 | +- **Direct links** - Users can still navigate to hidden modules via direct URLs |
| 97 | +- **Search functionality** - Hidden modules appear in search results |
| 98 | +- **SEO crawling** - Search engines can still index hidden module pages |
| 99 | +- **Internal navigation** - Navigation within the hidden module works normally |
| 100 | + |
| 101 | +## Use Cases |
| 102 | + |
| 103 | +### Legacy Support |
| 104 | + |
| 105 | +Hide deprecated modules while keeping them accessible for existing users: |
| 106 | + |
| 107 | +```ts |
| 108 | +const legacyModule = { |
| 109 | + text: 'Legacy API v1', |
| 110 | + subpath: 'legacy-api-v1', |
| 111 | + defaultPageLink: '/legacy-api-v1/', |
| 112 | + description: 'Deprecated API - use v2 instead', |
| 113 | + hidden: true, |
| 114 | + sidebar: [ |
| 115 | + // ... legacy documentation |
| 116 | + ], |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +### Work in Progress |
| 121 | + |
| 122 | +Hide modules that are under development: |
| 123 | + |
| 124 | +```ts |
| 125 | +const experimentalModule = { |
| 126 | + text: 'Experimental Features', |
| 127 | + subpath: 'experimental', |
| 128 | + defaultPageLink: '/experimental/', |
| 129 | + description: 'Features under development', |
| 130 | + hidden: true, |
| 131 | + sidebar: [ |
| 132 | + // ... experimental documentation |
| 133 | + ], |
| 134 | +} |
| 135 | +``` |
| 136 | + |
| 137 | +### Conditional Visibility |
| 138 | + |
| 139 | +You can conditionally hide modules based on environment or other factors: |
| 140 | + |
| 141 | +```ts |
| 142 | +const internalModule = { |
| 143 | + text: 'Internal Tools', |
| 144 | + subpath: 'internal', |
| 145 | + defaultPageLink: '/internal/', |
| 146 | + description: 'Internal development tools', |
| 147 | + hidden: process.env.NODE_ENV === 'production', |
| 148 | + sidebar: [ |
| 149 | + // ... internal documentation |
| 150 | + ], |
| 151 | +} |
| 152 | +``` |
| 153 | + |
| 154 | +## Best Practices |
| 155 | + |
| 156 | +1. **Use sparingly** - Only hide modules when there's a specific need |
| 157 | +2. **Provide alternatives** - If hiding a module, ensure users can find replacement functionality |
| 158 | +3. **Document the change** - Consider adding a note about hidden modules in your changelog |
| 159 | +4. **Test accessibility** - Ensure hidden modules remain accessible via search and direct links |
| 160 | +5. **Consider redirects** - For deprecated modules, consider adding redirects to newer alternatives |
| 161 | + |
| 162 | +## Technical Implementation |
| 163 | + |
| 164 | +The hiding functionality works by: |
| 165 | + |
| 166 | +1. Adding a `hidden?: boolean` property to the module configuration |
| 167 | +2. Filtering modules in navigation components using the `useVisibleModules` composable |
| 168 | +3. Keeping the original module list intact for search and direct access |
| 169 | +4. Maintaining full functionality for hidden modules when accessed directly |
| 170 | + |
| 171 | +This approach ensures that hiding modules only affects navigation visibility, not the actual accessibility or functionality of the modules themselves. |
0 commit comments