11import { useState , useEffect } from 'react'
22import { Loader2 } from 'lucide-react'
33import PostCard from '../components/dynamic-page/PostCard'
4- import { useContent } from '../context/ContentContext '
4+ import { api } from '../api/client '
55
66/**
7- * Blog Home Page - Shows all published posts from all pages.
7+ * Blog Home Page - Shows all published posts from ALL pages.
88 *
9- * This replaces the previous landing-style Hero component with a clean
10- * blog listing view. Uses the ContentContext which already has the navigation
11- * data to avoid excessive API calls.
9+ * Uses listPublishedPages to get all pages (not just navigation items)
10+ * and then fetches posts from each page.
1211 */
1312const Home = ( ) => {
14- const { navigation, pages } = useContent ( )
1513 const [ posts , setPosts ] = useState ( [ ] )
1614 const [ loading , setLoading ] = useState ( true )
1715 const [ error , setError ] = useState ( null )
@@ -21,37 +19,39 @@ const Home = () => {
2119 try {
2220 setLoading ( true )
2321
24- // Get page slugs from navigation (already loaded by ContentContext)
25- const navItems = navigation ?. items || [ ]
26- if ( navItems . length === 0 ) {
22+ // Get ALL published pages, not just navigation items
23+ const pagesData = await api . listPublishedPages ( )
24+ const allPages = pagesData ?. items || [ ]
25+
26+ if ( allPages . length === 0 ) {
2727 setPosts ( [ ] )
2828 setLoading ( false )
2929 return
3030 }
3131
32- // Fetch all pages in parallel - but with a small delay to avoid rate limiting
32+ // Fetch posts from each page with delay to avoid rate limiting
3333 const allPosts = [ ]
3434
35- for ( const navItem of navItems ) {
35+ for ( const page of allPages ) {
3636 try {
37- // Use the ContentContext's fetch which caches results
38- const pageData = await pages . fetch ( navItem . slug )
37+ // Fetch the full page data which includes posts
38+ const pageData = await api . getPublishedPage ( page . slug )
3939 if ( pageData ?. posts ) {
4040 pageData . posts . forEach ( post => {
4141 allPosts . push ( {
4242 ...post ,
43- pageSlug : navItem . slug ,
44- pageTitle : navItem . title
43+ pageSlug : page . slug ,
44+ pageTitle : page . title
4545 } )
4646 } )
4747 }
4848 } catch ( e ) {
4949 // Page might have no posts or fail, continue with others
50- console . log ( `Could not load posts for ${ navItem . slug } :` , e . message )
50+ console . log ( `Could not load posts for ${ page . slug } :` , e . message )
5151 }
5252
5353 // Small delay between requests to avoid rate limiting
54- await new Promise ( resolve => setTimeout ( resolve , 100 ) )
54+ await new Promise ( resolve => setTimeout ( resolve , 150 ) )
5555 }
5656
5757 // Sort by creation date, newest first
@@ -65,11 +65,8 @@ const Home = () => {
6565 }
6666 }
6767
68- // Only fetch when navigation is loaded
69- if ( navigation ?. items ) {
70- fetchAllPosts ( )
71- }
72- } , [ navigation , pages ] )
68+ fetchAllPosts ( )
69+ } , [ ] )
7370
7471 return (
7572 < main className = "min-h-screen bg-gradient-to-br from-slate-50 via-white to-slate-100 dark:from-slate-950 dark:via-slate-900 dark:to-slate-950" >
0 commit comments