Skip to content

Commit

Permalink
display a list of all blogs (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuanianji authored Mar 30, 2024
1 parent 5575867 commit c56d78b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 7 deletions.
76 changes: 70 additions & 6 deletions app/Route/Blog.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ module Route.Blog exposing (Model, Msg, route, Data, ActionData)

import Article
import BackendTask exposing (BackendTask)
import Colours
import Css exposing (..)
import Date exposing (Date)
import Effect
import ErrorPage
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled as Html exposing (Attribute, Html, styled)
import Html.Styled.Attributes exposing (css)
import Html as HtmlOriginal
import Html.Styled as Html exposing (Html, styled)
import Html.Styled.Attributes exposing (css, fromUnstyled)
import Pages.Url
import PagesMsg
import Route exposing (Route)
Expand All @@ -24,6 +27,7 @@ import Server.Request
import Server.Response
import Shared
import UrlPath
import Util
import View exposing (View)


Expand Down Expand Up @@ -88,19 +92,20 @@ view :
-> View msg
view app shared =
{ title = "Blog | Joshua Ji"
, body = [ content ]
, body = [ content app.data ]
}


content : Html msg
content =
content : Data -> Html msg
content articles =
Html.div
[ css
[ maxWidth (px 900)
, margin2 zero auto
, displayFlex
, flexDirection column
, property "gap" "4em"
, property "gap" "1em"
, padding (em 1)
]
]
[ Html.h1
Expand All @@ -111,4 +116,63 @@ content =
]
]
[ Html.text "Blog" ]
, Html.div
[ css
[ Util.flexDirection Util.Column
, property "gap" "1em"
]
]
<|
List.map viewBlogPost articles
]


viewBlogPost : ( Route, Article.ArticleMetadata ) -> Html msg
viewBlogPost ( route_, metadata ) =
Html.div
[ css
[ Util.flexDirection Util.Column
, width (pct 100)
, padding (em 1.5)
, border3 (px 1) solid (Colours.toCss Colours.gray)
, borderRadius (em 0.5)
, hover
[ borderColor (Colours.toCss Colours.black) ]
, property "gap" "0.5em"
]
]
[ Route.toLink (blogPostTitle metadata) route_
, blogDate metadata.published
, blogDescription metadata.description
]


blogPostTitle : Article.ArticleMetadata -> List (HtmlOriginal.Attribute msg) -> Html msg
blogPostTitle metadata attrs =
Html.a
([ css
[ fontSize (em 1.25)
, fontWeight bold
, textDecoration none
, color (Colours.toCss Colours.black)
, hover
[ color (Colours.toCss Colours.themeBlue) ]
]
]
++ List.map fromUnstyled attrs
)
[ Html.text metadata.title ]


blogDate : Date -> Html msg
blogDate date =
Html.p
[ css
[ fontSize (em 0.75) ]
]
[ Html.text <| Date.format "MMM d y" date ]


blogDescription : String -> Html msg
blogDescription description =
Html.p [] [ Html.text description ]
2 changes: 1 addition & 1 deletion blog/hello-world.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
author: Joshua Ji
title: Hello World!
description: Testing my blog
description: My first blog post
draft: false
published: "2024-03-29"
---
Expand Down

0 comments on commit c56d78b

Please sign in to comment.