init
This commit is contained in:
145
app/Route/Blog/Slug_.elm
Normal file
145
app/Route/Blog/Slug_.elm
Normal file
@ -0,0 +1,145 @@
|
||||
module Route.Blog.Slug_ exposing (ActionData, Data, Model, Msg, route)
|
||||
|
||||
import Article
|
||||
import BackendTask exposing (BackendTask)
|
||||
import Date exposing (Date)
|
||||
import FatalError exposing (FatalError)
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
import Html.Styled exposing (..)
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Decode.Extra
|
||||
import Pages.Url
|
||||
import PagesMsg exposing (PagesMsg)
|
||||
import RouteBuilder exposing (App, StatelessRoute)
|
||||
import Shared
|
||||
import View exposing (View)
|
||||
|
||||
|
||||
import Markdown.Block
|
||||
import Markdown.Renderer
|
||||
import MarkdownCodec
|
||||
import TailwindMarkdownRenderer
|
||||
import Tailwind.Utilities as Tw
|
||||
|
||||
|
||||
type alias Model =
|
||||
{}
|
||||
|
||||
|
||||
type alias Msg =
|
||||
()
|
||||
|
||||
|
||||
type alias RouteParams =
|
||||
{ slug : String }
|
||||
|
||||
|
||||
route : StatelessRoute RouteParams Data ActionData
|
||||
route =
|
||||
RouteBuilder.preRender
|
||||
{ head = head
|
||||
, pages = pages
|
||||
, data = data
|
||||
}
|
||||
|> RouteBuilder.buildNoState { view = view }
|
||||
|
||||
|
||||
pages : BackendTask FatalError (List RouteParams)
|
||||
pages =
|
||||
Article.blogPostsGlob
|
||||
|> BackendTask.map
|
||||
(List.map
|
||||
(\globData ->
|
||||
{ slug = globData.slug }
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
type alias Data =
|
||||
{ metadata : ArticleMetadata
|
||||
, body : List Markdown.Block.Block
|
||||
}
|
||||
|
||||
type alias ActionData =
|
||||
{}
|
||||
|
||||
|
||||
data : RouteParams -> BackendTask FatalError Data
|
||||
data routeParams =
|
||||
MarkdownCodec.withFrontmatter Data
|
||||
frontmatterDecoder
|
||||
TailwindMarkdownRenderer.renderer
|
||||
("content/blog/" ++ routeParams.slug ++ ".md")
|
||||
|
||||
|
||||
type alias ArticleMetadata =
|
||||
{ title : String
|
||||
, description : String
|
||||
, published : Date
|
||||
-- , image : Pages.Url.Url
|
||||
, draft : Bool
|
||||
}
|
||||
|
||||
|
||||
frontmatterDecoder : Decoder ArticleMetadata
|
||||
frontmatterDecoder =
|
||||
Decode.map4 ArticleMetadata
|
||||
(Decode.field "title" Decode.string)
|
||||
(Decode.field "description" Decode.string)
|
||||
(Decode.field "published"
|
||||
(Decode.string
|
||||
|> Decode.andThen
|
||||
(\isoString ->
|
||||
Date.fromIsoString isoString
|
||||
|> Json.Decode.Extra.fromResult
|
||||
)
|
||||
)
|
||||
)
|
||||
-- (Decode.oneOf
|
||||
-- [ Decode.field "image" imageDecoder
|
||||
-- , Decode.field "unsplash" UnsplashImage.decoder |> Decode.map UnsplashImage.imagePath
|
||||
-- ]
|
||||
-- )
|
||||
(Decode.field "draft" Decode.bool
|
||||
|> Decode.maybe
|
||||
|> Decode.map (Maybe.withDefault False)
|
||||
)
|
||||
|
||||
head :
|
||||
App Data ActionData RouteParams
|
||||
-> List Head.Tag
|
||||
head app =
|
||||
Seo.summary
|
||||
{ canonicalUrlOverride = Nothing
|
||||
, siteName = "elm-pages"
|
||||
, image =
|
||||
{ url = Pages.Url.external "TODO"
|
||||
, alt = "elm-pages logo"
|
||||
, dimensions = Nothing
|
||||
, mimeType = Nothing
|
||||
}
|
||||
, description = "TODO"
|
||||
, locale = Nothing
|
||||
, title = "TODO title" -- metadata.title -- TODO
|
||||
}
|
||||
|> Seo.website
|
||||
|
||||
|
||||
view :
|
||||
App Data ActionData RouteParams
|
||||
-> Shared.Model
|
||||
-> View (PagesMsg Msg)
|
||||
view app shared =
|
||||
{ title = "title"
|
||||
, body =
|
||||
(app.data.body
|
||||
|> Markdown.Renderer.render TailwindMarkdownRenderer.renderer
|
||||
|> Result.withDefault []
|
||||
|> processReturn
|
||||
)
|
||||
}
|
||||
|
||||
processReturn : List (Html Msg) -> List (Html (PagesMsg Msg))
|
||||
processReturn =
|
||||
List.map (Html.Styled.map (PagesMsg.fromMsg))
|
94
app/Route/Index.elm
Normal file
94
app/Route/Index.elm
Normal file
@ -0,0 +1,94 @@
|
||||
module Route.Index exposing (ActionData, Data, Model, Msg, route)
|
||||
|
||||
import BackendTask exposing (BackendTask)
|
||||
import FatalError exposing (FatalError)
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
import Html.Styled as Html
|
||||
import Link exposing (Link)
|
||||
import Pages.Url
|
||||
import PagesMsg exposing (PagesMsg)
|
||||
import UrlPath
|
||||
import Route
|
||||
import RouteBuilder exposing (App, StatelessRoute)
|
||||
import Shared
|
||||
import View exposing (View)
|
||||
|
||||
|
||||
type alias Model =
|
||||
{}
|
||||
|
||||
|
||||
type alias Msg =
|
||||
()
|
||||
|
||||
|
||||
type alias RouteParams =
|
||||
{}
|
||||
|
||||
|
||||
type alias Data =
|
||||
{ message : String
|
||||
}
|
||||
|
||||
|
||||
type alias ActionData =
|
||||
{}
|
||||
|
||||
|
||||
route : StatelessRoute RouteParams Data ActionData
|
||||
route =
|
||||
RouteBuilder.single
|
||||
{ head = head
|
||||
, data = data
|
||||
}
|
||||
|> RouteBuilder.buildNoState { view = view }
|
||||
|
||||
|
||||
data : BackendTask FatalError Data
|
||||
data =
|
||||
BackendTask.succeed Data
|
||||
|> BackendTask.andMap
|
||||
(BackendTask.succeed "Hello!")
|
||||
|
||||
|
||||
head :
|
||||
App Data ActionData RouteParams
|
||||
-> List Head.Tag
|
||||
head app =
|
||||
Seo.summary
|
||||
{ canonicalUrlOverride = Nothing
|
||||
, siteName = "elm-pages"
|
||||
, image =
|
||||
{ url = [ "images", "icon-png.png" ] |> UrlPath.join |> Pages.Url.fromPath
|
||||
, alt = "elm-pages logo"
|
||||
, dimensions = Nothing
|
||||
, mimeType = Nothing
|
||||
}
|
||||
, description = "Welcome to elm-pages!"
|
||||
, locale = Nothing
|
||||
, title = "elm-pages is running"
|
||||
}
|
||||
|> Seo.website
|
||||
|
||||
|
||||
view :
|
||||
App Data ActionData RouteParams
|
||||
-> Shared.Model
|
||||
-> View (PagesMsg Msg)
|
||||
view app shared =
|
||||
{ title = "elm-pages is running"
|
||||
, body =
|
||||
[ Html.h1 [] [ Html.text "elm-pages is up and running!" ]
|
||||
, Html.p []
|
||||
[ Html.text <| "The message is: " ++ app.data.message
|
||||
]
|
||||
, Link.link (Link.internal (Route.Blog__Slug_ { slug = "a" })) [] [ Html.text "My blog post" ]
|
||||
]
|
||||
|> processReturn
|
||||
}
|
||||
|
||||
|
||||
processReturn : List (Html.Html Msg) -> List (Html.Html (PagesMsg Msg))
|
||||
processReturn =
|
||||
List.map (Html.map (PagesMsg.fromMsg))
|
Reference in New Issue
Block a user