@@ -30,17 +30,22 @@ const articles = findInDir("./thoughts/articles", ".md");
3030
3131const mdConverter = new showdown . Converter ( ) ;
3232
33- const articlesGenerated = [ ] ;
33+ const articlesGenerated : Array < {
34+ title : string ;
35+ link : string ;
36+ body : string ;
37+ date : string ;
38+ } > = [ ] ;
3439
3540articles . forEach ( ( article ) => {
3641 const articleWithoutFolder = article
3742 . replace ( "thoughts/articles/" , "" )
3843 . replace ( ".md" , ".html" ) ;
39- let [ datestring , title ] = articleWithoutFolder
44+ let [ datestring , titleWithDash ] = articleWithoutFolder
4045 . replace ( ".html" , "" )
4146 . split ( "_" ) ;
4247 const date = dateFormat ( new Date ( datestring ) , "do LLL, u" ) ;
43- title = title . replace ( / - / g, " " ) ;
48+ const title = titleWithDash . replace ( / - / g, " " ) ;
4449 const body = mdConverter . makeHtml ( fs . readFileSync ( article , "utf8" ) ) ;
4550
4651 const articleContents = thoughtsPageTemplateContents
@@ -55,13 +60,31 @@ articles.forEach((article) => {
5560 "utf8"
5661 ) ;
5762
63+ const splitBody = body . split ( "</p>" ) ;
64+
5865 articlesGenerated . push ( {
66+ link : `${ datestring } _${ titleWithDash } ` ,
5967 title,
6068 date,
61- body,
69+ body : ` ${ splitBody [ 0 ] } </p> ${ splitBody [ 1 ] } </p>` ,
6270 } ) ;
6371} ) ;
6472
6573console . log ( `Generated ${ articlesGenerated . length } articles` ) ;
6674
75+ console . log ( "Updating thoughts page proper" ) ;
76+ let thoughtsPageContents = fs . readFileSync ( "./public/thoughts.html" , "utf8" ) ;
77+
78+ for ( let i = 0 ; i < Math . min ( 2 , articlesGenerated . length ) ; i ++ ) {
79+ thoughtsPageContents = thoughtsPageContents
80+ . replace ( `{title${ i } }` , articlesGenerated [ i ] . title )
81+ . replace ( `{date${ i } }` , articlesGenerated [ i ] . date )
82+ . replace ( `{body${ i } }` , articlesGenerated [ i ] . body )
83+ . replace ( `{link${ i } }` , articlesGenerated [ i ] . link ) ;
84+ }
85+
86+ console . log ( "Updated thoughts page" ) ;
87+
88+ fs . writeFileSync ( "./public/thoughts.html" , thoughtsPageContents , "utf8" ) ;
89+
6790console . log ( "/// Finished generation of thoughts" ) ;
0 commit comments