Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vitepress/cache
.vitepress/.temp
dist
node_modules
63 changes: 28 additions & 35 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
groupIconVitePlugin,
} from 'vitepress-plugin-group-icons'


import { markdownItImageSize } from 'markdown-it-image-size'
import packageJson from '../package.json' with { type: 'json' }
import { buildEnd } from './buildEnd.config'
Expand Down Expand Up @@ -95,30 +94,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' }],
Expand Down Expand Up @@ -475,16 +450,34 @@ export default defineConfig({
level: [2, 3],
},
},
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
Expand Down
16 changes: 16 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---

<script setup>
Expand Down