Sfoglia il codice sorgente

fix: resolve all TypeScript type errors from null date and untyped properties

- Use Role type from notion-types for NestedBlockEntry
- Fall back to empty string for missing pageCover
- Cast dynamic Notion property key to avoid implicit any
- Guard null lastEditedAt in sitemap with optional chaining

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
rriecc 7 mesi fa
parent
commit
56f6e7995a
2 ha cambiato i file con 11 aggiunte e 8 eliminazioni
  1. 6 4
      app/sitemap.ts
  2. 5 4
      lib/notion.ts

+ 6 - 4
app/sitemap.ts

@@ -18,19 +18,21 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
 
   const blogs = blogPosts.map(({ id, lastEditedAt }) => ({
     url: `${siteConfig.url}/blog/${id}`,
-    lastModified: lastEditedAt.toISOString(),
+    lastModified: lastEditedAt?.toISOString() ?? new Date().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,
+            (post.lastEditedAt?.getTime() ?? 0) >
+            (latest.lastEditedAt?.getTime() ?? 0)
+              ? post
+              : latest,
           )
-          .lastEditedAt.toISOString()
+          .lastEditedAt?.toISOString() ?? new Date().toISOString()
       : new Date().toISOString();
 
   const routes: MetadataRoute.Sitemap = [

+ 5 - 4
lib/notion.ts

@@ -1,7 +1,7 @@
 import { cache } from "react";
 
 import { NotionAPI } from "notion-client";
-import { Block, ExtendedRecordMap } from "notion-types";
+import { Block, ExtendedRecordMap, Role } from "notion-types";
 import { getPageTitle } from "notion-utils";
 
 import { Blog } from "@/types/blog";
@@ -16,7 +16,7 @@ const notion = new NotionAPI();
 // This type covers both shapes so we can unwrap safely.
 type NestedBlockEntry = {
   spaceId?: string;
-  value: { value: Block; role: string };
+  value: { value: Block; role: Role };
 };
 
 function normalizeRecordMap(recordMap: ExtendedRecordMap): ExtendedRecordMap {
@@ -57,13 +57,14 @@ export async function getAllBlogPosts(pageId: string) {
     blogPosts.push({
       id: key,
       block,
-      pageCover: block.format?.page_cover,
+      pageCover: block.format?.page_cover ?? "",
       title: block.properties.title[0][0],
       createdAt: block.created_time ? new Date(block.created_time) : null,
       lastEditedAt: block.last_edited_time
         ? new Date(block.last_edited_time)
         : null,
-      description: block.properties?.["\\u2O5F"]?.[0]?.[0] ?? "",
+      description:
+        (block.properties as Record<string, unknown[][]>)?.["\\u2O5F"]?.[0]?.[0]?.toString() ?? "",
     });
   });