Skip to content

Commit 39e8d30

Browse files
committed
added screensize adaption
1 parent 8b32192 commit 39e8d30

File tree

3 files changed

+45
-27
lines changed

3 files changed

+45
-27
lines changed

content/assets/styles.css

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,32 @@ html, body {
3636
padding-left: 10px;
3737
}
3838

39-
.gridContainerDesktop {
40-
display: grid;
41-
grid-auto-flow: row;
42-
width: 920px;
43-
margin-left: auto;
44-
margin-right: auto;
39+
@media only screen and (max-width: 920px) {
40+
.grid-container {
41+
display: grid;
42+
grid-auto-flow: row;
43+
overflow: clip;
44+
background-color: var(--ctp-mocha-mantle);
45+
}
4546
}
4647

47-
.gridContainerMobile {
48-
display: grid;
49-
grid-auto-flow: row;
50-
overflow: clip;
48+
@media only screen and (min-width: 920px) {
49+
.grid-container {
50+
display: grid;
51+
grid-auto-flow: row;
52+
width: 920px;
53+
margin-left: auto;
54+
margin-right: auto;
55+
padding-left: 2vw;
56+
padding-right: 2vw;
57+
height: 100vh;
58+
background-color: var(--ctp-mocha-mantle);
59+
}
5160
}
5261

62+
5363
.gridCell {
54-
background-color: var(--ctp-mocha-mantle);
64+
5565
padding-left: 2vh;
5666
padding-right: 2vh;
5767
height: 100vh;

src/blog/render.gleam

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,40 @@ import lustre/ssg/djot
88
import lustre/vdom/vnode
99
import tom
1010

11-
fn include_styles_and_scripts(page: List(vnode.Element(a))) -> vnode.Element(_) {
11+
fn include_styles_and_scripts(
12+
page: List(vnode.Element(a)),
13+
asset_path: String,
14+
) -> vnode.Element(_) {
1215
html([], [
1316
head([], [
1417
link([
15-
attribute("rel", "stylesheet"),
16-
attribute(
17-
"href",
18+
attribute.rel("stylesheet"),
19+
attribute.href(
1820
"https://cdn.jsdelivr.net/npm/@catppuccin/palette/css/catppuccin.css",
1921
),
2022
]),
2123
link([
22-
attribute("rel", "stylesheet"),
23-
attribute("href", "assets/styles.css"),
24+
attribute.rel("stylesheet"),
25+
attribute.href(asset_path <> "styles.css"),
2426
]),
25-
script([attribute.src("assets/startup.js")], ""),
27+
script([attribute.src(asset_path <> "startup.js")], ""),
2628
]),
27-
body([attribute.class("gridContainerDesktop")], [
28-
div([attribute.class("gridCell")], page),
29+
body([attribute.class("grid-container")], [
30+
div([attribute.class("grid-cell")], page),
2931
]),
3032
])
3133
}
3234

33-
pub fn render_md_path(path: String) -> vnode.Element(_) {
35+
pub fn render_md_path(path: String, asset_path: String) -> vnode.Element(_) {
3436
let assert Ok(posts.FileSource(_, md)) = posts.from_file(path)
3537

3638
djot.render(md, djot.default_renderer())
37-
|> include_styles_and_scripts
39+
|> include_styles_and_scripts(asset_path)
3840
}
3941

40-
pub fn render_md(md: String) -> vnode.Element(_) {
42+
pub fn render_md(md: String, asset_path: String) -> vnode.Element(_) {
4143
djot.render(md, djot.default_renderer())
42-
|> include_styles_and_scripts
44+
|> include_styles_and_scripts(asset_path)
4345
}
4446

4547
pub fn render_matter(
@@ -68,5 +70,5 @@ pub fn render_links(base: String, sources: List(posts.PostSource)) {
6870
|> list.map(render_matter(base, _))
6971

7072
[html.h1([], [text("Blogs")]), ..rendered_matters]
71-
|> include_styles_and_scripts
73+
|> include_styles_and_scripts("assets/")
7274
}

src/build.gleam

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,15 @@ fn build() -> Result(_, _) {
3838

3939
let build =
4040
ssg.new("./pages")
41-
|> ssg.add_static_route("/", render.render_md_path("./content/index.md"))
41+
|> ssg.add_static_route(
42+
"/",
43+
render.render_md_path("./content/index.md", "assets/"),
44+
)
4245
|> ssg.add_static_route("/blogs", render.render_links("blogs", blogs))
43-
|> ssg.add_dynamic_route("/blogs", blog_dict, render.render_md)
46+
|> ssg.add_dynamic_route("/blogs", blog_dict, render.render_md(
47+
_,
48+
"../assets/",
49+
))
4450
|> ssg.build
4551

4652
case build {

0 commit comments

Comments
 (0)