@@ -44,6 +44,7 @@ export default function Page(props) {
4444 } , [ props . content ] ) ;
4545
4646 const { hash, pathname } = useLocation ( ) ;
47+ const isBlogIndex = pathname === "/blog/" ;
4748
4849 useEffect ( ( ) => {
4950 let observer ;
@@ -52,13 +53,15 @@ export default function Page(props) {
5253 const target = document . querySelector ( "#md-content" ) ;
5354 // two cases here
5455 // 1. server side rendered page, so hash target is already there
55- if ( document . querySelector ( hash ) ) {
56- document . querySelector ( hash ) . scrollIntoView ( ) ;
56+ // Note: Why this change because we use getElementById instead of querySelector(hash) here because
57+ // CSS selectors cannot start with a digit (e.g. #11-in-scope is invalid)
58+ if ( document . getElementById ( hash . slice ( 1 ) ) ) {
59+ document . getElementById ( hash . slice ( 1 ) ) . scrollIntoView ( ) ;
5760 } else {
5861 // 2. dynamic loaded content
5962 // we need to observe the dom change to tell if hash exists
6063 observer = new MutationObserver ( ( ) => {
61- const element = document . querySelector ( hash ) ;
64+ const element = document . getElementById ( hash . slice ( 1 ) ) ;
6265 if ( element ) {
6366 element . scrollIntoView ( ) ;
6467 }
@@ -99,9 +102,12 @@ export default function Page(props) {
99102 ) ;
100103 }
101104 return (
102- < section className = "page" >
105+ < main id = "main-content" className = "page" >
103106 < Markdown >
104107 < h1 > { title } </ h1 >
108+ { rest . date && pathname . startsWith ( "/blog/" ) && ! isBlogIndex && (
109+ < div className = "blog-post-date" > { rest . date } </ div >
110+ ) }
105111
106112 { rest . thirdParty ? (
107113 < div className = "italic my-[20px]" >
@@ -114,6 +120,27 @@ export default function Page(props) {
114120
115121 < div id = "md-content" > { contentRender } </ div >
116122
123+ { rest . url === "/blog/" && (
124+ < div className = "blog-list" >
125+ { ( props . pages || [ ] )
126+ . filter ( ( post ) => post . url !== "/blog/" )
127+ . map ( ( post ) => (
128+ < div key = { post . url } className = "blog-post-item" >
129+ < h2 >
130+ < Link to = { post . url } > { post . title } </ Link >
131+ </ h2 >
132+ { post . date && (
133+ < div className = "blog-post-date" > { post . date } </ div >
134+ ) }
135+ < p > { post . teaser } </ p >
136+ < Link to = { post . url } className = "read-more" >
137+ Read More →
138+ </ Link >
139+ </ div >
140+ ) ) }
141+ </ div >
142+ ) }
143+
117144 { loadRelated && (
118145 < div className = "print:hidden" >
119146 < h2 > Further Reading</ h2 >
@@ -129,7 +156,7 @@ export default function Page(props) {
129156
130157 < PageLinks page = { rest } />
131158
132- { ( previous || next ) && (
159+ { ! isBlogIndex && ( previous || next ) && (
133160 < AdjacentPages previous = { previous } next = { next } />
134161 ) }
135162
@@ -143,7 +170,7 @@ export default function Page(props) {
143170 </ div >
144171 ) }
145172 </ Markdown >
146- </ section >
173+ </ main >
147174 ) ;
148175}
149176
@@ -153,13 +180,12 @@ Page.propTypes = {
153180 related : PropTypes . array ,
154181 previous : PropTypes . object ,
155182 next : PropTypes . object ,
183+ pages : PropTypes . array ,
156184 content : PropTypes . oneOfType ( [
157- PropTypes . string ,
158- PropTypes . func ,
159185 PropTypes . shape ( {
160186 // eslint-disable-next-line unicorn/no-thenable
161187 then : PropTypes . func . isRequired ,
162- default : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . func ] ) ,
188+ default : PropTypes . string ,
163189 } ) ,
164190 ] ) ,
165191} ;
0 commit comments