2019-08-25 04:58:48 +03:00
|
|
|
port module PagesNew exposing (application, PageRoute, all, pages, routeToString, Image, imageUrl, images)
|
2019-08-19 18:54:28 +03:00
|
|
|
|
|
|
|
import Dict exposing (Dict)
|
2019-08-25 04:58:48 +03:00
|
|
|
import Color exposing (Color)
|
2019-08-19 18:54:28 +03:00
|
|
|
import Head
|
|
|
|
import Html exposing (Html)
|
|
|
|
import Json.Decode
|
|
|
|
import Json.Encode
|
|
|
|
import Mark
|
2019-08-19 19:25:43 +03:00
|
|
|
import Pages
|
2019-08-19 18:54:28 +03:00
|
|
|
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)
|
2019-08-19 19:25:43 +03:00
|
|
|
import RawContent
|
2019-08-25 04:58:48 +03:00
|
|
|
import Url.Parser as Url exposing ((</>), s)
|
|
|
|
import Pages.Document
|
2019-08-19 18:54:28 +03:00
|
|
|
|
|
|
|
|
2019-08-19 19:25:43 +03:00
|
|
|
port toJsPort : Json.Encode.Value -> Cmd msg
|
2019-08-19 18:54:28 +03:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2019-08-19 18:54:28 +03:00
|
|
|
}
|
2019-08-19 19:25:43 +03:00
|
|
|
-> Pages.Program userModel userMsg metadata view
|
2019-08-19 18:54:28 +03:00
|
|
|
application config =
|
2019-08-20 00:50:33 +03:00
|
|
|
Pages.application
|
2019-08-19 19:25:43 +03:00
|
|
|
{ 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
|
2019-08-19 19:25:43 +03:00
|
|
|
, 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-19 18:54:28 +03:00
|
|
|
}
|
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 "/")
|
|
|
|
|