11---
2+ import type { RenderedContent } from ' astro:content' ;
23interface Post {
34 id: string ;
45 data: {
6+ date: Date ;
57 title: string ;
68 description? : string ;
79 imagePath? : string ;
810 imageAlt? : string ;
911 };
12+ rendered? : RenderedContent ;
1013}
1114
1215export interface Props {
@@ -15,7 +18,27 @@ export interface Props {
1518
1619const { post } = Astro .props ;
1720const { id, data } = post ;
18- const { title, description, imageAlt, imagePath } = data ;
21+ const { title, date } = data ;
22+ const html: string = post .rendered ?.html ?? ' ' ;
23+
24+ // format publication date for the given post.
25+ const formattedDate = date .toLocaleDateString (' en-US' , {
26+ year: ' numeric' ,
27+ month: ' short' ,
28+ day: ' numeric' ,
29+ });
30+
31+ // retrieve and truncate the post body after the first paragraph.
32+ // this makes it consistent with Jekyll's default behavior for
33+ // creating post excerpts.
34+ // see https://jekyllrb.com/docs/posts/#post-excerpts
35+ const closingParagraph = ' </p>' ;
36+ const idxClosingParagraph = html .indexOf (closingParagraph );
37+ const idxCutOff = idxClosingParagraph + closingParagraph .length ;
38+ let content = html ;
39+ if (idxClosingParagraph !== - 1 && idxCutOff < html .length ) {
40+ content = html .slice (0 , idxCutOff );
41+ }
1942---
2043
2144<style >
@@ -29,7 +52,9 @@ const { title, description, imageAlt, imagePath } = data;
2952</style >
3053
3154<li >
32- <a href ={ ` /posts/${id } ` } >{ title } </a >
33- { imagePath && <img src = { imagePath } alt = { imageAlt } />}
34- { description && <p >{ description } </p >}
55+ { formattedDate && <span class = " post-meta" >{ formattedDate } </span >}
56+ <h2 >
57+ <a class =" post-link" href ={ ` /posts/${id } ` } >{ title } </a >
58+ </h2 >
59+ <Fragment set:html ={ content } />
3560</li >
0 commit comments