|
| 1 | +/** |
| 2 | + * @fileoverview Vitepress site configuration. |
| 3 | + * |
| 4 | + * @see https://vitepress.dev/reference/site-config#site-config |
| 5 | + */ |
| 6 | + |
| 7 | +// -------------------------------------------------------------------------------- |
| 8 | +// Import |
| 9 | +// -------------------------------------------------------------------------------- |
| 10 | + |
| 11 | +import { parse } from 'node:path'; |
| 12 | + |
| 13 | +import { generateGoogleAnalyticsScript } from 'bananass-utils-vitepress/head'; |
| 14 | +import footnote from 'markdown-it-footnote'; |
| 15 | +import { defineConfig } from 'vitepress'; |
| 16 | +import { groupIconMdPlugin, groupIconVitePlugin } from 'vitepress-plugin-group-icons'; |
| 17 | +import { codecovVitePlugin } from '@codecov/vite-plugin'; |
| 18 | +import isInteractive from 'is-interactive'; |
| 19 | +import rules from 'eslint-plugin-mark/rules'; |
| 20 | + |
| 21 | +// -------------------------------------------------------------------------------- |
| 22 | +// Constants |
| 23 | +// -------------------------------------------------------------------------------- |
| 24 | + |
| 25 | +const TITLE = 'eslint-plugin-mark'; |
| 26 | +const DESCRIPTION = 'Lint your Markdown with ESLint.🛠️'; |
| 27 | +const AUTHOR = '루밀LuMir'; |
| 28 | +const SITE_URL = 'https://eslint-plugin-mark.lumir.page'; |
| 29 | +const GITHUB_URL = 'https://github.com/lumirlumir/npm-eslint-plugin-mark'; |
| 30 | +const NPM_URL = 'https://www.npmjs.com'; |
| 31 | +const GOOGLE_GA_ID = 'G-9KLYX5PTLT'; |
| 32 | + |
| 33 | +// -------------------------------------------------------------------------------- |
| 34 | +// Export |
| 35 | +// -------------------------------------------------------------------------------- |
| 36 | + |
| 37 | +export default defineConfig({ |
| 38 | + /* Site Metadata */ |
| 39 | + title: TITLE, |
| 40 | + description: DESCRIPTION, |
| 41 | + head: [ |
| 42 | + // Basic |
| 43 | + ['link', { rel: 'icon', href: '/logo.svg', type: 'image/svg+xml' }], |
| 44 | + ['link', { rel: 'icon', href: '/logo-small.png', type: 'image/png' }], |
| 45 | + ['link', { rel: 'icon', href: '/favicon.ico', type: 'image/x-icon' }], |
| 46 | + ['meta', { name: 'title', content: TITLE }], |
| 47 | + ['meta', { name: 'theme-color', content: '#a0a0f5' }], |
| 48 | + ['meta', { name: 'author', content: AUTHOR }], |
| 49 | + [ |
| 50 | + 'meta', |
| 51 | + { |
| 52 | + name: 'keywords', |
| 53 | + content: 'eslint, plugin, mark, markdown, lint, linting, eslint-plugin-mark', |
| 54 | + }, |
| 55 | + ], |
| 56 | + |
| 57 | + // Open Graph |
| 58 | + ['meta', { property: 'og:type', content: 'website' }], |
| 59 | + ['meta', { property: 'og:url', content: SITE_URL }], |
| 60 | + ['meta', { property: 'og:title', content: TITLE }], |
| 61 | + ['meta', { property: 'og:description', content: DESCRIPTION }], |
| 62 | + ['meta', { property: 'og:image', content: `${SITE_URL}/logo-og.png` }], |
| 63 | + ['meta', { property: 'og:image:width', content: '1280' }], |
| 64 | + ['meta', { property: 'og:image:height', content: '640' }], |
| 65 | + ['meta', { property: 'og:site_name', content: TITLE }], |
| 66 | + ['meta', { property: 'og:article:author', content: AUTHOR }], |
| 67 | + |
| 68 | + // Twitter |
| 69 | + ['meta', { name: 'twitter:url', content: SITE_URL }], |
| 70 | + ['meta', { name: 'twitter:title', content: TITLE }], |
| 71 | + ['meta', { name: 'twitter:description', content: DESCRIPTION }], |
| 72 | + ['meta', { name: 'twitter:image', content: `${SITE_URL}/logo-og.png` }], |
| 73 | + ['meta', { name: 'twitter:creator', content: AUTHOR }], |
| 74 | + ['meta', { name: 'twitter:card', content: 'summary_large_image' }], |
| 75 | + |
| 76 | + // Google Analytics |
| 77 | + ...generateGoogleAnalyticsScript(GOOGLE_GA_ID), |
| 78 | + ], |
| 79 | + lang: 'en-US', |
| 80 | + |
| 81 | + /* Routing */ |
| 82 | + cleanUrls: true, |
| 83 | + |
| 84 | + /* Build */ |
| 85 | + outDir: 'build', |
| 86 | + metaChunk: true, |
| 87 | + |
| 88 | + /* Theming */ |
| 89 | + lastUpdated: true, |
| 90 | + |
| 91 | + /* Sitemap */ |
| 92 | + sitemap: { |
| 93 | + hostname: SITE_URL, |
| 94 | + }, |
| 95 | + |
| 96 | + /* Theme Configuration */ |
| 97 | + themeConfig: { |
| 98 | + logo: { |
| 99 | + src: '/logo.svg', |
| 100 | + alt: 'eslint-plugin-mark Logo', |
| 101 | + }, |
| 102 | + |
| 103 | + outline: { |
| 104 | + level: 'deep', |
| 105 | + }, |
| 106 | + |
| 107 | + nav: [ |
| 108 | + // TODO: From here |
| 109 | + { |
| 110 | + text: 'Get Started', |
| 111 | + activeMatch: '/docs/(?:get-started|community)', |
| 112 | + items: [ |
| 113 | + { |
| 114 | + text: 'Get Started', |
| 115 | + link: '/docs/get-started', |
| 116 | + activeMatch: '/docs/get-started', |
| 117 | + }, |
| 118 | + { |
| 119 | + text: 'Community', |
| 120 | + link: '/docs/community/code-of-conduct', |
| 121 | + activeMatch: '/docs/community', |
| 122 | + }, |
| 123 | + ], |
| 124 | + }, |
| 125 | + { |
| 126 | + text: 'Rules', |
| 127 | + link: '/docs/rules', |
| 128 | + activeMatch: '/docs/rules', |
| 129 | + }, |
| 130 | + { |
| 131 | + text: 'Configs', |
| 132 | + link: '/docs/get-started/configurations', |
| 133 | + activeMatch: '/docs/get-started/configurations', |
| 134 | + }, |
| 135 | + ], |
| 136 | + |
| 137 | + sidebar: { |
| 138 | + '/docs/rules/': [ |
| 139 | + { |
| 140 | + base: '/docs/rules/', |
| 141 | + text: 'Rules', |
| 142 | + link: '/', |
| 143 | + collapsed: false, |
| 144 | + items: Object.keys(rules).map(ruleName => ({ |
| 145 | + text: ruleName, |
| 146 | + link: ruleName, |
| 147 | + })), |
| 148 | + }, |
| 149 | + ], |
| 150 | + |
| 151 | + '/docs/': [ |
| 152 | + { |
| 153 | + base: '/docs/get-started/', |
| 154 | + text: 'Get Started', |
| 155 | + link: '/', |
| 156 | + collapsed: false, // Set it `false` to show `>` icon. |
| 157 | + items: [ |
| 158 | + { |
| 159 | + text: 'Introduction', |
| 160 | + link: 'introduction', |
| 161 | + }, |
| 162 | + { |
| 163 | + text: 'Installation', |
| 164 | + link: 'installation', |
| 165 | + }, |
| 166 | + { |
| 167 | + text: 'Configurations', |
| 168 | + link: 'configurations', |
| 169 | + }, |
| 170 | + { |
| 171 | + text: 'Dependency Versions', |
| 172 | + link: 'dependency-versions', |
| 173 | + }, |
| 174 | + { |
| 175 | + text: 'Versioning', |
| 176 | + link: 'versioning', |
| 177 | + }, |
| 178 | + ], |
| 179 | + }, |
| 180 | + |
| 181 | + { |
| 182 | + base: '/docs/community/', |
| 183 | + text: 'Community', |
| 184 | + collapsed: true, |
| 185 | + items: [ |
| 186 | + { |
| 187 | + text: 'Code of Conduct', |
| 188 | + link: 'code-of-conduct', |
| 189 | + }, |
| 190 | + { |
| 191 | + text: 'Contributing', |
| 192 | + link: 'contributing', |
| 193 | + }, |
| 194 | + { |
| 195 | + text: 'Change Log', |
| 196 | + link: 'change-log', |
| 197 | + }, |
| 198 | + { |
| 199 | + text: 'Security', |
| 200 | + link: 'security', |
| 201 | + }, |
| 202 | + { |
| 203 | + text: 'License', |
| 204 | + link: 'license', |
| 205 | + }, |
| 206 | + ], |
| 207 | + }, |
| 208 | + ], |
| 209 | + }, |
| 210 | + |
| 211 | + socialLinks: [ |
| 212 | + { |
| 213 | + icon: 'npm', |
| 214 | + link: `${NPM_URL}/package/eslint-plugin-mark`, |
| 215 | + ariaLabel: 'npm package link for eslint-plugin-mark', |
| 216 | + }, |
| 217 | + { |
| 218 | + icon: 'github', |
| 219 | + link: GITHUB_URL, |
| 220 | + ariaLabel: 'GitHub repository link for eslint-plugin-mark', |
| 221 | + }, |
| 222 | + ], |
| 223 | + |
| 224 | + editLink: { |
| 225 | + pattern: `${GITHUB_URL}/edit/main/website/:path`, |
| 226 | + text: 'Edit this page on GitHub', |
| 227 | + }, |
| 228 | + |
| 229 | + search: { |
| 230 | + provider: 'local', |
| 231 | + }, |
| 232 | + |
| 233 | + footer: { |
| 234 | + message: 'Released under the MIT License.', |
| 235 | + copyright: `Copyright © 2024-${new Date().getFullYear()} <a href="https://github.com/lumirlumir">${AUTHOR}(lumirlumir)</a>`, |
| 236 | + }, |
| 237 | + }, |
| 238 | + |
| 239 | + markdown: { |
| 240 | + config(md) { |
| 241 | + md.use(footnote); |
| 242 | + md.use(groupIconMdPlugin); |
| 243 | + }, |
| 244 | + }, |
| 245 | + |
| 246 | + vite: { |
| 247 | + plugins: [ |
| 248 | + groupIconVitePlugin(), |
| 249 | + codecovVitePlugin({ |
| 250 | + // Put the Codecov vite plugin after all other plugins |
| 251 | + enableBundleAnalysis: !isInteractive(), // Works only in CI |
| 252 | + bundleName: 'website', |
| 253 | + uploadToken: process.env.CODECOV_TOKEN, |
| 254 | + gitService: 'github', |
| 255 | + }), |
| 256 | + ], |
| 257 | + }, |
| 258 | + |
| 259 | + transformPageData(pageData) { |
| 260 | + // Process only the files inside `docs/rules/`, excluding `index.md`. |
| 261 | + if (/^docs\/rules\/(?!index).+/.test(pageData.relativePath)) { |
| 262 | + const ruleName = parse(pageData.relativePath).name; |
| 263 | + const rule = rules[ruleName]; |
| 264 | + |
| 265 | + pageData.title = ruleName; |
| 266 | + pageData.frontmatter.title = ruleName; |
| 267 | + pageData.frontmatter.rule = ` |
| 268 | +
|
| 269 | +<p> |
| 270 | + ${(rule.meta.docs.recommended ?? false) ? '<code class="rule-emoji">✅ Recommended</code>' : ''} |
| 271 | + ${(rule.meta.fixable ?? false) ? '<code class="rule-emoji">🔧 Fixable</code>' : ''} |
| 272 | + ${(rule.meta.docs.suggestion ?? false) ? '<code class="rule-emoji">💡 Suggestion</code>' : ''} |
| 273 | + ${(rule.meta.dialects.includes('commonmark') ?? false) ? '<code class="rule-emoji">⭐ CommonMark</code>' : ''} |
| 274 | + ${(rule.meta.dialects.includes('gfm') ?? false) ? '<code class="rule-emoji">🌟 GFM</code>' : ''} |
| 275 | +</p> |
| 276 | +<p> |
| 277 | + ${(rule.meta.docs.description ?? '') |
| 278 | + .split(/(`[^`]+`)/) |
| 279 | + .map(part => |
| 280 | + part.startsWith('`') && part.endsWith('`') |
| 281 | + ? `<code>${part.slice(1, -1)}</code>` |
| 282 | + : part, |
| 283 | + ) |
| 284 | + .join('')}. |
| 285 | +</p> |
| 286 | +
|
| 287 | +`; |
| 288 | + } |
| 289 | + |
| 290 | + return pageData; |
| 291 | + }, |
| 292 | +}); |
0 commit comments