|
8 | 8 | groupIconVitePlugin, |
9 | 9 | } from 'vitepress-plugin-group-icons' |
10 | 10 |
|
11 | | - |
12 | 11 | import { markdownItImageSize } from 'markdown-it-image-size' |
13 | 12 | import packageJson from '../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' }], |
@@ -475,16 +450,34 @@ export default defineConfig({ |
475 | 450 | level: [2, 3], |
476 | 451 | }, |
477 | 452 | }, |
478 | | - transformPageData(pageData) { |
479 | | - const canonicalUrl = `${ogUrl}/${pageData.relativePath}` |
480 | | - .replace(/\/index\.md$/, '/') |
481 | | - .replace(/\.md$/, '') |
482 | | - pageData.frontmatter.head ??= [] |
483 | | - pageData.frontmatter.head.unshift( |
484 | | - ['link', { rel: 'canonical', href: canonicalUrl }], |
485 | | - ['meta', { property: 'og:title', content: pageData.title }], |
486 | | - ) |
487 | | - return pageData |
| 453 | + transformHead(ctx) { |
| 454 | + const path = ctx.page.replace(/(^|\/)index\.md$/, '$1').replace(/\.md$/, '') |
| 455 | + |
| 456 | + if (path !== '404') { |
| 457 | + const canonicalUrl = path ? `${ogUrl}/${path}` : ogUrl |
| 458 | + ctx.head.push( |
| 459 | + ['link', { rel: 'canonical', href: canonicalUrl }], |
| 460 | + ['meta', { property: 'og:title', content: ctx.pageData.title }], |
| 461 | + ) |
| 462 | + } |
| 463 | + |
| 464 | + // For the landing page, move the google font links to the top for better performance |
| 465 | + if (path === '') { |
| 466 | + const googleFontLinks: HeadConfig[] = [] |
| 467 | + for (let i = 0; i < ctx.head.length; i++) { |
| 468 | + const tag = ctx.head[i] |
| 469 | + if ( |
| 470 | + tag[0] === 'link' && |
| 471 | + (tag[1]?.href?.includes('fonts.googleapis.com') || |
| 472 | + tag[1]?.href?.includes('fonts.gstatic.com')) |
| 473 | + ) { |
| 474 | + ctx.head.splice(i, 1) |
| 475 | + googleFontLinks.push(tag) |
| 476 | + i-- |
| 477 | + } |
| 478 | + } |
| 479 | + ctx.head.unshift(...googleFontLinks) |
| 480 | + } |
488 | 481 | }, |
489 | 482 | markdown: { |
490 | 483 | // languages used for twoslash and jsdocs in twoslash |
|
0 commit comments