@@ -17,6 +17,7 @@ const LinkRenderer = ({ href, children }) => {
1717const BlogPostPage = ( ) => {
1818 const { slug } = useParams ( ) ;
1919 const [ post , setPost ] = useState ( null ) ;
20+ const [ shownPostsData , setShownPostsData ] = useState ( [ ] ) ;
2021 const [ loading , setLoading ] = useState ( true ) ;
2122 const [ readingProgress , setReadingProgress ] = useState ( 0 ) ;
2223 const [ isAtTop , setIsAtTop ] = useState ( true ) ; // New state for tracking if at top
@@ -26,16 +27,28 @@ const BlogPostPage = () => {
2627 const fetchPost = async ( ) => {
2728 setLoading ( true ) ;
2829 try {
29- const response = await fetch ( `/posts/${ slug } .md` ) ;
30- if ( response . ok ) {
31- const text = await response . text ( ) ;
30+ const [ postResponse , shownPostsResponse ] = await Promise . all ( [
31+ fetch ( `/posts/${ slug } .md` ) ,
32+ fetch ( '/data/shownPosts.json' )
33+ ] ) ;
34+
35+ if ( postResponse . ok ) {
36+ const text = await postResponse . text ( ) ;
3237 const content = fm ( text ) ;
3338 setPost ( content ) ;
3439 } else {
3540 setPost ( { attributes : { title : 'Post not found' } , body : '' } ) ;
3641 }
42+
43+ if ( shownPostsResponse . ok ) {
44+ const data = await shownPostsResponse . json ( ) ;
45+ setShownPostsData ( data ) ;
46+ } else {
47+ console . error ( 'Failed to fetch shownPosts.json' ) ;
48+ }
49+
3750 } catch ( error ) {
38- console . error ( 'Error fetching post:' , error ) ;
51+ console . error ( 'Error fetching post or shownPosts.json :' , error ) ;
3952 setPost ( { attributes : { title : 'Error loading post' } , body : '' } ) ;
4053 }
4154 setLoading ( false ) ;
@@ -67,6 +80,10 @@ const BlogPostPage = () => {
6780 return < div className = "text-center py-16" > Post not found</ div > ;
6881 }
6982
83+ const currentPostData = shownPostsData . find ( item => item . file === slug ) ;
84+ const postDate = currentPostData ? currentPostData . date : null ;
85+ const updatedDate = currentPostData ? currentPostData . updated : null ;
86+
7087 return (
7188 < div className = "bg-gray-900 py-16 sm:py-24" >
7289 < div className = "mx-auto max-w-7xl px-6 lg:px-8" >
@@ -80,7 +97,7 @@ const BlogPostPage = () => {
8097 </ div >
8198 </ div >
8299 < div className = "hidden lg:block" >
83- < PostMetadata metadata = { post . attributes } readingProgress = { readingProgress } isAtTop = { isAtTop } />
100+ < PostMetadata metadata = { post . attributes } readingProgress = { readingProgress } isAtTop = { isAtTop } overrideDate = { postDate } updatedDate = { updatedDate } />
84101 </ div >
85102 </ div >
86103 </ div >
0 commit comments