mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-30 23:47:42 +03:00
Add author page.
This commit is contained in:
parent
8dbe87d370
commit
e08e68677f
10
examples/docs/content/authors/dillon-kearns.md
Normal file
10
examples/docs/content/authors/dillon-kearns.md
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
{
|
||||
"name": "Dillon Kearns",
|
||||
"avatar": "/images/dillon.jpg",
|
||||
"bio": "Elm developer and educator. Founder of Incremental Elm Consulting.",
|
||||
"type": "author",
|
||||
}
|
||||
---
|
||||
|
||||
Elm developer and educator. Founder of [Incremental Elm Consulting](https://incrementalelm.com).
|
@ -61,14 +61,19 @@ application config =
|
||||
|
||||
allPages : List (Path PathKey Path.ToPage)
|
||||
allPages =
|
||||
[ (buildPage [ "blog", "types-over-conventions" ])
|
||||
[ (buildPage [ "authors", "dillon-kearns" ])
|
||||
, (buildPage [ "blog", "types-over-conventions" ])
|
||||
, (buildPage [ "docs", "directory-structure" ])
|
||||
, (buildPage [ "docs" ])
|
||||
, (buildPage [ ])
|
||||
]
|
||||
|
||||
pages =
|
||||
{ blog =
|
||||
{ authors =
|
||||
{ dillonKearns = (buildPage [ "authors", "dillon-kearns" ])
|
||||
, all = [ (buildPage [ "authors", "dillon-kearns" ]) ]
|
||||
}
|
||||
, blog =
|
||||
{ typesOverConventions = (buildPage [ "blog", "types-over-conventions" ])
|
||||
, all = [ (buildPage [ "blog", "types-over-conventions" ]) ]
|
||||
}
|
||||
@ -120,6 +125,12 @@ isValidRoute route =
|
||||
content : List ( List String, { extension: String, frontMatter : String, body : Maybe String } )
|
||||
content =
|
||||
[
|
||||
( ["authors", "dillon-kearns"]
|
||||
, { frontMatter = """{"name":"Dillon Kearns","avatar":"/images/dillon.jpg","bio":"Elm developer and educator. Founder of Incremental Elm Consulting.","type":"author"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
,
|
||||
( ["blog", "types-over-conventions"]
|
||||
, { frontMatter = """{"type":"blog","author":"Dillon Kearns","title":"Types Over Conventions","description":"TODO","published":"2019-09-09"}
|
||||
""" , body = Nothing
|
||||
|
@ -27,6 +27,9 @@ view posts =
|
||||
Metadata.Article meta ->
|
||||
Nothing
|
||||
|
||||
Metadata.Author _ ->
|
||||
Nothing
|
||||
|
||||
Metadata.Doc meta ->
|
||||
Just ( path, meta )
|
||||
)
|
||||
|
@ -12,6 +12,7 @@ import Element.Region
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as Attr
|
||||
import Json.Decode
|
||||
import MarkdownRenderer
|
||||
import Metadata exposing (Metadata)
|
||||
@ -22,6 +23,7 @@ import Pages.Manifest.Category
|
||||
import Pages.Path as Path
|
||||
import PagesNew exposing (images, pages)
|
||||
import Palette
|
||||
import View.Avatar as Avatar
|
||||
|
||||
|
||||
manifest : Manifest.Config PagesNew.PathKey
|
||||
@ -144,10 +146,7 @@ pageView model siteMetadata page =
|
||||
]
|
||||
(Palette.blogHeading metadata.title
|
||||
:: publishedDateView metadata
|
||||
:: Element.image
|
||||
[ Element.width (Element.px 70)
|
||||
]
|
||||
{ src = Path.toString metadata.author.avatar, description = metadata.author.name }
|
||||
:: Avatar.view metadata.author
|
||||
:: Tuple.second page.view
|
||||
)
|
||||
]
|
||||
@ -180,6 +179,27 @@ pageView model siteMetadata page =
|
||||
]
|
||||
}
|
||||
|
||||
Metadata.Author author ->
|
||||
{ title = author.name
|
||||
, body =
|
||||
Element.column
|
||||
[ Element.width Element.fill
|
||||
]
|
||||
[ header
|
||||
, Element.column
|
||||
[ Element.padding 30
|
||||
, Element.spacing 20
|
||||
, Element.Region.mainContent
|
||||
, Element.width (Element.fill |> Element.maximum 800)
|
||||
, Element.centerX
|
||||
]
|
||||
[ Palette.blogHeading author.name
|
||||
, Avatar.view author
|
||||
, Element.paragraph [ Element.centerX, Font.center ] (Tuple.second page.view)
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
header : Element msg
|
||||
header =
|
||||
@ -282,6 +302,41 @@ head metadata =
|
||||
, expirationTime = Nothing
|
||||
}
|
||||
|
||||
Metadata.Author meta ->
|
||||
let
|
||||
( firstName, lastName ) =
|
||||
case meta.name |> String.split " " of
|
||||
[ first, last ] ->
|
||||
( first, last )
|
||||
|
||||
[ first, middle, last ] ->
|
||||
( first ++ " " ++ middle, last )
|
||||
|
||||
[] ->
|
||||
( "", "" )
|
||||
|
||||
_ ->
|
||||
( meta.name, "" )
|
||||
in
|
||||
Seo.summary
|
||||
{ canonicalUrlOverride = Nothing
|
||||
, siteName = "elm-pages"
|
||||
, image =
|
||||
{ url = meta.avatar
|
||||
, alt = meta.name ++ "'s elm-pages articles."
|
||||
, dimensions = Nothing
|
||||
, mimeType = Nothing
|
||||
}
|
||||
, description = meta.bio
|
||||
, locale = Nothing
|
||||
, title = meta.name ++ "'s elm-pages articles."
|
||||
}
|
||||
|> Seo.profile
|
||||
{ firstName = firstName
|
||||
, lastName = lastName
|
||||
, username = Nothing
|
||||
}
|
||||
|
||||
|
||||
canonicalSiteUrl : String
|
||||
canonicalSiteUrl =
|
||||
|
@ -14,13 +14,14 @@ type Metadata
|
||||
= Page PageMetadata
|
||||
| Article ArticleMetadata
|
||||
| Doc DocMetadata
|
||||
| Author AuthorMetadata
|
||||
|
||||
|
||||
type alias ArticleMetadata =
|
||||
{ title : String
|
||||
, description : String
|
||||
, published : Date
|
||||
, author : Author
|
||||
, author : AuthorMetadata
|
||||
}
|
||||
|
||||
|
||||
@ -46,6 +47,13 @@ decoder =
|
||||
Decode.field "title" Decode.string
|
||||
|> Decode.map (\title -> Page { title = title })
|
||||
|
||||
"author" ->
|
||||
Decode.map3 AuthorMetadata
|
||||
(Decode.field "name" Decode.string)
|
||||
(Decode.field "avatar" imageDecoder)
|
||||
(Decode.field "bio" Decode.string)
|
||||
|> Decode.map Author
|
||||
|
||||
"blog" ->
|
||||
Decode.map4 ArticleMetadata
|
||||
(Decode.field "title" Decode.string)
|
||||
@ -71,13 +79,14 @@ decoder =
|
||||
)
|
||||
|
||||
|
||||
type alias Author =
|
||||
type alias AuthorMetadata =
|
||||
{ name : String
|
||||
, avatar : Path PagesNew.PathKey Path.ToImage
|
||||
, bio : String
|
||||
}
|
||||
|
||||
|
||||
authorDecoder : Decoder Author
|
||||
authorDecoder : Decoder AuthorMetadata
|
||||
authorDecoder =
|
||||
Decode.string
|
||||
|> Decode.andThen
|
||||
@ -85,6 +94,7 @@ authorDecoder =
|
||||
Decode.succeed
|
||||
{ name = "Dillon Kearns"
|
||||
, avatar = PagesNew.images.dillon
|
||||
, bio = ""
|
||||
}
|
||||
)
|
||||
|
||||
|
13
examples/docs/src/View/Avatar.elm
Normal file
13
examples/docs/src/View/Avatar.elm
Normal file
@ -0,0 +1,13 @@
|
||||
module View.Avatar exposing (view)
|
||||
|
||||
import Element
|
||||
import Html.Attributes as Attr
|
||||
import Pages.Path as Path
|
||||
|
||||
|
||||
view author =
|
||||
Element.image
|
||||
[ Element.width (Element.px 70)
|
||||
, Element.htmlAttribute (Attr.class "avatar")
|
||||
]
|
||||
{ src = Path.toString author.avatar, description = author.name }
|
@ -14,3 +14,7 @@
|
||||
stroke-dashoffset: 10;
|
||||
}
|
||||
}
|
||||
|
||||
.avatar img {
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user