11import { NotionAPI } from 'notion-client'
2+ import { getCanonicalPageId } from './get-canonical-page-id'
23
34const notion = new NotionAPI ( )
45
@@ -12,10 +13,7 @@ export interface BlogPost {
1213
1314export async function getHomepageData ( ) {
1415 try {
15- // Fetch the blog posts collection
16- const collectionId = 'c7cbc279-6edb-4462-85c1-84ae5af1c7b6'
17-
18- // Fetch the page that contains the collection
16+ // Fetch the root page which contains the blog posts collection
1917 const recordMap = await notion . getPage ( '16ccc94eb4cf4b3d85fb31ac7be58e87' )
2018
2119 const posts : BlogPost [ ] = [ ]
@@ -28,9 +26,13 @@ export async function getHomepageData() {
2826 if ( block . value && block . value . type === 'page' && block . value . parent_table === 'collection' ) {
2927 const properties = block . value . properties
3028
29+ // Skip pages without Public checkbox or where Public is false
30+ const isPublic = block . value . properties ?. [ '[ZmN' '] ?. [ 0 ] ?. [ 0 ] === 'Yes'
31+
3132 if ( properties ) {
3233 const title = properties . title ?. [ 0 ] ?. [ 0 ] || 'Untitled'
33- const slug = block . value . id . replace ( / - / g, '' )
34+ // Use the canonical page ID which generates the proper URL slug
35+ const slug = getCanonicalPageId ( block . value . id , recordMap , { uuid : false } ) || block . value . id . replace ( / - / g, '' )
3436 const date = properties . published ?. [ 0 ] ?. [ 1 ] ?. [ 0 ] ?. [ 1 ] ?. start_date
3537 const tags = properties . tags ?. [ 0 ] ?. [ 0 ] ?. split ( ',' ) . map ( ( t : string ) => t . trim ( ) ) || [ ]
3638
0 commit comments