elm-pages-v3-beta/examples/docs/gen/PagesNew.elm

118 lines
3.7 KiB
Elm
Raw Normal View History

2019-08-25 04:58:48 +03:00
port module PagesNew exposing (application, PageRoute, all, pages, routeToString, Image, imageUrl, images)
import Dict exposing (Dict)
2019-08-25 04:58:48 +03:00
import Color exposing (Color)
import Head
import Html exposing (Html)
import Json.Decode
import Json.Encode
import Mark
import Pages
import Pages.ContentCache exposing (Page)
2019-08-25 04:58:48 +03:00
import Pages.Manifest exposing (DisplayMode, Orientation)
import Pages.Manifest.Category as Category exposing (Category)
import RawContent
2019-08-25 04:58:48 +03:00
import Url.Parser as Url exposing ((</>), s)
import Pages.Document
port toJsPort : Json.Encode.Value -> Cmd msg
application :
{ init : ( userModel, Cmd userMsg )
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
, subscriptions : userModel -> Sub userMsg
, view : userModel -> List ( List String, metadata ) -> Page metadata view -> { title : String, body : Html userMsg }
, head : metadata -> List Head.Tag
2019-08-25 04:58:48 +03:00
, documents : List (Pages.Document.DocumentParser metadata view)
, manifest :
{ backgroundColor : Maybe Color
, categories : List Category
, displayMode : DisplayMode
, orientation : Orientation
, description : String
, iarcRatingId : Maybe String
, name : String
, themeColor : Maybe Color
, startUrl : PageRoute
, shortName : Maybe String
, sourceIcon : Image
}
}
-> Pages.Program userModel userMsg metadata view
application config =
2019-08-20 00:50:33 +03:00
Pages.application
{ init = config.init
, view = config.view
, update = config.update
, subscriptions = config.subscriptions
2019-08-25 04:58:48 +03:00
, document = Dict.fromList config.documents
, content = RawContent.content
, toJsPort = toJsPort
, head = config.head
2019-08-25 04:58:48 +03:00
, manifest =
{ backgroundColor = config.manifest.backgroundColor
, categories = config.manifest.categories
, displayMode = config.manifest.displayMode
, orientation = config.manifest.orientation
, description = config.manifest.description
, iarcRatingId = config.manifest.iarcRatingId
, name = config.manifest.name
, themeColor = config.manifest.themeColor
, startUrl = Just (routeToString config.manifest.startUrl)
, shortName = config.manifest.shortName
, sourceIcon = "./" ++ imageUrl config.manifest.sourceIcon
}
}
type PageRoute = PageRoute (List String)
type Image = Image (List String)
imageUrl : Image -> String
imageUrl (Image path) =
"/"
++ String.join "/" ("images" :: path)
all : List PageRoute
all =
[ (PageRoute [ "about" ])
, (PageRoute [ "docs", "file-structure" ])
, (PageRoute [ "docs" ])
, (PageRoute [ ])
]
pages =
{ about = (PageRoute [ "about" ])
, docs =
{ fileStructure = (PageRoute [ "docs", "file-structure" ])
, index = (PageRoute [ "docs" ])
, all = [ (PageRoute [ "docs", "file-structure" ]), (PageRoute [ "docs" ]) ]
}
2019-08-25 04:58:48 +03:00
, index = (PageRoute [ ])
, all = [ (PageRoute [ "about" ]), (PageRoute [ ]) ]
}
urlParser : Url.Parser (PageRoute -> a) a
urlParser =
Url.oneOf
[ Url.map (PageRoute [ "about" ]) (s "about")
, Url.map (PageRoute [ "docs", "file-structure" ]) (s "docs" </> s "file-structure")
, Url.map (PageRoute [ "docs" ]) (s "docs" </> s "index")
, Url.map (PageRoute [ ]) (s "index")
]
images =
{ icon = (Image [ "icon.svg" ])
, mountains = (Image [ "mountains.jpg" ])
, all = [ (Image [ "icon.svg" ]), (Image [ "mountains.jpg" ]) ]
}
routeToString : PageRoute -> String
routeToString (PageRoute route) =
"/"
++ (route |> String.join "/")