|
| 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 joiInfo from '../generated/modules/joi/info.json' with { type: 'json' }; |
| 6 | +import { formatVersion } from './utils.js'; |
| 7 | + |
| 8 | +const modulesItems = Object.keys(modulesData) |
| 9 | + .filter((name) => name !== 'joi') |
| 10 | + .map((name) => ({ |
| 11 | + link: `/module/${name}/install`, |
| 12 | + text: name, |
| 13 | + })); |
| 14 | + |
| 15 | +const getModuleSidebar = (moduleName: string) => { |
| 16 | + const moduleData = modulesData[moduleName as keyof typeof modulesData]; |
| 17 | + return [ |
| 18 | + { |
| 19 | + items: [{ link: '/module/', text: 'All Modules' }, ...modulesItems], |
| 20 | + text: 'Modules', |
| 21 | + }, |
| 22 | + { |
| 23 | + items: [ |
| 24 | + { link: `/module/${moduleName}/install`, text: 'Installation' }, |
| 25 | + { |
| 26 | + items: moduleData.versions.map((version) => ({ |
| 27 | + link: `/module/${moduleName}/api/${formatVersion(version.name)}`, |
| 28 | + text: formatVersion(version.name), |
| 29 | + })), |
| 30 | + link: `/module/${moduleName}/api/${formatVersion(moduleData.versions[0].name)}`, |
| 31 | + text: 'API', |
| 32 | + }, |
| 33 | + { link: `/module/${moduleName}/changelog`, text: 'Changelog' }, |
| 34 | + ], |
| 35 | + text: moduleName, |
| 36 | + }, |
| 37 | + ]; |
| 38 | +}; |
| 39 | + |
| 40 | +const moduleSidebars = Object.fromEntries( |
| 41 | + Object.keys(modulesData) |
| 42 | + .filter((name) => name !== 'joi') |
| 43 | + .map((name) => [`/module/${name}/`, getModuleSidebar(name)]), |
| 44 | +); |
| 45 | + |
| 46 | +export default defineConfig({ |
| 47 | + appearance: true, |
| 48 | + cleanUrls: true, |
| 49 | + description: 'The most powerful data validation library for JS', |
| 50 | + head: [['link', { href: '/favicon2.png', rel: 'icon' }]], |
| 51 | + markdown: { |
| 52 | + config(md) { |
| 53 | + md.use(groupIconMdPlugin); |
| 54 | + }, |
| 55 | + lineNumbers: true, |
| 56 | + theme: { |
| 57 | + dark: 'vitesse-dark', |
| 58 | + light: 'vitesse-light', |
| 59 | + }, |
| 60 | + }, |
| 61 | + outDir: 'dist', |
| 62 | + srcDir: 'docs', |
| 63 | + themeConfig: { |
| 64 | + docFooter: { |
| 65 | + next: false, |
| 66 | + prev: false, |
| 67 | + }, |
| 68 | + footer: { |
| 69 | + copyright: 'Copyright © 2012-present hapi.js team', |
| 70 | + message: |
| 71 | + '<a href="https://www.netlify.com" target="_blank"><img src="https://www.netlify.com/img/global/badges/netlify-dark.svg" alt="Deploys by Netlify" style="display: inline-block; vertical-align: middle; height: 20px; margin-left: 10px;" /></a>', |
| 72 | + }, |
| 73 | + logo: '/img/joiTransparent.png', |
| 74 | + nav: [ |
| 75 | + { link: '/', text: 'Home' }, |
| 76 | + { activeMatch: '^/api/', link: `/api/${formatVersion(joiInfo.versionsArray[0])}`, text: 'API' }, |
| 77 | + { |
| 78 | + activeMatch: '^/resources/', |
| 79 | + link: '/resources/changelog', |
| 80 | + text: 'Resources', |
| 81 | + }, |
| 82 | + { activeMatch: '^/module/', link: '/module/', text: 'Modules' }, |
| 83 | + { activeMatch: '^/policies/', link: '/policies/coc', text: 'Policies' }, |
| 84 | + { activeMatch: '^/tester/', link: '/tester/', text: 'Sandbox' }, |
| 85 | + ], |
| 86 | + outline: { |
| 87 | + label: 'On this page', |
| 88 | + level: 'deep', |
| 89 | + }, |
| 90 | + sidebar: { |
| 91 | + '/api/': [ |
| 92 | + { |
| 93 | + items: [ |
| 94 | + { |
| 95 | + items: joiInfo.versionsArray.map((version) => ({ |
| 96 | + link: `/api/${formatVersion(version)}`, |
| 97 | + text: formatVersion(version), |
| 98 | + })), |
| 99 | + link: `/api/${formatVersion(joiInfo.versionsArray[0])}`, |
| 100 | + text: 'API', |
| 101 | + }, |
| 102 | + ], |
| 103 | + text: 'joi', |
| 104 | + }, |
| 105 | + ], |
| 106 | + '/module/': [ |
| 107 | + { |
| 108 | + items: [{ link: '/module/', text: 'All Modules' }, ...modulesItems], |
| 109 | + text: 'Modules', |
| 110 | + }, |
| 111 | + ], |
| 112 | + '/policies/': [ |
| 113 | + { |
| 114 | + items: [ |
| 115 | + { link: '/policies/coc', text: 'Code of Conduct' }, |
| 116 | + { link: '/policies/contributing', text: 'Contributing' }, |
| 117 | + { link: '/policies/license', text: 'License' }, |
| 118 | + { link: '/policies/security', text: 'Security' }, |
| 119 | + { link: '/policies/styleguide', text: 'Style Guide' }, |
| 120 | + { link: '/policies/support', text: 'Support' }, |
| 121 | + ], |
| 122 | + text: 'Policies', |
| 123 | + }, |
| 124 | + ], |
| 125 | + '/resources/': [ |
| 126 | + { |
| 127 | + items: [ |
| 128 | + { link: '/resources/changelog', text: 'Changelog' }, |
| 129 | + { link: '/resources/status', text: 'Module Status' }, |
| 130 | + ], |
| 131 | + text: 'Resources', |
| 132 | + }, |
| 133 | + ], |
| 134 | + '/tester/': [ |
| 135 | + { |
| 136 | + items: joiInfo.versionsArray.map((version) => ({ |
| 137 | + link: `/tester/${formatVersion(version)}`, |
| 138 | + text: formatVersion(version), |
| 139 | + })), |
| 140 | + text: 'Versions', |
| 141 | + }, |
| 142 | + ], |
| 143 | + ...moduleSidebars, |
| 144 | + }, |
| 145 | + socialLinks: [{ icon: 'github', link: 'https://github.com/hapijs/joi' }], |
| 146 | + }, |
| 147 | + title: 'joi.dev', |
| 148 | + titleTemplate: 'joi.dev - :title', |
| 149 | + vite: { |
| 150 | + plugins: [groupIconVitePlugin()], |
| 151 | + }, |
| 152 | +}); |
0 commit comments