diff --git a/.vitepress/config.ts b/.vitepress/config.ts index 0dec9ec8..c31bc5a8 100644 --- a/.vitepress/config.ts +++ b/.vitepress/config.ts @@ -59,30 +59,6 @@ export default defineConfig({ 'link', { rel: 'alternate', type: 'application/rss+xml', href: '/blog.rss' } ], - ['link', { rel: 'preconnect', href: 'https://fonts.googleapis.com' }], - [ - 'link', - { - rel: 'preconnect', - href: 'https://fonts.gstatic.com', - crossorigin: 'true' - } - ], - [ - 'link', - { - rel: 'preload', - href: 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Manrope:wght@600&family=IBM+Plex+Mono:wght@400&display=swap', - as: 'style' - } - ], - [ - 'link', - { - rel: 'stylesheet', - href: 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Manrope:wght@600&family=IBM+Plex+Mono:wght@400&display=swap' - } - ], inlineScript('banner.js'), ['link', { rel: 'me', href: 'https://m.webtoo.ls/@vite' }], ['meta', { property: 'og:type', content: 'website' }], @@ -449,16 +425,34 @@ export default defineConfig({ ] } }, - transformPageData(pageData) { - const canonicalUrl = `${ogUrl}/${pageData.relativePath}` - .replace(/\/index\.md$/, '/') - .replace(/\.md$/, '') - pageData.frontmatter.head ??= [] - pageData.frontmatter.head.unshift( - ['link', { rel: 'canonical', href: canonicalUrl }], - ['meta', { property: 'og:title', content: pageData.title }] - ) - return pageData + transformHead(ctx) { + const path = ctx.page.replace(/(^|\/)index\.md$/, '$1').replace(/\.md$/, '') + + if (path !== '404') { + const canonicalUrl = path ? `${ogUrl}/${path}` : ogUrl + ctx.head.push( + ['link', { rel: 'canonical', href: canonicalUrl }], + ['meta', { property: 'og:title', content: ctx.pageData.title }], + ) + } + + // For the landing page, move the google font links to the top for better performance + if (path === '') { + const googleFontLinks: HeadConfig[] = [] + for (let i = 0; i < ctx.head.length; i++) { + const tag = ctx.head[i] + if ( + tag[0] === 'link' && + (tag[1]?.href?.includes('fonts.googleapis.com') || + tag[1]?.href?.includes('fonts.gstatic.com')) + ) { + ctx.head.splice(i, 1) + googleFontLinks.push(tag) + i-- + } + } + ctx.head.unshift(...googleFontLinks) + } }, markdown: { // languages used for twoslash and jsdocs in twoslash diff --git a/guide/rolldown.md b/guide/rolldown.md index 87e9b8f8..c3426d7f 100644 --- a/guide/rolldown.md +++ b/guide/rolldown.md @@ -36,7 +36,7 @@ Rolldown 专注于三个主要原则: ```json { - "dependencies": { + "devDependencies": { "vite": "^7.0.0" // [!code --] "vite": "npm:rolldown-vite@latest" // [!code ++] } diff --git a/index.md b/index.md index c99b6cd1..3604ab3e 100644 --- a/index.md +++ b/index.md @@ -9,6 +9,22 @@ layout: home aside: false editLink: false markdownStyles: false + +head: + - - link + - rel: preconnect + href: https://fonts.googleapis.com + - - link + - rel: preconnect + href: https://fonts.gstatic.com + crossorigin: '' + - - link + - rel: preload + href: https://fonts.googleapis.com/css2?family=Manrope:wght@600&family=IBM+Plex+Mono:wght@400&display=swap + as: style + - - link + - rel: stylesheet + href: https://fonts.googleapis.com/css2?family=Manrope:wght@600&family=IBM+Plex+Mono:wght@400&display=swap ---