|
| 1 | +import { defineConfig } from 'vitepress'; |
| 2 | +import path from 'node:path'; |
| 3 | +import { glossaryAbbr } from 'markdown-it-glossary'; |
| 4 | +import { readingTimeTag } from '@binarynoir/vitepress-reading-time-tag'; |
| 5 | +import { markdownTags, stripTags } from '@binarynoir/vitepress-markdown-tags'; |
| 6 | +import { taggedPagesVitePlugin } from '@binarynoir/vitepress-markdown-tags/vitepress'; |
| 7 | +import { generateNav } from '@binarynoir/vitepress-auto-navbar'; |
| 8 | +import { generateSidebar } from '@binarynoir/vitepress-auto-sidebar'; |
| 9 | +import { imageFallbackPlugin } from '@binarynoir/vite-plugin-image-fallback'; |
| 10 | +import { optimizeImagesPlugin } from '@binarynoir/vite-plugin-optimize-images'; |
| 11 | + |
| 12 | +// import.meta.dirname, not __dirname: VitePress configs are ESM. |
| 13 | +const docsRoot = path.resolve(import.meta.dirname, '..'); |
| 14 | + |
| 15 | +const SITE_URL = 'https://binarynoir.github.io'; |
| 16 | + |
| 17 | +export default defineConfig({ |
| 18 | + title: 'BinaryNoir', |
| 19 | + description: 'Open-source tools and VitePress plugins by BinaryNoir, with live demos.', |
| 20 | + lang: 'en-US', |
| 21 | + cleanUrls: true, |
| 22 | + lastUpdated: true, |
| 23 | + |
| 24 | + sitemap: { hostname: SITE_URL }, |
| 25 | + |
| 26 | + head: [ |
| 27 | + ['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }], |
| 28 | + ['meta', { name: 'theme-color', content: '#7a5add' }], |
| 29 | + ['meta', { property: 'og:type', content: 'website' }], |
| 30 | + ['meta', { property: 'og:title', content: 'BinaryNoir' }], |
| 31 | + [ |
| 32 | + 'meta', |
| 33 | + { |
| 34 | + property: 'og:description', |
| 35 | + content: 'Open-source tools and VitePress plugins by BinaryNoir, with live demos.', |
| 36 | + }, |
| 37 | + ], |
| 38 | + ['meta', { property: 'og:url', content: SITE_URL }], |
| 39 | + ], |
| 40 | + |
| 41 | + themeConfig: { |
| 42 | + logo: '/logo.svg', |
| 43 | + |
| 44 | + // @binarynoir/vitepress-auto-navbar: top nav built from the folder tree. |
| 45 | + // `.nav` files set order and titles; `.inherit` borrows titles from `.sidebar`. |
| 46 | + nav: generateNav(docsRoot, { |
| 47 | + maxDepth: 2, |
| 48 | + configFilenames: ['.nav', '.sidebar'], |
| 49 | + }), |
| 50 | + |
| 51 | + // @binarynoir/vitepress-auto-sidebar: one sidebar per top-level folder. |
| 52 | + sidebar: generateSidebar(docsRoot, { |
| 53 | + maxDepth: 3, |
| 54 | + maxTitleLength: 50, |
| 55 | + }), |
| 56 | + |
| 57 | + socialLinks: [{ icon: 'github', link: 'https://github.com/binarynoir' }], |
| 58 | + |
| 59 | + search: { provider: 'local' }, |
| 60 | + |
| 61 | + editLink: { |
| 62 | + pattern: 'https://github.com/binarynoir/binarynoir.github.io/edit/main/docs/:path', |
| 63 | + text: 'Suggest a change to this page', |
| 64 | + }, |
| 65 | + |
| 66 | + footer: { |
| 67 | + message: 'Released under the MIT License. Built with VitePress and the plugins it documents.', |
| 68 | + copyright: 'Copyright © John Smith III / BinaryNoir', |
| 69 | + }, |
| 70 | + }, |
| 71 | + |
| 72 | + markdown: { |
| 73 | + theme: { light: 'github-light', dark: 'github-dark' }, |
| 74 | + config(md) { |
| 75 | + // markdown-it-glossary: hover definitions from docs/glossary.md on every page. |
| 76 | + // A page opts out with `glossary: false` in its frontmatter. |
| 77 | + md.use(glossaryAbbr, { file: path.join(docsRoot, 'glossary.md') }); |
| 78 | + // @binarynoir/vitepress-reading-time-tag: [[readingTime]] becomes a tip block. |
| 79 | + md.use(readingTimeTag); |
| 80 | + // @binarynoir/vitepress-markdown-tags: ((tag|Done|green)) becomes a badge. |
| 81 | + md.use(markdownTags); |
| 82 | + }, |
| 83 | + }, |
| 84 | + |
| 85 | + // Keep ((tag|...)) syntax out of <title>, search results and the page outline. |
| 86 | + transformPageData(pageData) { |
| 87 | + if (typeof pageData.title === 'string') { |
| 88 | + pageData.title = stripTags(pageData.title); |
| 89 | + } |
| 90 | + if (typeof pageData.frontmatter?.title === 'string') { |
| 91 | + pageData.frontmatter.title = stripTags(pageData.frontmatter.title); |
| 92 | + } |
| 93 | + }, |
| 94 | + |
| 95 | + vite: { |
| 96 | + plugins: [ |
| 97 | + // Missing image imports become a placeholder plus a console warning |
| 98 | + // instead of failing the build. |
| 99 | + imageFallbackPlugin(), |
| 100 | + // Re-compress PNG/JPEG/WebP in the build output. Source files are untouched. |
| 101 | + optimizeImagesPlugin({ verbose: true }), |
| 102 | + // Keeps `tagged: true` pages current while running `vitepress dev`. |
| 103 | + taggedPagesVitePlugin(), |
| 104 | + ], |
| 105 | + }, |
| 106 | +}); |
0 commit comments