@@ -25,11 +25,13 @@ export default function Page(props) {
2525 } = props ;
2626
2727 const isDynamicContent = props . content instanceof Promise ;
28- const [ content , setContent ] = useState (
29- isDynamicContent
30- ? placeholderString ( )
31- : ( ) => props . content . default || props . content ,
28+ const [ dynamicContent , setContent ] = useState (
29+ isDynamicContent ? placeholderString ( ) : null ,
3230 ) ;
31+ const content = isDynamicContent
32+ ? dynamicContent
33+ : props . content . default || props . content ;
34+
3335 const [ contentLoaded , setContentLoaded ] = useState ( ! isDynamicContent ) ;
3436
3537 useEffect ( ( ) => {
@@ -44,6 +46,7 @@ export default function Page(props) {
4446 } , [ props . content ] ) ;
4547
4648 const { hash, pathname } = useLocation ( ) ;
49+ const isBlogIndex = pathname === "/blog/" ;
4750
4851 useEffect ( ( ) => {
4952 let observer ;
@@ -52,13 +55,15 @@ export default function Page(props) {
5255 const target = document . querySelector ( "#md-content" ) ;
5356 // two cases here
5457 // 1. server side rendered page, so hash target is already there
55- if ( document . querySelector ( hash ) ) {
56- document . querySelector ( hash ) . scrollIntoView ( ) ;
58+ // Note: Why this change because we use getElementById instead of querySelector(hash) here because
59+ // CSS selectors cannot start with a digit (e.g. #11-in-scope is invalid)
60+ if ( document . getElementById ( hash . slice ( 1 ) ) ) {
61+ document . getElementById ( hash . slice ( 1 ) ) . scrollIntoView ( ) ;
5762 } else {
5863 // 2. dynamic loaded content
5964 // we need to observe the dom change to tell if hash exists
6065 observer = new MutationObserver ( ( ) => {
61- const element = document . querySelector ( hash ) ;
66+ const element = document . getElementById ( hash . slice ( 1 ) ) ;
6267 if ( element ) {
6368 element . scrollIntoView ( ) ;
6469 }
@@ -99,9 +104,12 @@ export default function Page(props) {
99104 ) ;
100105 }
101106 return (
102- < section className = "page" >
107+ < main id = "main-content" className = "page" >
103108 < Markdown >
104109 < h1 > { title } </ h1 >
110+ { rest . date && pathname . startsWith ( "/blog/" ) && ! isBlogIndex && (
111+ < div className = "blog-post-date" > { rest . date } </ div >
112+ ) }
105113
106114 { rest . thirdParty ? (
107115 < div className = "italic my-[20px]" >
@@ -114,6 +122,27 @@ export default function Page(props) {
114122
115123 < div id = "md-content" > { contentRender } </ div >
116124
125+ { rest . url === "/blog/" && (
126+ < div className = "blog-list" >
127+ { ( props . pages || [ ] )
128+ . filter ( ( post ) => post . url !== "/blog/" )
129+ . map ( ( post ) => (
130+ < div key = { post . url } className = "blog-post-item" >
131+ < h2 >
132+ < Link to = { post . url } > { post . title } </ Link >
133+ </ h2 >
134+ { post . date && (
135+ < div className = "blog-post-date" > { post . date } </ div >
136+ ) }
137+ < p > { post . teaser } </ p >
138+ < Link to = { post . url } className = "read-more" >
139+ Read More →
140+ </ Link >
141+ </ div >
142+ ) ) }
143+ </ div >
144+ ) }
145+
117146 { loadRelated && (
118147 < div className = "print:hidden" >
119148 < h2 > Further Reading</ h2 >
@@ -129,7 +158,7 @@ export default function Page(props) {
129158
130159 < PageLinks page = { rest } />
131160
132- { ( previous || next ) && (
161+ { ! isBlogIndex && ( previous || next ) && (
133162 < AdjacentPages previous = { previous } next = { next } />
134163 ) }
135164
@@ -143,7 +172,7 @@ export default function Page(props) {
143172 </ div >
144173 ) }
145174 </ Markdown >
146- </ section >
175+ </ main >
147176 ) ;
148177}
149178
@@ -153,6 +182,7 @@ Page.propTypes = {
153182 related : PropTypes . array ,
154183 previous : PropTypes . object ,
155184 next : PropTypes . object ,
185+ pages : PropTypes . array ,
156186 content : PropTypes . oneOfType ( [
157187 PropTypes . string ,
158188 PropTypes . func ,
0 commit comments