Skip to content

Commit 27bed1b

Browse files
committed
resolved flicker issue on markdown pages
1 parent 2e7bf30 commit 27bed1b

File tree

4 files changed

+32
-41
lines changed

4 files changed

+32
-41
lines changed

content/blogs/blog1.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ title = "The First blog"
33
url = "blog_1"
44
---
55

6-
``` =html
7-
<link href="https://cdn.jsdelivr.net/npm/@catppuccin/palette/css/catppuccin.css" rel="stylesheet">
8-
<link href="../assets/styles.css" rel="stylesheet">
9-
<script src="../assets/startup.js"></script>
10-
```
11-
126
# Hello There
137

148
this is a test edit

content/blogs/blog2.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,4 @@ title = "The Second blog"
33
url = "blog_2"
44
---
55

6-
``` =html
7-
<link href="https://cdn.jsdelivr.net/npm/@catppuccin/palette/css/catppuccin.css" rel="stylesheet">
8-
<link href="../assets/styles.css" rel="stylesheet">
9-
<script src="../assets/startup.js"></script>
10-
```
11-
126
# General Kenobi

content/index.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ url = "test_url"
44
---
55
# Hello
66

7-
``` =html
8-
<link href="https://cdn.jsdelivr.net/npm/@catppuccin/palette/css/catppuccin.css" rel="stylesheet">
9-
<link href="assets/styles.css" rel="stylesheet">
10-
<script src="assets/startup.js"></script>
11-
```
12-
137
This is static content generated by lustre_ssg.
148

159
To build use `gleam run -m build`.

src/blog/render.gleam

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,45 @@ import gleam/result
55
import lustre/attribute.{attribute}
66
import lustre/element/html.{a, body, div, head, html, link, p, script, text}
77
import lustre/ssg/djot
8+
import lustre/vdom/vnode
89
import tom
910

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(_) {
1132
let assert Ok(posts.FileSource(_, md)) = posts.from_file(path)
1233

1334
djot.render(md, djot.default_renderer())
14-
|> div([], _)
35+
|> include_styles_and_scripts
1536
}
1637

17-
pub fn render_md(md: String) {
38+
pub fn render_md(md: String) -> vnode.Element(_) {
1839
djot.render(md, djot.default_renderer())
19-
|> div([], _)
40+
|> include_styles_and_scripts
2041
}
2142

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(_) {
2347
div([attribute.class("blog")], [
2448
p([], [text(matter.0)]),
2549
p([], [a([attribute.href(base <> "/" <> matter.1)], [text(matter.1)])]),
@@ -37,22 +61,7 @@ pub fn render_links(base: String, sources: List(posts.PostSource)) {
3761

3862
let assert Ok(matters) = result.all(matters)
3963

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
5867
}

0 commit comments

Comments
 (0)