|
8 | 8 | groupIconVitePlugin, |
9 | 9 | } from 'vitepress-plugin-group-icons' |
10 | 10 | import llmstxt from 'vitepress-plugin-llms' |
11 | | -import type { PluginOption } from 'vite' |
12 | 11 | import { markdownItImageSize } from 'markdown-it-image-size' |
13 | 12 | import packageJson from '../../packages/vite/package.json' with { type: 'json' } |
14 | 13 | import { buildEnd } from './buildEnd.config' |
@@ -95,30 +94,6 @@ export default defineConfig({ |
95 | 94 | 'link', |
96 | 95 | { rel: 'alternate', type: 'application/rss+xml', href: '/blog.rss' }, |
97 | 96 | ], |
98 | | - ['link', { rel: 'preconnect', href: 'https://fonts.googleapis.com' }], |
99 | | - [ |
100 | | - 'link', |
101 | | - { |
102 | | - rel: 'preconnect', |
103 | | - href: 'https://fonts.gstatic.com', |
104 | | - crossorigin: 'true', |
105 | | - }, |
106 | | - ], |
107 | | - [ |
108 | | - 'link', |
109 | | - { |
110 | | - rel: 'preload', |
111 | | - href: 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Manrope:wght@600&family=IBM+Plex+Mono:wght@400&display=swap', |
112 | | - as: 'style', |
113 | | - }, |
114 | | - ], |
115 | | - [ |
116 | | - 'link', |
117 | | - { |
118 | | - rel: 'stylesheet', |
119 | | - href: 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Manrope:wght@600&family=IBM+Plex+Mono:wght@400&display=swap', |
120 | | - }, |
121 | | - ], |
122 | 97 | inlineScript('banner.js'), |
123 | 98 | ['link', { rel: 'me', href: 'https://m.webtoo.ls/@vite' }], |
124 | 99 | ['meta', { property: 'og:type', content: 'website' }], |
@@ -468,16 +443,34 @@ export default defineConfig({ |
468 | 443 | level: [2, 3], |
469 | 444 | }, |
470 | 445 | }, |
471 | | - transformPageData(pageData) { |
472 | | - const canonicalUrl = `${ogUrl}/${pageData.relativePath}` |
473 | | - .replace(/\/index\.md$/, '/') |
474 | | - .replace(/\.md$/, '') |
475 | | - pageData.frontmatter.head ??= [] |
476 | | - pageData.frontmatter.head.unshift( |
477 | | - ['link', { rel: 'canonical', href: canonicalUrl }], |
478 | | - ['meta', { property: 'og:title', content: pageData.title }], |
479 | | - ) |
480 | | - return pageData |
| 446 | + transformHead(ctx) { |
| 447 | + const path = ctx.page.replace(/(^|\/)index\.md$/, '$1').replace(/\.md$/, '') |
| 448 | + |
| 449 | + if (path !== '404') { |
| 450 | + const canonicalUrl = path ? `${ogUrl}/${path}` : ogUrl |
| 451 | + ctx.head.push( |
| 452 | + ['link', { rel: 'canonical', href: canonicalUrl }], |
| 453 | + ['meta', { property: 'og:title', content: ctx.pageData.title }], |
| 454 | + ) |
| 455 | + } |
| 456 | + |
| 457 | + // For the landing page, move the google font links to the top for better performance |
| 458 | + if (path === '') { |
| 459 | + const googleFontLinks: HeadConfig[] = [] |
| 460 | + for (let i = 0; i < ctx.head.length; i++) { |
| 461 | + const tag = ctx.head[i] |
| 462 | + if ( |
| 463 | + tag[0] === 'link' && |
| 464 | + (tag[1]?.href?.includes('fonts.googleapis.com') || |
| 465 | + tag[1]?.href?.includes('fonts.gstatic.com')) |
| 466 | + ) { |
| 467 | + ctx.head.splice(i, 1) |
| 468 | + googleFontLinks.push(tag) |
| 469 | + i-- |
| 470 | + } |
| 471 | + } |
| 472 | + ctx.head.unshift(...googleFontLinks) |
| 473 | + } |
481 | 474 | }, |
482 | 475 | markdown: { |
483 | 476 | // languages used for twoslash and jsdocs in twoslash |
@@ -520,7 +513,7 @@ Vite is a new breed of frontend build tooling that significantly improves the fr |
520 | 513 | - A [build command](https://vite.dev/guide/build.md) that bundles your code with [Rollup](https://rollupjs.org), pre-configured to output highly optimized static assets for production. |
521 | 514 |
|
522 | 515 | In addition, Vite is highly extensible via its [Plugin API](https://vite.dev/guide/api-plugin.md) and [JavaScript API](https://vite.dev/guide/api-javascript.md) with full typing support.`, |
523 | | - }) as PluginOption, |
| 516 | + }), |
524 | 517 | ], |
525 | 518 | optimizeDeps: { |
526 | 519 | include: [ |
|
0 commit comments