From a48f161647711f3fee956aeb2c2b9dc6f8820177 Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 7 Aug 2025 04:36:53 +0800 Subject: [PATCH] docs: SEO improvements --- docs/.vitepress/config/en.ts | 1 + docs/.vitepress/config/shared.ts | 63 +++++++++++++++++------ docs/openapi-ts/plugins/fastify.md | 5 +- docs/openapi-ts/plugins/tanstack-query.md | 5 +- docs/openapi-ts/plugins/valibot.md | 5 +- docs/openapi-ts/plugins/zod.md | 5 +- docs/openapi-ts/plugins/zod/mini.md | 5 +- docs/openapi-ts/plugins/zod/v3.md | 5 +- docs/public/robots.txt | 4 ++ 9 files changed, 69 insertions(+), 29 deletions(-) create mode 100644 docs/public/robots.txt diff --git a/docs/.vitepress/config/en.ts b/docs/.vitepress/config/en.ts index 4b554f111..3fc19189e 100644 --- a/docs/.vitepress/config/en.ts +++ b/docs/.vitepress/config/en.ts @@ -305,4 +305,5 @@ export default defineConfig({ }, ], }, + title: 'Hey API', }); diff --git a/docs/.vitepress/config/shared.ts b/docs/.vitepress/config/shared.ts index ccc56c761..1814ad940 100644 --- a/docs/.vitepress/config/shared.ts +++ b/docs/.vitepress/config/shared.ts @@ -1,5 +1,7 @@ import { defineConfig, type HeadConfig } from 'vitepress'; +const domain = process.env.SITE_DOMAIN || 'http://localhost:5173'; + export default defineConfig({ cleanUrls: true, head: [ @@ -30,19 +32,6 @@ export default defineConfig({ type: 'image/png', }, ], - ['meta', { content: 'website', property: 'og:type' }], - ['meta', { content: 'en', property: 'og:locale' }], - [ - 'meta', - { - content: - '🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more.', - property: 'og:title', - }, - ], - ['meta', { content: 'OpenAPI TypeScript', property: 'og:site_name' }], - ['meta', { content: '/images/logo-640w.png', property: 'og:image' }], - ['meta', { content: 'https://heyapi.dev', property: 'og:url' }], [ 'script', {}, @@ -52,10 +41,14 @@ export default defineConfig({ 'script', { defer: '', src: '/_vercel/insights/script.js' }, ], - ].filter(Boolean) as HeadConfig[], - lastUpdated: false, + ].filter(Boolean) as Array, + lastUpdated: true, sitemap: { - hostname: 'https://heyapi.dev', + hostname: domain, + lastmodDateOnly: true, + // filter out everything but index and `openapi-ts` pages + transformItems: (items) => + items.filter((item) => !item.url || item.url.startsWith('openapi-ts')), }, themeConfig: { externalLinkIcon: true, @@ -69,5 +62,41 @@ export default defineConfig({ { icon: 'github', link: 'https://github.com/hey-api/openapi-ts' }, ], }, - title: 'Hey API', + transformPageData: (pageData, context) => { + pageData.frontmatter.head ??= []; + + const canonicalUrl = pageData.relativePath + .replace(/index\.md$/, '') + .replace(/\.md$/, context.siteConfig.cleanUrls ? '' : '.html'); + const url = `${domain}/${canonicalUrl}`; + + const head: Array = pageData.frontmatter.head; + head.unshift( + ['link', { href: url, rel: 'canonical' }], + ['meta', { content: 'website', property: 'og:type' }], + ['meta', { content: 'en_US', property: 'og:locale' }], + ['meta', { content: 'Hey API', property: 'og:site_name' }], + [ + 'meta', + { content: `${domain}/images/logo-640w.png`, property: 'og:image' }, + ], + ['meta', { content: url, property: 'og:url' }], + [ + 'meta', + { + content: + pageData.frontmatter.description || + '🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more.', + property: 'og:description', + }, + ], + [ + 'meta', + { + content: pageData.frontmatter.title || 'OpenAPI TypeScript', + property: 'og:title', + }, + ], + ); + }, }); diff --git a/docs/openapi-ts/plugins/fastify.md b/docs/openapi-ts/plugins/fastify.md index fcf5d43a3..85d891cc9 100644 --- a/docs/openapi-ts/plugins/fastify.md +++ b/docs/openapi-ts/plugins/fastify.md @@ -1,6 +1,6 @@ --- -title: Fastify -description: Fastify plugin for Hey API. Compatible with all our features. +title: Fastify v5 Plugin +description: Generate Fastify v5 route handlers from OpenAPI with the Fastify plugin for openapi-ts. Fully compatible with validators, transformers, and all core features. --- @@ -30,6 +30,7 @@ StackBlitz ## Features +- Fastify v5 support - seamless integration with `@hey-api/openapi-ts` ecosystem - type-safe route handlers - minimal learning curve thanks to extending the underlying technology diff --git a/docs/openapi-ts/plugins/tanstack-query.md b/docs/openapi-ts/plugins/tanstack-query.md index 8bf7a5612..6125b182b 100644 --- a/docs/openapi-ts/plugins/tanstack-query.md +++ b/docs/openapi-ts/plugins/tanstack-query.md @@ -1,6 +1,6 @@ --- -title: TanStack Query -description: TanStack Query plugin for Hey API. Compatible with all our features. +title: TanStack Query v5 Plugin +description: Generate TanStack Query v5 functions and query keys from OpenAPI with the TanStack Query plugin for openapi-ts. Fully compatible with validators, transformers, and all core features. ---