mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-30 23:47:42 +03:00
Add published metadata to blog posts.
This commit is contained in:
parent
11c3503a25
commit
1c5749d1cf
@ -1,7 +1,11 @@
|
||||
---
|
||||
author: Dillon Kearns
|
||||
title: Types Over Conventions
|
||||
description: TODO
|
||||
{
|
||||
"type": "blog",
|
||||
"author": "Dillon Kearns",
|
||||
"title": "Types Over Conventions",
|
||||
"description": "TODO",
|
||||
"published": "2019-09-09",
|
||||
}
|
||||
---
|
||||
|
||||
Rails started a movement of simplifying project setup with [a philosophy of "Convention Over Configuration"](https://rubyonrails.org/doctrine/#convention-over-configuration). This made for a very easy experience bootstrapping a new web server. The downside is that you have a lot of implicit rules that can be hard to follow.
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
title: elm-pages - a statically typed site generator
|
||||
type: page
|
||||
---
|
||||
|
||||
<Banner>A **statically typed** site generator</Banner>
|
||||
|
@ -1,14 +0,0 @@
|
||||
---
|
||||
title: Hello from markdown! 👋
|
||||
---
|
||||
|
||||
# Welcome to `elm-pages`! 🚀
|
||||
|
||||
`elm-pages`
|
||||
|
||||
Looks like it's working!
|
||||
|
||||
Here's a list:
|
||||
|
||||
- This is an item
|
||||
- And so is this
|
@ -22,6 +22,7 @@
|
||||
"elm-community/result-extra": "2.2.1",
|
||||
"elm-community/string-extra": "4.0.1",
|
||||
"elm-explorations/markdown": "1.0.0",
|
||||
"justinmimbs/date": "3.1.2",
|
||||
"lukewestby/elm-string-interpolate": "1.0.3",
|
||||
"mdgriffith/elm-markup": "3.0.1",
|
||||
"mdgriffith/elm-ui": "1.1.4",
|
||||
|
@ -65,7 +65,6 @@ allPages =
|
||||
, (buildPage [ "docs", "directory-structure" ])
|
||||
, (buildPage [ "docs" ])
|
||||
, (buildPage [ ])
|
||||
, (buildPage [ "markdown" ])
|
||||
]
|
||||
|
||||
pages =
|
||||
@ -79,8 +78,7 @@ pages =
|
||||
, all = [ (buildPage [ "docs", "directory-structure" ]), (buildPage [ "docs" ]) ]
|
||||
}
|
||||
, index = (buildPage [ ])
|
||||
, markdown = (buildPage [ "markdown" ])
|
||||
, all = [ (buildPage [ ]), (buildPage [ "markdown" ]) ]
|
||||
, all = [ (buildPage [ ]) ]
|
||||
}
|
||||
|
||||
images =
|
||||
@ -121,7 +119,7 @@ content : List ( List String, { extension: String, frontMatter : String, body :
|
||||
content =
|
||||
[
|
||||
( ["blog", "types-over-conventions"]
|
||||
, { frontMatter = """{"author":"Dillon Kearns","title":"Types Over Conventions","description":"TODO"}
|
||||
, { frontMatter = """{"type":"blog","author":"Dillon Kearns","title":"Types Over Conventions","description":"TODO","published":"2019-09-09"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
@ -139,13 +137,7 @@ content =
|
||||
} )
|
||||
,
|
||||
( []
|
||||
, { frontMatter = """{"title":"elm-pages - a statically typed site generator"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
,
|
||||
( ["markdown"]
|
||||
, { frontMatter = """{"title":"Hello from markdown! 👋"}
|
||||
, { frontMatter = """{"title":"elm-pages - a statically typed site generator","type":"page"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
|
@ -1,6 +1,7 @@
|
||||
module Main exposing (main)
|
||||
|
||||
import Color
|
||||
import Date
|
||||
import DocSidebar
|
||||
import DocumentSvg
|
||||
import Element exposing (Element)
|
||||
@ -62,32 +63,48 @@ markdownDocument =
|
||||
Pages.Document.parser
|
||||
{ extension = "md"
|
||||
, metadata =
|
||||
Json.Decode.oneOf
|
||||
[ Json.Decode.map3
|
||||
(\author title description ->
|
||||
Metadata.Article
|
||||
{ author = author
|
||||
, title = title
|
||||
, description = description
|
||||
}
|
||||
)
|
||||
(Json.Decode.field "author" Json.Decode.string)
|
||||
(Json.Decode.field "title" Json.Decode.string)
|
||||
(Json.Decode.field "description" Json.Decode.string)
|
||||
, Json.Decode.map2
|
||||
(\title maybeType ->
|
||||
case maybeType of
|
||||
Just "doc" ->
|
||||
Metadata.Doc { title = title }
|
||||
Json.Decode.field "type" Json.Decode.string
|
||||
|> Json.Decode.andThen
|
||||
(\pageType ->
|
||||
case pageType of
|
||||
"doc" ->
|
||||
Json.Decode.field "title" Json.Decode.string
|
||||
|> Json.Decode.map (\title -> Metadata.Doc { title = title })
|
||||
|
||||
"page" ->
|
||||
Json.Decode.field "title" Json.Decode.string
|
||||
|> Json.Decode.map (\title -> Metadata.Page { title = title })
|
||||
|
||||
"blog" ->
|
||||
Json.Decode.map4
|
||||
(\author title description published ->
|
||||
Metadata.Article
|
||||
{ author = author
|
||||
, title = title
|
||||
, description = description
|
||||
, published = published
|
||||
}
|
||||
)
|
||||
(Json.Decode.field "author" Json.Decode.string)
|
||||
(Json.Decode.field "title" Json.Decode.string)
|
||||
(Json.Decode.field "description" Json.Decode.string)
|
||||
(Json.Decode.field "published"
|
||||
(Json.Decode.string
|
||||
|> Json.Decode.andThen
|
||||
(\isoString ->
|
||||
case Date.fromIsoString isoString of
|
||||
Ok date ->
|
||||
Json.Decode.succeed date
|
||||
|
||||
Err error ->
|
||||
Json.Decode.fail error
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
_ ->
|
||||
Metadata.Page { title = title }
|
||||
Json.Decode.fail <| "Unexpected page type " ++ pageType
|
||||
)
|
||||
(Json.Decode.field "title" Json.Decode.string)
|
||||
(Json.Decode.field "type" Json.Decode.string
|
||||
|> Json.Decode.maybe
|
||||
)
|
||||
]
|
||||
, body = MarkdownRenderer.view
|
||||
}
|
||||
|
||||
@ -296,7 +313,7 @@ head metadata =
|
||||
|> Seo.article
|
||||
{ tags = []
|
||||
, section = Nothing
|
||||
, publishedTime = Nothing
|
||||
, publishedTime = Just "May 13"
|
||||
, modifiedTime = Nothing
|
||||
, expirationTime = Nothing
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
module Metadata exposing (ArticleMetadata, DocMetadata, Metadata(..), PageMetadata)
|
||||
|
||||
import Date exposing (Date)
|
||||
import Dict exposing (Dict)
|
||||
import Element exposing (Element)
|
||||
import Element.Font as Font
|
||||
@ -12,7 +13,11 @@ type Metadata msg
|
||||
|
||||
|
||||
type alias ArticleMetadata =
|
||||
{ author : String, title : String, description : String }
|
||||
{ author : String
|
||||
, title : String
|
||||
, description : String
|
||||
, published : Date
|
||||
}
|
||||
|
||||
|
||||
type alias DocMetadata =
|
||||
@ -22,44 +27,3 @@ type alias DocMetadata =
|
||||
|
||||
type alias PageMetadata =
|
||||
{ title : String }
|
||||
|
||||
|
||||
gather : List { styled : Element msg, raw : String } -> { styled : List (Element msg), raw : String }
|
||||
gather myList =
|
||||
let
|
||||
styled =
|
||||
myList
|
||||
|> List.map .styled
|
||||
|
||||
raw =
|
||||
myList
|
||||
|> List.map .raw
|
||||
|> String.join " "
|
||||
in
|
||||
{ styled = styled, raw = raw }
|
||||
|
||||
|
||||
viewText : { a | bold : Bool, italic : Bool, strike : Bool } -> String -> Element msg
|
||||
viewText styles string =
|
||||
Element.el (stylesFor styles) (Element.text string)
|
||||
|
||||
|
||||
stylesFor : { a | bold : Bool, italic : Bool, strike : Bool } -> List (Element.Attribute b)
|
||||
stylesFor styles =
|
||||
[ if styles.bold then
|
||||
Just Font.bold
|
||||
|
||||
else
|
||||
Nothing
|
||||
, if styles.italic then
|
||||
Just Font.italic
|
||||
|
||||
else
|
||||
Nothing
|
||||
, if styles.strike then
|
||||
Just Font.strike
|
||||
|
||||
else
|
||||
Nothing
|
||||
]
|
||||
|> List.filterMap identity
|
||||
|
Loading…
Reference in New Issue
Block a user