Skip to content

Commit c56d78b

Browse files
authored
display a list of all blogs (#90)
1 parent 5575867 commit c56d78b

File tree

2 files changed

+71
-7
lines changed

2 files changed

+71
-7
lines changed

app/Route/Blog.elm

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ module Route.Blog exposing (Model, Msg, route, Data, ActionData)
88

99
import Article
1010
import BackendTask exposing (BackendTask)
11+
import Colours
1112
import Css exposing (..)
13+
import Date exposing (Date)
1214
import Effect
1315
import ErrorPage
1416
import FatalError exposing (FatalError)
1517
import Head
1618
import Head.Seo as Seo
17-
import Html.Styled as Html exposing (Attribute, Html, styled)
18-
import Html.Styled.Attributes exposing (css)
19+
import Html as HtmlOriginal
20+
import Html.Styled as Html exposing (Html, styled)
21+
import Html.Styled.Attributes exposing (css, fromUnstyled)
1922
import Pages.Url
2023
import PagesMsg
2124
import Route exposing (Route)
@@ -24,6 +27,7 @@ import Server.Request
2427
import Server.Response
2528
import Shared
2629
import UrlPath
30+
import Util
2731
import View exposing (View)
2832

2933

@@ -88,19 +92,20 @@ view :
8892
-> View msg
8993
view app shared =
9094
{ title = "Blog | Joshua Ji"
91-
, body = [ content ]
95+
, body = [ content app.data ]
9296
}
9397

9498

95-
content : Html msg
96-
content =
99+
content : Data -> Html msg
100+
content articles =
97101
Html.div
98102
[ css
99103
[ maxWidth (px 900)
100104
, margin2 zero auto
101105
, displayFlex
102106
, flexDirection column
103-
, property "gap" "4em"
107+
, property "gap" "1em"
108+
, padding (em 1)
104109
]
105110
]
106111
[ Html.h1
@@ -111,4 +116,63 @@ content =
111116
]
112117
]
113118
[ Html.text "Blog" ]
119+
, Html.div
120+
[ css
121+
[ Util.flexDirection Util.Column
122+
, property "gap" "1em"
123+
]
124+
]
125+
<|
126+
List.map viewBlogPost articles
127+
]
128+
129+
130+
viewBlogPost : ( Route, Article.ArticleMetadata ) -> Html msg
131+
viewBlogPost ( route_, metadata ) =
132+
Html.div
133+
[ css
134+
[ Util.flexDirection Util.Column
135+
, width (pct 100)
136+
, padding (em 1.5)
137+
, border3 (px 1) solid (Colours.toCss Colours.gray)
138+
, borderRadius (em 0.5)
139+
, hover
140+
[ borderColor (Colours.toCss Colours.black) ]
141+
, property "gap" "0.5em"
142+
]
143+
]
144+
[ Route.toLink (blogPostTitle metadata) route_
145+
, blogDate metadata.published
146+
, blogDescription metadata.description
114147
]
148+
149+
150+
blogPostTitle : Article.ArticleMetadata -> List (HtmlOriginal.Attribute msg) -> Html msg
151+
blogPostTitle metadata attrs =
152+
Html.a
153+
([ css
154+
[ fontSize (em 1.25)
155+
, fontWeight bold
156+
, textDecoration none
157+
, color (Colours.toCss Colours.black)
158+
, hover
159+
[ color (Colours.toCss Colours.themeBlue) ]
160+
]
161+
]
162+
++ List.map fromUnstyled attrs
163+
)
164+
[ Html.text metadata.title ]
165+
166+
167+
blogDate : Date -> Html msg
168+
blogDate date =
169+
Html.p
170+
[ css
171+
[ fontSize (em 0.75) ]
172+
]
173+
[ Html.text <| Date.format "MMM d y" date ]
174+
175+
176+
blogDescription : String -> Html msg
177+
blogDescription description =
178+
Html.p [] [ Html.text description ]

blog/hello-world.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
author: Joshua Ji
33
title: Hello World!
4-
description: Testing my blog
4+
description: My first blog post
55
draft: false
66
published: "2024-03-29"
77
---

0 commit comments

Comments
 (0)