File tree 2 files changed +12
-5
lines changed
2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change 5
5
const { data }: { data: PageData } = $props ();
6
6
</script >
7
7
8
- {#each data .posts as { metadata, default: Post }}
9
- <h2 class ="heading" >{ metadata .title }</h2 >
8
+ {#each data .posts as { metadata, slug, default: Post }}
9
+ <h2 class ="heading" id ={ slug }>< a class = "anchorLink" href = "# { slug } " >{ metadata .title }</ a > </h2 >
10
10
<p class ="byline" >{format (metadata .date , " MMMM d, yyyy" )} by {metadata .author }</p >
11
11
<div class =" post" >
12
12
<Post />
22
22
font-style : italic ;
23
23
font-size : 1rem ;
24
24
}
25
+ .anchorLink {
26
+ color : inherit ;
27
+ text-decoration : none ;
28
+ }
25
29
</style >
Original file line number Diff line number Diff line change @@ -11,8 +11,11 @@ export async function load() {
11
11
} > ( "./posts/*.md" , { eager : true } ) ;
12
12
13
13
return {
14
- posts : Object . values ( markdownFiles ) . sort (
15
- ( a , b ) => new Date ( b . metadata . date ) . getTime ( ) - new Date ( a . metadata . date ) . getTime ( ) ,
16
- ) ,
14
+ posts : Object . entries ( markdownFiles )
15
+ . map ( ( [ path , post ] ) => ( {
16
+ slug : path . match ( / ( [ ^ \/ ] + ) \. m d $ / ) ?. [ 1 ] ,
17
+ ...post ,
18
+ } ) )
19
+ . sort ( ( a , b ) => new Date ( b . metadata . date ) . getTime ( ) - new Date ( a . metadata . date ) . getTime ( ) ) ,
17
20
} ;
18
21
}
You can’t perform that action at this time.
0 commit comments