@@ -30,17 +30,22 @@ const articles = findInDir("./thoughts/articles", ".md");
30
30
31
31
const mdConverter = new showdown . Converter ( ) ;
32
32
33
- const articlesGenerated = [ ] ;
33
+ const articlesGenerated : Array < {
34
+ title : string ;
35
+ link : string ;
36
+ body : string ;
37
+ date : string ;
38
+ } > = [ ] ;
34
39
35
40
articles . forEach ( ( article ) => {
36
41
const articleWithoutFolder = article
37
42
. replace ( "thoughts/articles/" , "" )
38
43
. replace ( ".md" , ".html" ) ;
39
- let [ datestring , title ] = articleWithoutFolder
44
+ let [ datestring , titleWithDash ] = articleWithoutFolder
40
45
. replace ( ".html" , "" )
41
46
. split ( "_" ) ;
42
47
const date = dateFormat ( new Date ( datestring ) , "do LLL, u" ) ;
43
- title = title . replace ( / - / g, " " ) ;
48
+ const title = titleWithDash . replace ( / - / g, " " ) ;
44
49
const body = mdConverter . makeHtml ( fs . readFileSync ( article , "utf8" ) ) ;
45
50
46
51
const articleContents = thoughtsPageTemplateContents
@@ -55,13 +60,31 @@ articles.forEach((article) => {
55
60
"utf8"
56
61
) ;
57
62
63
+ const splitBody = body . split ( "</p>" ) ;
64
+
58
65
articlesGenerated . push ( {
66
+ link : `${ datestring } _${ titleWithDash } ` ,
59
67
title,
60
68
date,
61
- body,
69
+ body : ` ${ splitBody [ 0 ] } </p> ${ splitBody [ 1 ] } </p>` ,
62
70
} ) ;
63
71
} ) ;
64
72
65
73
console . log ( `Generated ${ articlesGenerated . length } articles` ) ;
66
74
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
+
67
90
console . log ( "/// Finished generation of thoughts" ) ;
0 commit comments