mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-15 22:33:47 +03:00
447 lines
16 KiB
Plaintext
447 lines
16 KiB
Plaintext
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
|
|
exports[`generate UI file 1`] = `
|
|
"port module Pages exposing (PathKey, allPages, allImages, internals, images, isValidRoute, pages, builtAt)
|
|
|
|
import Color exposing (Color)
|
|
import Pages.Internal
|
|
import Head
|
|
import Html exposing (Html)
|
|
import Json.Decode
|
|
import Json.Encode
|
|
import Pages.Platform
|
|
import Pages.Manifest exposing (DisplayMode, Orientation)
|
|
import Pages.Manifest.Category as Category exposing (Category)
|
|
import Url.Parser as Url exposing ((</>), s)
|
|
import Pages.ImagePath as ImagePath exposing (ImagePath)
|
|
import Pages.PagePath as PagePath exposing (PagePath)
|
|
import Pages.Directory as Directory exposing (Directory)
|
|
import Time
|
|
|
|
|
|
builtAt : Time.Posix
|
|
builtAt =
|
|
Time.millisToPosix 1589734402000
|
|
|
|
|
|
type PathKey
|
|
= PathKey
|
|
|
|
|
|
buildImage : List String -> ImagePath.Dimensions -> ImagePath PathKey
|
|
buildImage path dimensions =
|
|
ImagePath.build PathKey (\\"images\\" :: path) dimensions
|
|
|
|
|
|
buildPage : List String -> PagePath PathKey
|
|
buildPage path =
|
|
PagePath.build PathKey path
|
|
|
|
|
|
directoryWithIndex : List String -> Directory PathKey Directory.WithIndex
|
|
directoryWithIndex path =
|
|
Directory.withIndex PathKey allPages path
|
|
|
|
|
|
directoryWithoutIndex : List String -> Directory PathKey Directory.WithoutIndex
|
|
directoryWithoutIndex path =
|
|
Directory.withoutIndex PathKey allPages path
|
|
|
|
|
|
port toJsPort : Json.Encode.Value -> Cmd msg
|
|
|
|
port fromJsPort : (Json.Decode.Value -> msg) -> Sub msg
|
|
|
|
|
|
internals : Pages.Internal.Internal PathKey
|
|
internals =
|
|
{ applicationType = Pages.Internal.Browser
|
|
, toJsPort = toJsPort
|
|
, fromJsPort = fromJsPort identity
|
|
, content = content
|
|
, pathKey = PathKey
|
|
}
|
|
|
|
|
|
|
|
|
|
allPages : List (PagePath PathKey)
|
|
allPages =
|
|
[
|
|
]
|
|
|
|
pages =
|
|
{ directory = directoryWithoutIndex []
|
|
}
|
|
|
|
images =
|
|
{ staticHttpError = (buildImage [ \\"static-http-error.png\\" ] { width = 919, height = 105 })
|
|
, directory = directoryWithoutIndex []
|
|
}
|
|
|
|
|
|
allImages : List (ImagePath PathKey)
|
|
allImages =
|
|
[(buildImage [ \\"static-http-error.png\\" ] { width = 919, height = 105 })
|
|
]
|
|
|
|
|
|
isValidRoute : String -> Result String ()
|
|
isValidRoute route =
|
|
let
|
|
validRoutes =
|
|
List.map PagePath.toString allPages
|
|
in
|
|
if
|
|
(route |> String.startsWith \\"http://\\")
|
|
|| (route |> String.startsWith \\"https://\\")
|
|
|| (route |> String.startsWith \\"#\\")
|
|
|| (validRoutes |> List.member route)
|
|
then
|
|
Ok ()
|
|
|
|
else
|
|
(\\"Valid routes:\\\\n\\"
|
|
++ String.join \\"\\\\n\\\\n\\" validRoutes
|
|
)
|
|
|> Err
|
|
|
|
|
|
content : List ( List String, { extension: String, frontMatter : String, body : Maybe String } )
|
|
content =
|
|
[
|
|
]
|
|
"
|
|
`;
|
|
|
|
exports[`generate template module connector 1`] = `
|
|
"module TemplateDemultiplexer exposing (..)
|
|
|
|
import Browser
|
|
import Element exposing (Element)
|
|
import Global
|
|
import GlobalMetadata as M exposing (Metadata)
|
|
import Head
|
|
import Html exposing (Html)
|
|
import MarkdownRenderer
|
|
import Pages
|
|
import Pages.PagePath exposing (PagePath)
|
|
import Pages.Platform
|
|
import Pages.StaticHttp as StaticHttp
|
|
import SiteConfig
|
|
import Template.BlogIndex
|
|
import Template.BlogPost
|
|
import Template.Documentation
|
|
import Template.Page
|
|
import Template.Showcase
|
|
|
|
|
|
type alias Model =
|
|
{ global : Global.Model
|
|
, page : TemplateModel
|
|
}
|
|
|
|
|
|
type TemplateModel
|
|
= ModelBlogPost Template.BlogPost.Model
|
|
| ModelShowcase Template.Showcase.Model
|
|
| ModelPage Template.Page.Model
|
|
| ModelDocumentation Template.Documentation.Model
|
|
| ModelBlogIndex Template.BlogIndex.Model
|
|
|
|
|
|
type Msg
|
|
= MsgBlogPost Template.BlogPost.Msg
|
|
| MsgBlogIndex Template.BlogIndex.Msg
|
|
| MsgGlobal Global.Msg
|
|
| OnPageChange
|
|
{ path : PagePath Pages.PathKey
|
|
, query : Maybe String
|
|
, fragment : Maybe String
|
|
, metadata : Metadata
|
|
}
|
|
|
|
|
|
type alias View =
|
|
( MarkdownRenderer.TableOfContents, List (Element Never) )
|
|
|
|
|
|
view :
|
|
List ( PagePath Pages.PathKey, Metadata )
|
|
->
|
|
{ path : PagePath Pages.PathKey
|
|
, frontmatter : Metadata
|
|
}
|
|
->
|
|
StaticHttp.Request
|
|
{ view : Model -> View -> { title : String, body : Html Msg }
|
|
, head : List (Head.Tag Pages.PathKey)
|
|
}
|
|
view siteMetadata page =
|
|
case page.frontmatter of
|
|
M.MetadataBlogPost metadata ->
|
|
StaticHttp.map2
|
|
(data globalData ->
|
|
{ view =
|
|
model rendered ->
|
|
case model.page of
|
|
ModelBlogPost subModel ->
|
|
Template.BlogPost.template.view
|
|
siteMetadata
|
|
data
|
|
subModel
|
|
metadata
|
|
rendered
|
|
|> ({ title, body } ->
|
|
Global.wrapBody
|
|
globalData
|
|
page
|
|
model.global
|
|
MsgGlobal
|
|
{ title = title
|
|
, body =
|
|
-- Template.BlogPost.liftViewMsg
|
|
Element.map never body
|
|
}
|
|
)
|
|
|
|
_ ->
|
|
{ title = \\"\\", body = Html.text \\"\\" }
|
|
, head = Template.BlogPost.template.head data page.path metadata
|
|
}
|
|
)
|
|
(Template.BlogPost.template.staticData siteMetadata)
|
|
(Global.staticData siteMetadata)
|
|
|
|
M.MetadataShowcase metadata ->
|
|
StaticHttp.map2
|
|
(data globalData ->
|
|
{ view =
|
|
model rendered ->
|
|
case model.page of
|
|
ModelShowcase subModel ->
|
|
Template.Showcase.template.view siteMetadata data subModel metadata rendered
|
|
|> ({ title, body } ->
|
|
Global.wrapBody
|
|
globalData
|
|
page
|
|
model.global
|
|
MsgGlobal
|
|
{ title = title
|
|
, body =
|
|
-- Template.BlogPost.liftViewMsg
|
|
Element.map never body
|
|
}
|
|
)
|
|
|
|
_ ->
|
|
{ title = \\"\\", body = Html.text \\"\\" }
|
|
, head = Template.Showcase.template.head data page.path metadata
|
|
}
|
|
)
|
|
(Template.Showcase.template.staticData siteMetadata)
|
|
(Global.staticData siteMetadata)
|
|
|
|
M.MetadataPage metadata ->
|
|
StaticHttp.map2
|
|
(data globalData ->
|
|
{ view =
|
|
model rendered ->
|
|
case model.page of
|
|
ModelPage subModel ->
|
|
Template.Page.template.view siteMetadata data subModel metadata rendered
|
|
|> ({ title, body } ->
|
|
Global.wrapBody
|
|
globalData
|
|
page
|
|
model.global
|
|
MsgGlobal
|
|
{ title = title
|
|
, body =
|
|
-- Template.BlogPost.liftViewMsg
|
|
Element.map never body
|
|
}
|
|
)
|
|
|
|
_ ->
|
|
{ title = \\"\\", body = Html.text \\"\\" }
|
|
, head = Template.Page.template.head data page.path metadata
|
|
}
|
|
)
|
|
(Template.Page.template.staticData siteMetadata)
|
|
(Global.staticData siteMetadata)
|
|
|
|
M.MetadataBlogIndex metadata ->
|
|
StaticHttp.map2
|
|
(data globalData ->
|
|
{ view =
|
|
model rendered ->
|
|
case model.page of
|
|
ModelBlogIndex subModel ->
|
|
--Template.BlogIndex.view siteMetadata data subModel metadata rendered
|
|
Template.BlogIndex.template.view
|
|
siteMetadata
|
|
data
|
|
subModel
|
|
metadata
|
|
rendered
|
|
|> ({ title, body } ->
|
|
Global.wrapBody
|
|
globalData
|
|
page
|
|
model.global
|
|
MsgGlobal
|
|
{ title = title
|
|
, body = Element.map never body
|
|
}
|
|
)
|
|
|
|
_ ->
|
|
{ title = \\"\\", body = Html.text \\"\\" }
|
|
, head = Template.BlogIndex.template.head data page.path metadata
|
|
}
|
|
)
|
|
(Template.BlogIndex.template.staticData siteMetadata)
|
|
(Global.staticData siteMetadata)
|
|
|
|
M.MetadataDocumentation metadata ->
|
|
StaticHttp.map2
|
|
(data globalData ->
|
|
{ view =
|
|
model rendered ->
|
|
case model.page of
|
|
ModelDocumentation subModel ->
|
|
Template.Documentation.template.view siteMetadata data subModel metadata rendered
|
|
|> ({ title, body } ->
|
|
Global.wrapBody
|
|
globalData
|
|
page
|
|
model.global
|
|
MsgGlobal
|
|
{ title = title
|
|
, body =
|
|
-- Template.BlogPost.liftViewMsg
|
|
Element.map never body
|
|
}
|
|
)
|
|
|
|
_ ->
|
|
{ title = \\"\\", body = Html.text \\"\\" }
|
|
, head = Template.Page.template.head data page.path metadata
|
|
}
|
|
)
|
|
(Template.Page.template.staticData siteMetadata)
|
|
(Global.staticData siteMetadata)
|
|
|
|
|
|
init :
|
|
Maybe
|
|
{ path :
|
|
{ path : PagePath Pages.PathKey
|
|
, query : Maybe String
|
|
, fragment : Maybe String
|
|
}
|
|
, metadata : Metadata
|
|
}
|
|
-> ( Model, Cmd Msg )
|
|
init maybePagePath =
|
|
( { global = Global.init maybePagePath
|
|
, page =
|
|
case maybePagePath |> Maybe.map .metadata of
|
|
Nothing ->
|
|
Debug.todo \\"\\"
|
|
|
|
Just meta ->
|
|
case meta of
|
|
M.MetadataBlogPost metadata ->
|
|
Template.BlogPost.template.init metadata
|
|
|> Tuple.first
|
|
|> ModelBlogPost
|
|
|
|
M.MetadataShowcase metadata ->
|
|
Template.Showcase.template.init metadata
|
|
|> Tuple.first
|
|
|> ModelShowcase
|
|
|
|
M.MetadataPage metadata ->
|
|
Template.Page.template.init metadata
|
|
|> Tuple.first
|
|
|> ModelPage
|
|
|
|
M.MetadataBlogIndex metadata ->
|
|
Template.BlogIndex.template.init metadata
|
|
|> Tuple.first
|
|
|> ModelBlogIndex
|
|
|
|
M.MetadataDocumentation metadata ->
|
|
Template.Documentation.template.init metadata
|
|
|> Tuple.first
|
|
|> ModelDocumentation
|
|
}
|
|
, Cmd.none
|
|
)
|
|
|
|
|
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
update msg model =
|
|
case msg of
|
|
MsgBlogPost msg_ ->
|
|
( model, Cmd.none )
|
|
|
|
MsgGlobal msg_ ->
|
|
let
|
|
( globalModel, globalCmd ) =
|
|
Global.update msg_ model.global
|
|
in
|
|
( { model | global = globalModel }, globalCmd |> Cmd.map MsgGlobal )
|
|
|
|
OnPageChange record ->
|
|
init <|
|
|
Just
|
|
{ path =
|
|
{ path = record.path
|
|
, query = record.query
|
|
, fragment = record.fragment
|
|
}
|
|
, metadata = record.metadata
|
|
}
|
|
|
|
MsgBlogIndex msg_ ->
|
|
let
|
|
( updatedPageModel, pageCmd ) =
|
|
case model.page of
|
|
ModelBlogIndex pageModel ->
|
|
Template.BlogIndex.template.update (Debug.todo \\"\\")
|
|
msg_
|
|
pageModel
|
|
|> Tuple.mapBoth ModelBlogIndex (Cmd.map MsgBlogIndex)
|
|
|
|
_ ->
|
|
( model.page, Cmd.none )
|
|
in
|
|
( { model | page = updatedPageModel }, pageCmd )
|
|
|
|
|
|
mainTemplate { documents, manifest, canonicalSiteUrl } =
|
|
Pages.Platform.init
|
|
{ init = init
|
|
, view = view
|
|
, update = update
|
|
, subscriptions = _ -> Sub.none
|
|
, documents = documents
|
|
, onPageChange = Just OnPageChange
|
|
, manifest = manifest -- SiteConfig.manifest
|
|
, canonicalSiteUrl = canonicalSiteUrl -- SiteConfig.canonicalUrl
|
|
, internals = Pages.internals
|
|
}
|
|
|> Pages.Platform.toProgram
|
|
|
|
|
|
mapDocument : Browser.Document Never -> Browser.Document mapped
|
|
mapDocument document =
|
|
{ title = document.title
|
|
, body = document.body |> List.map (Html.map never)
|
|
}
|
|
"
|
|
`;
|