Pārlūkot izejas kodu

fix: comprehensive SEO best practices improvements

- Add dynamic OG image generation via opengraph-image.tsx
- Fix blog post metadata: real descriptions extracted from content, cover images in OG tags, publishedTime/modifiedTime
- Enrich Article JSON-LD with datePublished, dateModified, image, description, mainEntityOfPage
- Fix heading hierarchy: h3→h2 for blog titles, h3→<time> for dates
- Add aria-labels to all icon-only buttons for accessibility
- Add keyboard accessibility to MiniPic interactive div
- Create custom 404 page matching site light/dark theme
- Use actual lastEditedAt in sitemap instead of current timestamp
- Add lastEditedAt and description fields to Blog type

https://claude.ai/code/session_01EehUnAjENF3faiEauSyCsN
Claude 9 mēneši atpakaļ
vecāks
revīzija
9640d29a69

+ 38 - 5
app/blog/[blogId]/page.tsx

@@ -1,7 +1,11 @@
 import { Metadata } from "next";
 
 import { NotionPage } from "@/components/notion-page";
-import { getPageContent } from "@/lib/notion";
+import {
+  getPageContent,
+  extractDescription,
+  customMapImageUrl,
+} from "@/lib/notion";
 import { siteConfig } from "@/config/site";
 
 export const revalidate = 3600;
@@ -12,27 +16,40 @@ export async function generateMetadata({
   params: Promise<{ blogId: string }>;
 }): Promise<Metadata> {
   const { blogId } = await params;
-  const { title } = await getPageContent(blogId);
+  const { title, recordMap } = await getPageContent(blogId);
 
   const postTitle = title || "Blog Post";
+  const description =
+    extractDescription(recordMap) ||
+    `${postTitle} - by ${siteConfig.author}`;
+
+  const block = recordMap.block[blogId]?.value;
+  const coverUrl = block?.format?.page_cover;
+  const ogImages = coverUrl
+    ? [{ url: customMapImageUrl(coverUrl, block), alt: postTitle }]
+    : [{ url: "/og-image.png", alt: postTitle }];
 
   return {
     title: postTitle,
-    description: `${postTitle} - by ${siteConfig.author}`,
+    description,
     alternates: {
       canonical: `/blog/${blogId}`,
     },
     openGraph: {
       title: postTitle,
-      description: `${postTitle} - by ${siteConfig.author}`,
+      description,
       type: "article",
       url: `/blog/${blogId}`,
       authors: [siteConfig.author],
+      publishedTime: new Date(block?.created_time).toISOString(),
+      modifiedTime: new Date(block?.last_edited_time).toISOString(),
+      images: ogImages,
     },
     twitter: {
       card: "summary_large_image",
       title: postTitle,
-      description: `${postTitle} - by ${siteConfig.author}`,
+      description,
+      images: ogImages.map((img) => img.url),
     },
   };
 }
@@ -45,10 +62,22 @@ export default async function Page({
   const { blogId } = await params;
   const { recordMap, title } = await getPageContent(blogId);
 
+  const block = recordMap.block[blogId]?.value;
+  const coverUrl = block?.format?.page_cover;
+  const description =
+    extractDescription(recordMap) ||
+    `${title} - by ${siteConfig.author}`;
+
   const jsonLd = {
     "@context": "https://schema.org",
     "@type": "Article",
     headline: title,
+    description,
+    datePublished: new Date(block?.created_time).toISOString(),
+    dateModified: new Date(block?.last_edited_time).toISOString(),
+    ...(coverUrl && {
+      image: customMapImageUrl(coverUrl, block),
+    }),
     author: {
       "@type": "Person",
       name: siteConfig.author,
@@ -59,6 +88,10 @@ export default async function Page({
       name: siteConfig.author,
       url: siteConfig.url,
     },
+    mainEntityOfPage: {
+      "@type": "WebPage",
+      "@id": `${siteConfig.url}/blog/${blogId}`,
+    },
     url: `${siteConfig.url}/blog/${blogId}`,
   };
 

+ 0 - 9
app/layout.tsx

@@ -31,20 +31,11 @@ export const metadata: Metadata = {
     siteName: siteConfig.name,
     title: siteConfig.name,
     description: siteConfig.description,
-    images: [
-      {
-        url: "/og-image.png",
-        width: 1200,
-        height: 630,
-        alt: siteConfig.name,
-      },
-    ],
   },
   twitter: {
     card: "summary_large_image",
     title: siteConfig.name,
     description: siteConfig.description,
-    images: ["/og-image.png"],
   },
   robots: {
     index: true,

+ 20 - 0
app/not-found.tsx

@@ -0,0 +1,20 @@
+import Link from "next/link";
+
+export default function NotFound() {
+  return (
+    <div className="flex flex-col items-center justify-center min-h-[60vh] gap-6 px-4 text-center">
+      <h1 className="text-7xl md:text-9xl font-bold text-[#2a2f35] dark:text-[#eef0f7]">
+        404
+      </h1>
+      <p className="text-lg md:text-xl text-[#666] dark:text-[#888]">
+        This page doesn&apos;t exist.
+      </p>
+      <Link
+        className="mt-2 px-6 py-3 rounded-full bg-[#ece7e7] dark:bg-[#1e2228] dark:border-2 dark:border-knight text-sm font-medium hover:opacity-80 transition-opacity"
+        href="/"
+      >
+        Back to Home
+      </Link>
+    </div>
+  );
+}

+ 67 - 0
app/opengraph-image.tsx

@@ -0,0 +1,67 @@
+import { ImageResponse } from "next/og";
+
+export const runtime = "edge";
+export const alt = "Eric Wu - Full Stack Developer & Data Scientist";
+export const size = { width: 1200, height: 630 };
+export const contentType = "image/png";
+
+export default function Image() {
+  return new ImageResponse(
+    (
+      <div
+        style={{
+          background: "linear-gradient(135deg, #0b0f11 0%, #1a1f25 100%)",
+          width: "100%",
+          height: "100%",
+          display: "flex",
+          flexDirection: "column",
+          alignItems: "center",
+          justifyContent: "center",
+          fontFamily: "sans-serif",
+        }}
+      >
+        <div
+          style={{
+            display: "flex",
+            flexDirection: "column",
+            alignItems: "center",
+            gap: "20px",
+          }}
+        >
+          <h1
+            style={{
+              fontSize: 72,
+              fontWeight: 700,
+              color: "#ffffff",
+              margin: 0,
+              letterSpacing: "-0.02em",
+            }}
+          >
+            Eric Wu
+          </h1>
+          <p
+            style={{
+              fontSize: 32,
+              color: "#8cc9fe",
+              margin: 0,
+              letterSpacing: "0.05em",
+            }}
+          >
+            Full Stack Developer & Data Scientist
+          </p>
+          <p
+            style={{
+              fontSize: 24,
+              color: "#888888",
+              margin: 0,
+              marginTop: "8px",
+            }}
+          >
+            ericwu.me
+          </p>
+        </div>
+      </div>
+    ),
+    { ...size },
+  );
+}

+ 15 - 5
app/sitemap.ts

@@ -16,24 +16,34 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
   const blogPosts = await getAllBlogPosts(notionBlogConfig.blogParentId);
   const changeFrequency: ChangeFrequency = "weekly";
 
-  const blogs = blogPosts.map(({ id, createdAt }) => ({
+  const blogs = blogPosts.map(({ id, lastEditedAt }) => ({
     url: `${siteConfig.url}/blog/${id}`,
-    lastModified: createdAt.toISOString(),
+    lastModified: lastEditedAt.toISOString(),
     changeFrequency,
     priority: 0.7,
   }));
 
+  // Use the most recent blog post's edit time for the blog list page
+  const latestBlogEdit =
+    blogPosts.length > 0
+      ? blogPosts
+          .reduce((latest, post) =>
+            post.lastEditedAt > latest.lastEditedAt ? post : latest,
+          )
+          .lastEditedAt.toISOString()
+      : new Date().toISOString();
+
   const routes: MetadataRoute.Sitemap = [
     {
       url: siteConfig.url,
-      lastModified: new Date().toISOString(),
+      lastModified: latestBlogEdit,
       changeFrequency: "weekly" as ChangeFrequency,
       priority: 1.0,
     },
     {
       url: `${siteConfig.url}/blog`,
-      lastModified: new Date().toISOString(),
-      changeFrequency: "daily" as ChangeFrequency,
+      lastModified: latestBlogEdit,
+      changeFrequency: "weekly" as ChangeFrequency,
       priority: 0.8,
     },
   ];

+ 2 - 0
components/animation-swith.tsx

@@ -29,6 +29,7 @@ export const AnimationSwitch: FC<AnimationSwitchProps> = ({
         <Tooltip content="Animate it!" placement="bottom">
           <Button
             isIconOnly
+            aria-label="Enable animation"
             className="dark:border-knight dark:bg-transparent dark:border-2 bg-midnight border-0"
             radius="full"
             variant="bordered"
@@ -40,6 +41,7 @@ export const AnimationSwitch: FC<AnimationSwitchProps> = ({
       ) : (
         <Button
           isIconOnly
+          aria-label="Show static image"
           className="dark:border-knight dark:bg-transparent dark:border-2 bg-midnight border-0"
           radius="full"
           variant="bordered"

+ 5 - 2
components/blog-list.tsx

@@ -18,6 +18,7 @@ export function BlogList({ blogPosts }: BlogListProps) {
         <Link href="/" prefetch={true}>
           <Button
             isIconOnly
+            aria-label="Back to home"
             className="dark:border-knight dark:bg-transparent dark:border-2 bg-[#ece7e7] border-0"
             radius="full"
             variant="bordered"
@@ -42,8 +43,10 @@ export function BlogList({ blogPosts }: BlogListProps) {
                 />
               </CardBody>
               <CardFooter className="flex justify-between">
-                <h3 className="font-[500] text-lg">{title}</h3>
-                <h3 className="text-sm">{createdAt.toDateString()}</h3>
+                <h2 className="font-[500] text-lg">{title}</h2>
+                <time className="text-sm" dateTime={createdAt.toISOString()}>
+                  {createdAt.toDateString()}
+                </time>
               </CardFooter>
             </Card>
           </Link>

+ 9 - 0
components/mini-pic.tsx

@@ -25,7 +25,16 @@ const MiniPic = ({ onClick, showOverlay = false }: MiniPicProps) => {
 
   return (
     <div
+      role="button"
+      tabIndex={0}
+      aria-label="View Mini Cooper in 3D"
       className="relative w-full h-full cursor-pointer"
+      onKeyDown={(e) => {
+        if (e.key === "Enter" || e.key === " ") {
+          e.preventDefault();
+          onClick?.();
+        }
+      }}
       onMouseDown={(e) => handleStart(e.clientX, e.clientY)}
       onMouseUp={(e) => handleEnd(e.clientX, e.clientY)}
       onTouchStart={(e) => handleStart(e.touches[0].clientX, e.touches[0].clientY)}

+ 8 - 2
components/notion-page.tsx

@@ -111,6 +111,7 @@ export const NotionPage = ({
       <Link className="self-center" href="/blog" prefetch={true}>
         <Button
           isIconOnly
+          aria-label="Back to blog"
           className="dark:border-knight dark:bg-transparent dark:border-2 bg-[#ece7e7] border-0"
           radius="full"
           variant="bordered"
@@ -127,11 +128,16 @@ export const NotionPage = ({
           {title}
         </h1>
         <div className="ml-[15px] md:mx-[296px] mb-4">
-          <h3 className="w-fit dark:border-knight dark:bg-transparent dark:border-2 bg-[#ece7e7] border-0 py-1 px-4 rounded-full">
+          <time
+            className="w-fit dark:border-knight dark:bg-transparent dark:border-2 bg-[#ece7e7] border-0 py-1 px-4 rounded-full inline-block"
+            dateTime={new Date(
+              recordMap.block[rootPageId].value?.created_time,
+            ).toISOString()}
+          >
             {new Date(
               recordMap.block[rootPageId].value?.created_time,
             ).toDateString()}
-          </h3>
+          </time>
         </div>
 
         <NotionRenderer

+ 26 - 1
lib/notion.ts

@@ -1,7 +1,7 @@
 import { cache } from "react";
 
 import { NotionAPI } from "notion-client";
-import { Block } from "notion-types";
+import { Block, ExtendedRecordMap } from "notion-types";
 import { getPageTitle } from "notion-utils";
 
 import { Blog } from "@/types/blog";
@@ -31,6 +31,8 @@ export async function getAllBlogPosts(pageId: string) {
         pageCover: value.value.format?.page_cover,
         title: value.value.properties?.title[0][0],
         createdAt: new Date(value.value.created_time),
+        lastEditedAt: new Date(value.value.last_edited_time),
+        description: value.value.properties?.["\\u2O5F"]?.[0]?.[0] ?? "",
       });
     }
   });
@@ -41,6 +43,29 @@ export async function getAllBlogPosts(pageId: string) {
   return blogPosts;
 }
 
+/** Extract a plain-text excerpt from a Notion recordMap (first ~160 chars). */
+export function extractDescription(recordMap: ExtendedRecordMap): string {
+  const blocks = Object.values(recordMap.block);
+
+  for (const block of blocks) {
+    const value = block?.value;
+
+    if (!value) continue;
+    if (value.type !== "text" && value.type !== "quote") continue;
+
+    const text = value.properties?.title
+      ?.map((chunk: unknown[]) => chunk[0])
+      .join("")
+      .trim();
+
+    if (text && text.length > 0) {
+      return text.length > 160 ? text.slice(0, 157) + "..." : text;
+    }
+  }
+
+  return "";
+}
+
 export const customMapImageUrl = (url: string, block: Block): string => {
   if (!url) {
     throw new Error("URL can't be empty");

+ 2 - 0
types/blog.ts

@@ -6,4 +6,6 @@ export type Blog = {
   block: Block;
   pageCover: string;
   createdAt: Date;
+  lastEditedAt: Date;
+  description: string;
 };