From 340c3db383d9df2eaf791807210d41c3c248caaa Mon Sep 17 00:00:00 2001 From: zguiyang Date: Wed, 18 Mar 2026 08:20:13 +0800 Subject: [PATCH] feat: add SEO infrastructure, 404 page, accessibility and performance optimizations - Add robots.txt for search engine crawling - Enhance Layout.astro with complete SEO meta tags (OG, Twitter Card, canonical) - Create custom 404 page with bilingual support - Add skip link for accessibility - Add main-content id to all major pages for keyboard navigation - Add lazy loading to blog list and author card images --- public/robots.txt | 13 ++++++++ src/components/AuthorCard.tsx | 6 ++-- src/components/blog/BlogList.astro | 6 ++-- src/layouts/Layout.astro | 49 +++++++++++++++++++++++++--- src/pages/404.astro | 52 ++++++++++++++++++++++++++++++ src/pages/about.astro | 2 +- src/pages/hire.astro | 2 +- src/pages/index.astro | 2 +- src/pages/now.astro | 2 +- src/pages/projects.astro | 2 +- src/pages/zh/about.astro | 2 +- src/pages/zh/hire.astro | 2 +- src/pages/zh/index.astro | 2 +- src/pages/zh/now.astro | 2 +- src/pages/zh/projects.astro | 2 +- 15 files changed, 128 insertions(+), 18 deletions(-) create mode 100644 public/robots.txt create mode 100644 src/pages/404.astro diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..32a761b --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,13 @@ +# robots.txt for zhaoguiyang.com +# https://zhaoguiyang.com + +User-agent: * +Allow: / + +# Sitemap +Sitemap: https://zhaoguiyang.com/sitemap-index.xml + +# Disallow admin/private areas (if any) +Disallow: /api/ +Disallow: /_astro/ +Disallow: /assets/ diff --git a/src/components/AuthorCard.tsx b/src/components/AuthorCard.tsx index 9ffca7a..f778183 100644 --- a/src/components/AuthorCard.tsx +++ b/src/components/AuthorCard.tsx @@ -26,9 +26,11 @@ export default function AuthorCard({ lang, author }: AuthorCardProps) {
{authorInfo.avatar ? ( - {authorInfo.name} ) : ( diff --git a/src/components/blog/BlogList.astro b/src/components/blog/BlogList.astro index 4b19d8a..1e1f50a 100644 --- a/src/components/blog/BlogList.astro +++ b/src/components/blog/BlogList.astro @@ -80,9 +80,11 @@ const readMoreText = lang === 'zh' ? '阅读更多' : 'Read More';
{/* Featured Image */}
- {post.title}
diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index c262de6..cd35352 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -4,17 +4,27 @@ import BackToTop from "@/components/ui/back-to-top"; import { useTranslations } from "@/i18n/utils"; import type { Lang } from "@/types/i18n"; import { defaultLang } from "@/i18n/ui"; +import { personalInfo } from "@/lib/data"; import "../styles/global.css"; interface Props { title?: string; description?: string; + image?: string; + articleDate?: string; } const lang = Astro.currentLocale as Lang || defaultLang; -const { title = "Joey Z. - Portfolio", description = "Engineering-focused personal website" } = - Astro.props; +const isZh = lang === 'zh'; const t = useTranslations(lang); +const { title, description, image, articleDate } = Astro.props; +const siteTitle = t("site.title"); +const fullTitle = title ? `${title} | ${siteTitle}` : siteTitle; +const siteUrl = "https://zhaoguiyang.com"; +const defaultImage = "https://images.unsplash.com/photo-1516321318423-f06f85e504b3?w=1200&h=630&fit=crop"; + +const currentUrl = Astro.url.href; +const ogImage = image || defaultImage; --- @@ -27,8 +37,31 @@ const t = useTranslations(lang); - - {title} | {t("site.title")} + + + + + + + + + + + + + + + + + + + + + + {articleDate && } + + {fullTitle} + @@ -41,6 +74,14 @@ const t = useTranslations(lang); + + + {isZh ? '跳到主要内容' : 'Skip to main content'} + +
diff --git a/src/pages/404.astro b/src/pages/404.astro new file mode 100644 index 0000000..1b273ae --- /dev/null +++ b/src/pages/404.astro @@ -0,0 +1,52 @@ +--- +import Layout from '@/layouts/Layout.astro'; +import GlassHeader from '@/components/GlassHeader'; +import Footer from '@/components/Footer'; +import Container from '@/components/ui/Container.astro'; +import { getLocalizedPath } from '@/i18n/utils'; +import type { Lang } from '@/types/i18n'; +import { defaultLang } from '@/i18n/ui'; + +const lang = (Astro.currentLocale as Lang) || defaultLang; +const isZh = lang === 'zh'; +const homePath = getLocalizedPath('/', lang); +--- + + + + +
+ +
+

404

+

+ {isZh ? '页面未找到' : 'Page Not Found'} +

+

+ {isZh + ? '抱歉,您访问的页面不存在或已被移除。' + : 'Sorry, the page you are looking for does not exist or has been moved.'} +

+ +
+
+
+ +