|
| 1 | +import { defineConfig } from 'vitepress'; |
| 2 | +import { groupIconMdPlugin, groupIconVitePlugin } from 'vitepress-plugin-group-icons'; |
| 3 | + |
| 4 | +import modulesData from '../generated/metadata/modules.json' with { type: 'json' }; |
| 5 | +import hapiInfo from '../generated/modules/hapi/info.json' with { type: 'json' }; |
| 6 | +import pluginsData from '../src/plugins.json' with { type: 'json' }; |
| 7 | +import { formatVersion } from './utils.js'; |
| 8 | + |
| 9 | +const modulesItems = Object.keys(modulesData) |
| 10 | + .filter((name) => name !== 'hapi') |
| 11 | + .map((name) => ({ |
| 12 | + link: `/module/${name}/api/${modulesData[name as keyof typeof modulesData].latestVersion}`, |
| 13 | + text: name, |
| 14 | + })); |
| 15 | + |
| 16 | +const getModuleSidebar = (moduleName: string) => { |
| 17 | + const moduleData = modulesData[moduleName as keyof typeof modulesData]; |
| 18 | + |
| 19 | + const items: { link: string; text: string; items?: { link: string; text: string }[] }[] = [ |
| 20 | + { |
| 21 | + items: [...moduleData.versions].toReversed().map((version) => ({ |
| 22 | + link: `/module/${moduleName}/api/${formatVersion(version.name)}`, |
| 23 | + text: formatVersion(version.name), |
| 24 | + })), |
| 25 | + link: `/module/${moduleName}/api/${moduleData.latestVersion}`, |
| 26 | + text: 'API', |
| 27 | + }, |
| 28 | + { link: `/module/${moduleName}/changelog`, text: 'Changelog' }, |
| 29 | + ]; |
| 30 | + |
| 31 | + if (moduleName === 'bell') { |
| 32 | + items.push({ link: '/module/bell/examples', text: 'Examples' }); |
| 33 | + items.push({ link: '/module/bell/providers', text: 'Providers' }); |
| 34 | + } |
| 35 | + |
| 36 | + return [ |
| 37 | + { |
| 38 | + items, |
| 39 | + text: moduleName, |
| 40 | + }, |
| 41 | + { |
| 42 | + collapsed: true, |
| 43 | + items: [{ link: '/module/', text: 'All Modules' }, ...modulesItems], |
| 44 | + text: 'Other Modules', |
| 45 | + }, |
| 46 | + ]; |
| 47 | +}; |
| 48 | + |
| 49 | +const moduleSidebars = Object.fromEntries( |
| 50 | + Object.keys(modulesData) |
| 51 | + .filter((name) => name !== 'hapi') |
| 52 | + .map((name) => [`/module/${name}/`, getModuleSidebar(name)]), |
| 53 | +); |
| 54 | + |
| 55 | +const tutorialItems = [ |
| 56 | + { slug: 'getting-started', text: 'Getting Started' }, |
| 57 | + { slug: 'auth', text: 'Authentication' }, |
| 58 | + { slug: 'caching', text: 'Caching' }, |
| 59 | + { slug: 'cookies', text: 'Cookies' }, |
| 60 | + { slug: 'logging', text: 'Logging' }, |
| 61 | + { slug: 'plugins', text: 'Plugins' }, |
| 62 | + { slug: 'routing', text: 'Routing' }, |
| 63 | + { slug: 'server-methods', text: 'Server Methods' }, |
| 64 | + { slug: 'serving-files', text: 'Serving Files' }, |
| 65 | + { slug: 'testing', text: 'Testing' }, |
| 66 | + { slug: 'validation', text: 'Validation' }, |
| 67 | + { slug: 'views', text: 'Views' }, |
| 68 | + { slug: 'community', text: 'Community' }, |
| 69 | + { slug: 'express-to-hapi', text: 'Express to hapi' }, |
| 70 | +]; |
| 71 | + |
| 72 | +const getTutorialSidebar = (locale: string) => [ |
| 73 | + { |
| 74 | + items: tutorialItems.map((t) => ({ |
| 75 | + link: `/tutorials/${locale}/${t.slug}`, |
| 76 | + text: t.text, |
| 77 | + })), |
| 78 | + text: 'Tutorials', |
| 79 | + }, |
| 80 | +]; |
| 81 | + |
| 82 | +export default defineConfig({ |
| 83 | + appearance: true, |
| 84 | + cleanUrls: true, |
| 85 | + description: 'The Simple, Secure Framework Developers Trust', |
| 86 | + head: [['link', { href: '/favicon.png', rel: 'icon', type: 'image/png' }]], |
| 87 | + ignoreDeadLinks: true, |
| 88 | + markdown: { |
| 89 | + config(md) { |
| 90 | + md.use(groupIconMdPlugin); |
| 91 | + }, |
| 92 | + lineNumbers: true, |
| 93 | + theme: { |
| 94 | + dark: 'vitesse-dark', |
| 95 | + light: 'vitesse-light', |
| 96 | + }, |
| 97 | + }, |
| 98 | + outDir: 'dist', |
| 99 | + srcDir: 'docs', |
| 100 | + themeConfig: { |
| 101 | + docFooter: { |
| 102 | + next: false, |
| 103 | + prev: false, |
| 104 | + }, |
| 105 | + footer: { |
| 106 | + copyright: 'Copyright © 2012-present hapi.js team', |
| 107 | + message: |
| 108 | + '<a href="https://www.netlify.com" target="_blank"><img src="https://www.netlify.com/assets/badges/netlify-badge-dark.svg" alt="Deploys by Netlify" style="display: inline-block; vertical-align: middle; height: 30px; margin-left: 10px;" /></a>', |
| 109 | + }, |
| 110 | + logo: '/img/hapi.svg', |
| 111 | + nav: [ |
| 112 | + { link: '/', text: 'Home' }, |
| 113 | + { activeMatch: '^/api/', link: `/api/${formatVersion(hapiInfo.versions.at(-1)!.name)}`, text: 'API' }, |
| 114 | + { activeMatch: '^/tutorials/', link: '/tutorials/en_US/getting-started', text: 'Tutorials' }, |
| 115 | + { activeMatch: '^/plugins', link: '/plugins', text: 'Plugins' }, |
| 116 | + { |
| 117 | + activeMatch: '^/resources/', |
| 118 | + link: '/resources/changelog', |
| 119 | + text: 'Resources', |
| 120 | + }, |
| 121 | + { activeMatch: '^/module/', link: '/module/', text: 'Modules' }, |
| 122 | + { activeMatch: '^/policies/', link: '/policies/coc', text: 'Policies' }, |
| 123 | + { link: '/support', text: 'Support' }, |
| 124 | + { link: 'https://hapi.threadless.com', target: '_blank', text: 'Shop' }, |
| 125 | + ], |
| 126 | + outline: { |
| 127 | + label: 'On this page', |
| 128 | + level: 'deep', |
| 129 | + }, |
| 130 | + sidebar: { |
| 131 | + '/api/': [ |
| 132 | + { |
| 133 | + items: [ |
| 134 | + { |
| 135 | + items: [...hapiInfo.versions].toReversed().map((version) => ({ |
| 136 | + link: `/api/${formatVersion(version.name)}`, |
| 137 | + text: formatVersion(version.name), |
| 138 | + })), |
| 139 | + link: `/api/${formatVersion(hapiInfo.versions.at(-1)!.name)}`, |
| 140 | + text: 'API', |
| 141 | + }, |
| 142 | + ], |
| 143 | + text: '@hapi/hapi', |
| 144 | + }, |
| 145 | + ], |
| 146 | + '/module/': [ |
| 147 | + { |
| 148 | + items: [{ link: '/module/', text: 'All Modules' }, ...modulesItems], |
| 149 | + text: 'Modules', |
| 150 | + }, |
| 151 | + ], |
| 152 | + '/plugins': [ |
| 153 | + { |
| 154 | + items: pluginsData.map((category) => ({ |
| 155 | + link: `/plugins#${category.anchor}`, |
| 156 | + text: category.name, |
| 157 | + })), |
| 158 | + text: 'Plugins', |
| 159 | + }, |
| 160 | + ], |
| 161 | + '/policies/': [ |
| 162 | + { |
| 163 | + items: [ |
| 164 | + { link: '/policies/coc', text: 'Code of Conduct' }, |
| 165 | + { link: '/policies/contributing', text: 'Contributing' }, |
| 166 | + { link: '/policies/license', text: 'License' }, |
| 167 | + { link: '/policies/security', text: 'Security' }, |
| 168 | + { link: '/policies/sponsors', text: 'Sponsors' }, |
| 169 | + { link: '/policies/styleguide', text: 'Style Guide' }, |
| 170 | + { link: '/policies/support', text: 'Support' }, |
| 171 | + ], |
| 172 | + text: 'Policies', |
| 173 | + }, |
| 174 | + ], |
| 175 | + '/resources/': [ |
| 176 | + { |
| 177 | + items: [ |
| 178 | + { link: '/resources/changelog', text: 'Changelog' }, |
| 179 | + { link: '/resources/status', text: 'Module Status' }, |
| 180 | + { link: '/resources/list#books', text: 'Books' }, |
| 181 | + { link: '/resources/list#boilerplates', text: 'Boilerplates' }, |
| 182 | + { link: '/resources/list#projects', text: 'Projects' }, |
| 183 | + { link: '/resources/list#videos', text: 'Videos' }, |
| 184 | + ], |
| 185 | + text: 'Resources', |
| 186 | + }, |
| 187 | + ], |
| 188 | + '/tutorials/en_US/': getTutorialSidebar('en_US'), |
| 189 | + '/tutorials/ko_KR/': getTutorialSidebar('ko_KR'), |
| 190 | + '/tutorials/pt_BR/': getTutorialSidebar('pt_BR'), |
| 191 | + '/tutorials/tr_TR/': getTutorialSidebar('tr_TR'), |
| 192 | + '/tutorials/zh_CN/': getTutorialSidebar('zh_CN'), |
| 193 | + ...moduleSidebars, |
| 194 | + }, |
| 195 | + socialLinks: [ |
| 196 | + { icon: 'github', link: 'https://github.com/hapijs/hapi' }, |
| 197 | + { icon: 'slack', link: 'https://join.slack.com/t/hapihour/shared_invite/zt-g5ortpsk-ErlnRA2rUcPIWES21oXBOg' }, |
| 198 | + { icon: 'discord', link: 'https://discord.gg/YYxZhpKKvu' }, |
| 199 | + ], |
| 200 | + }, |
| 201 | + title: 'hapi.dev', |
| 202 | + titleTemplate: 'hapi.dev - :title', |
| 203 | + vite: { |
| 204 | + plugins: [groupIconVitePlugin()], |
| 205 | + }, |
| 206 | +}); |
0 commit comments