@@ -5,21 +5,45 @@ import gleam/result
5
5
import lustre/attribute . { attribute }
6
6
import lustre/element/html . { a , body , div , head , html , link , p , script , text }
7
7
import lustre/ssg/djot
8
+ import lustre/vdom/vnode
8
9
import tom
9
10
10
- pub fn render_md_path ( path : String ) {
11
+ fn include_styles_and_scripts ( page : List ( vnode . Element ( a) ) ) -> vnode . Element ( _) {
12
+ html ( [ ] , [
13
+ head ( [ ] , [
14
+ link ( [
15
+ attribute ( "rel" , "stylesheet" ) ,
16
+ attribute (
17
+ "href" ,
18
+ "https://cdn.jsdelivr.net/npm/@catppuccin/palette/css/catppuccin.css" ,
19
+ ) ,
20
+ ] ) ,
21
+ link ( [
22
+ attribute ( "rel" , "stylesheet" ) ,
23
+ attribute ( "href" , "assets/styles.css" ) ,
24
+ ] ) ,
25
+ script ( [ attribute . src ( "assets/startup.js" ) ] , "" ) ,
26
+ ] ) ,
27
+ body ( [ ] , page ) ,
28
+ ] )
29
+ }
30
+
31
+ pub fn render_md_path ( path : String ) -> vnode . Element ( _) {
11
32
let assert Ok ( posts . FileSource ( _ , md ) ) = posts . from_file ( path )
12
33
13
34
djot . render ( md , djot . default_renderer ( ) )
14
- |> div ( [ ] , _ )
35
+ |> include_styles_and_scripts
15
36
}
16
37
17
- pub fn render_md ( md : String ) {
38
+ pub fn render_md ( md : String ) -> vnode . Element ( _ ) {
18
39
djot . render ( md , djot . default_renderer ( ) )
19
- |> div ( [ ] , _ )
40
+ |> include_styles_and_scripts
20
41
}
21
42
22
- pub fn render_matter ( base : String , matter : # ( String , String ) ) {
43
+ pub fn render_matter (
44
+ base : String ,
45
+ matter : # ( String , String ) ,
46
+ ) -> vnode . Element ( _) {
23
47
div ( [ attribute . class ( "blog" ) ] , [
24
48
p ( [ ] , [ text ( matter . 0 ) ] ) ,
25
49
p ( [ ] , [ a ( [ attribute . href ( base <> "/" <> matter . 1 ) ] , [ text ( matter . 1 ) ] ) ] ) ,
@@ -37,22 +61,7 @@ pub fn render_links(base: String, sources: List(posts.PostSource)) {
37
61
38
62
let assert Ok ( matters ) = result . all ( matters )
39
63
40
- // <link rel="stylesheet" href="mystyle.css">
41
- html ( [ ] , [
42
- head ( [ ] , [
43
- link ( [
44
- attribute ( "rel" , "stylesheet" ) ,
45
- attribute (
46
- "href" ,
47
- "https://cdn.jsdelivr.net/npm/@catppuccin/palette/css/catppuccin.css" ,
48
- ) ,
49
- ] ) ,
50
- link ( [
51
- attribute ( "rel" , "stylesheet" ) ,
52
- attribute ( "href" , "assets/styles.css" ) ,
53
- ] ) ,
54
- script ( [ attribute . src ( "assets/startup.js" ) ] , "" ) ,
55
- ] ) ,
56
- body ( [ ] , [ div ( [ ] , list . map ( matters , render_matter ( base , _) ) ) ] ) ,
57
- ] )
64
+ matters
65
+ |> list . map ( render_matter ( base , _) )
66
+ |> include_styles_and_scripts
58
67
}
0 commit comments