From 7aeec0f72e803ca6778bfeaac2d8d915009ab996 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 20 May 2020 06:42:52 -0700 Subject: [PATCH 001/106] Add starting point for template modules file structure. --- examples/docs/src/Global.elm | 6 + examples/docs/src/Main.elm | 23 +--- examples/docs/src/Template/Showcase.elm | 152 ++++++++++++++++++++++++ 3 files changed, 163 insertions(+), 18 deletions(-) create mode 100644 examples/docs/src/Global.elm create mode 100644 examples/docs/src/Template/Showcase.elm diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm new file mode 100644 index 00000000..7e66cdc2 --- /dev/null +++ b/examples/docs/src/Global.elm @@ -0,0 +1,6 @@ +module Global exposing (..) + + +type alias Model = + { showMobileMenu : Bool + } diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 0e7dce5b..d83aca84 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -37,6 +37,7 @@ import RssPlugin import Secrets import Showcase import StructuredData +import Template.Showcase manifest : Manifest.Config Pages.PathKey @@ -194,24 +195,10 @@ view : view siteMetadata page = case page.frontmatter of Metadata.Showcase -> - StaticHttp.map2 - (\stars showcaseData -> - { view = - \model viewForPage -> - { title = "elm-pages blog" - , body = - Element.column [ Element.width Element.fill ] - [ Element.column [ Element.padding 20, Element.centerX ] [ Showcase.view showcaseData ] - ] - } - |> wrapBody stars page model - , head = head page.path page.frontmatter - } - ) - (StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages") - (D.field "stargazers_count" D.int) - ) - Showcase.staticRequest + Template.Showcase.view siteMetadata + { path = page.path + , frontmatter = Template.Showcase.Metadata + } _ -> StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages") diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm new file mode 100644 index 00000000..b8f2899e --- /dev/null +++ b/examples/docs/src/Template/Showcase.elm @@ -0,0 +1,152 @@ +module Template.Showcase exposing (..) + +import Element exposing (Element) +import Element.Font as Font +import Head +import Head.Seo as Seo +import Html exposing (Html) +import MarkdownRenderer +import Metadata as GlobalMetadata +import OptimizedDecoder as D +import Pages exposing (images) +import Pages.PagePath exposing (PagePath) +import Pages.StaticHttp as StaticHttp +import Secrets +import Showcase + + +type Metadata + = Metadata + + +type Msg + = Msg + + + +-- TODO wire in custom Model and Msg types +--type Model +-- = Model + + +type alias Model = + { showMobileMenu : Bool + } + + +type alias View msg = + ( MarkdownRenderer.TableOfContents, List (Element msg) ) + + +view : + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> + { path : PagePath Pages.PathKey + , frontmatter : Metadata + } + -> + StaticHttp.Request + { view : + Model + -> View msg + -> { title : String, body : Html msg } + , head : List (Head.Tag Pages.PathKey) + } +view siteMetadata page = + case page.frontmatter of + Metadata -> + StaticHttp.map2 + (\stars showcaseData -> + { view = + \model viewForPage -> + { title = "elm-pages blog" + , body = + Element.column [ Element.width Element.fill ] + [ Element.column [ Element.padding 20, Element.centerX ] [ Showcase.view showcaseData ] + ] + } + |> wrapBody stars page model + , head = head page.path page.frontmatter + } + ) + (StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages") + (D.field "stargazers_count" D.int) + ) + Showcase.staticRequest + + +siteTagline : String +siteTagline = + "A statically typed site generator - elm-pages" + + +head : PagePath Pages.PathKey -> Metadata -> List (Head.Tag Pages.PathKey) +head currentPath metadata = + case metadata of + Metadata -> + Seo.summary + { canonicalUrlOverride = Nothing + , siteName = "elm-pages" + , image = + { url = images.iconPng + , alt = "elm-pages logo" + , dimensions = Nothing + , mimeType = Nothing + } + , description = "See some neat sites built using elm-pages! (Or submit yours!)" + , locale = Nothing + , title = "elm-pages sites showcase" + } + |> Seo.website + + +canonicalSiteUrl : String +canonicalSiteUrl = + "https://elm-pages.com" + + +wrapBody : Int -> { a | path : PagePath Pages.PathKey } -> Model -> { c | body : Element msg, title : String } -> { body : Html msg, title : String } +wrapBody stars page model record = + { body = + Element.column [ Element.width Element.fill ] [ record.body ] + |> Element.layout + [ Element.width Element.fill + , Font.size 20 + , Font.family [ Font.typeface "Roboto" ] + , Font.color (Element.rgba255 0 0 0 0.8) + ] + , title = record.title + } + + + +--wrapBody : Int -> { a | path : PagePath Pages.PathKey } -> Model -> { c | body : Element Msg, title : String } -> { body : Html Msg, title : String } +--wrapBody stars page model record = +-- { body = +-- (if model.showMobileMenu then +-- Element.column +-- [ Element.width Element.fill +-- , Element.padding 20 +-- ] +-- [ Element.row [ Element.width Element.fill, Element.spaceEvenly ] +-- [ logoLinkMobile +-- , FontAwesome.styledIcon "fas fa-bars" [ Element.Events.onClick ToggleMobileMenu ] +-- ] +-- , Element.column [ Element.centerX, Element.spacing 20 ] +-- (navbarLinks stars page.path) +-- ] +-- +-- else +-- Element.column [ Element.width Element.fill ] +-- [ header stars page.path +-- , record.body +-- ] +-- ) +-- |> Element.layout +-- [ Element.width Element.fill +-- , Font.size 20 +-- , Font.family [ Font.typeface "Roboto" ] +-- , Font.color (Element.rgba255 0 0 0 0.8) +-- ] +-- , title = record.title +-- } From e9ff0faafb530d4c700ac643ac78c3f70cca6409 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 23 May 2020 15:31:56 -0700 Subject: [PATCH 002/106] Add BlogPost template prototype. --- examples/docs/src/Global.elm | 228 ++++++++++++++++++++ examples/docs/src/Main.elm | 9 + examples/docs/src/SiteConfig.elm | 6 + examples/docs/src/Template.elm | 41 ++++ examples/docs/src/Template/BlogPost.elm | 215 ++++++++++++++++++ examples/docs/src/TemplateDemultiplexer.elm | 90 ++++++++ 6 files changed, 589 insertions(+) create mode 100644 examples/docs/src/SiteConfig.elm create mode 100644 examples/docs/src/Template.elm create mode 100644 examples/docs/src/Template/BlogPost.elm create mode 100644 examples/docs/src/TemplateDemultiplexer.elm diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index 7e66cdc2..4c4ad300 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -1,6 +1,234 @@ module Global exposing (..) +import DocumentSvg +import Element exposing (Element) +import Element.Background +import Element.Border +import Element.Events +import Element.Font as Font +import Element.Region +import FontAwesome +import Html exposing (Html) +import Html.Attributes as Attr +import OptimizedDecoder as D +import Pages exposing (pages) +import Pages.Directory as Directory exposing (Directory) +import Pages.ImagePath as ImagePath +import Pages.PagePath as PagePath exposing (PagePath) +import Pages.StaticHttp as StaticHttp +import Palette +import Secrets + type alias Model = { showMobileMenu : Bool } + + +type Msg + = OnPageChange + { path : PagePath Pages.PathKey + , query : Maybe String + , fragment : Maybe String + } + | ToggleMobileMenu + + +toView : Element msg -> Html msg +toView = + Debug.todo "" + + +type alias StaticData = + Int + + +staticData : a -> StaticHttp.Request StaticData +staticData siteMetadata = + StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages") + (D.field "stargazers_count" D.int) + + +testing : { body : Html msg, title : String } +testing = + Debug.todo "" + + +wrapBody : + StaticData + -> { a | path : PagePath Pages.PathKey } + -> Model + -> (Msg -> msg) + -> { body : Element msg, title : String } + -> { body : Html msg, title : String } +wrapBody stars page model liftMsg record = + { body = + (if model.showMobileMenu then + Element.column + [ Element.width Element.fill + , Element.padding 20 + ] + [ Element.row [ Element.width Element.fill, Element.spaceEvenly ] + [ logoLinkMobile |> Element.map liftMsg + , FontAwesome.styledIcon "fas fa-bars" [ Element.Events.onClick ToggleMobileMenu ] + |> Element.map liftMsg + ] + , Element.column [ Element.centerX, Element.spacing 20 ] + (navbarLinks stars page.path) + ] + + else + Element.column [ Element.width Element.fill ] + [ header stars page.path |> Element.map liftMsg + , record.body + ] + ) + |> Element.layout + [ Element.width Element.fill + , Font.size 20 + , Font.family [ Font.typeface "Roboto" ] + , Font.color (Element.rgba255 0 0 0 0.8) + ] + + --|> Html.map liftMsg + , title = record.title + } + + +logoLinkMobile = + Element.link [] + { url = "/" + , label = + Element.row + [ Font.size 30 + , Element.spacing 16 + , Element.htmlAttribute (Attr.class "navbar-title") + ] + [ Element.text "elm-pages" + ] + } + + +navbarLinks stars currentPath = + [ elmDocsLink + , githubRepoLink stars + , highlightableLink currentPath pages.docs.directory "Docs" + , highlightableLink currentPath pages.showcase.directory "Showcase" + , highlightableLink currentPath pages.blog.directory "Blog" + ] + + +header : Int -> PagePath Pages.PathKey -> Element Msg +header stars currentPath = + Element.column [ Element.width Element.fill ] + [ responsiveHeader + , Element.column + [ Element.width Element.fill + , Element.htmlAttribute (Attr.class "responsive-desktop") + ] + [ Element.el + [ Element.height (Element.px 4) + , Element.width Element.fill + , Element.Background.gradient + { angle = 0.2 + , steps = + [ Element.rgb255 0 242 96 + , Element.rgb255 5 117 230 + ] + } + ] + Element.none + , Element.row + [ Element.paddingXY 25 4 + , Element.spaceEvenly + , Element.width Element.fill + , Element.Region.navigation + , Element.Border.widthEach { bottom = 1, left = 0, right = 0, top = 0 } + , Element.Border.color (Element.rgba255 40 80 40 0.4) + ] + [ logoLink + , Element.row [ Element.spacing 15 ] (navbarLinks stars currentPath) + ] + ] + ] + + +logoLink = + Element.link [] + { url = "/" + , label = + Element.row + [ Font.size 30 + , Element.spacing 16 + , Element.htmlAttribute (Attr.class "navbar-title") + ] + [ DocumentSvg.view + , Element.text "elm-pages" + ] + } + + +responsiveHeader = + Element.row + [ Element.width Element.fill + , Element.spaceEvenly + , Element.htmlAttribute (Attr.class "responsive-mobile") + , Element.width Element.fill + , Element.padding 20 + ] + [ logoLinkMobile + , FontAwesome.icon "fas fa-bars" |> Element.el [ Element.alignRight, Element.Events.onClick ToggleMobileMenu ] + ] + + +githubRepoLink : Int -> Element msg +githubRepoLink starCount = + Element.newTabLink [] + { url = "https://github.com/dillonkearns/elm-pages" + , label = + Element.row [ Element.spacing 5 ] + [ Element.image + [ Element.width (Element.px 22) + , Font.color Palette.color.primary + ] + { src = ImagePath.toString Pages.images.github, description = "Github repo" } + , Element.text <| String.fromInt starCount + ] + } + + +elmDocsLink : Element msg +elmDocsLink = + Element.newTabLink [] + { url = "https://package.elm-lang.org/packages/dillonkearns/elm-pages/latest/" + , label = + Element.image + [ Element.width (Element.px 22) + , Font.color Palette.color.primary + ] + { src = ImagePath.toString Pages.images.elmLogo, description = "Elm Package Docs" } + } + + +highlightableLink : + PagePath Pages.PathKey + -> Directory Pages.PathKey Directory.WithIndex + -> String + -> Element msg +highlightableLink currentPath linkDirectory displayName = + let + isHighlighted = + currentPath |> Directory.includes linkDirectory + in + Element.link + (if isHighlighted then + [ Font.underline + , Font.color Palette.color.primary + ] + + else + [] + ) + { url = linkDirectory |> Directory.indexPath |> PagePath.toString + , label = Element.text displayName + } diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index d83aca84..d379ad4d 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -37,6 +37,7 @@ import RssPlugin import Secrets import Showcase import StructuredData +import Template.BlogPost import Template.Showcase @@ -200,6 +201,14 @@ view siteMetadata page = , frontmatter = Template.Showcase.Metadata } + Metadata.Article metadata -> + --Template.BlogPost.view metadata + Template.BlogPost.template siteMetadata + { metadata = Template.BlogPost.Metadata metadata + , path = page.path + } + |> StaticHttp.map (\thing -> Debug.todo "") + _ -> StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages") (D.field "stargazers_count" D.int) diff --git a/examples/docs/src/SiteConfig.elm b/examples/docs/src/SiteConfig.elm new file mode 100644 index 00000000..daf1cead --- /dev/null +++ b/examples/docs/src/SiteConfig.elm @@ -0,0 +1,6 @@ +module SiteConfig exposing (..) + + +canonicalUrl : String +canonicalUrl = + "https://elm-pages.com" diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm new file mode 100644 index 00000000..7c38412b --- /dev/null +++ b/examples/docs/src/Template.elm @@ -0,0 +1,41 @@ +module Template exposing (..) + +import Head +import Pages +import Pages.PagePath exposing (PagePath) +import Pages.StaticHttp as StaticHttp + + +template : + { staticData : + List ( PagePath Pages.PathKey, globalMetadata ) + -> StaticHttp.Request templateStaticData + , view : + templateStaticData + -> templateModel + -> templateMetadata + -> renderedTemplate + -> view + , head : + templateStaticData + -> PagePath Pages.PathKey + -> templateMetadata + -> List (Head.Tag Pages.PathKey) + } + -> List ( PagePath Pages.PathKey, globalMetadata ) + -> { metadata : templateMetadata, path : PagePath Pages.PathKey } + -> + StaticHttp.Request + { view : templateModel -> renderedTemplate -> view + , head : List (Head.Tag Pages.PathKey) + } +template config siteMetadata page = + config.staticData siteMetadata + |> StaticHttp.map + (\staticData -> + { view = + \model rendered -> + config.view staticData model page.metadata rendered + , head = config.head staticData page.path page.metadata + } + ) diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm new file mode 100644 index 00000000..9214cab5 --- /dev/null +++ b/examples/docs/src/Template/BlogPost.elm @@ -0,0 +1,215 @@ +module Template.BlogPost exposing (Metadata(..), Model, Msg, decoder, head, liftViewMsg, staticData, template, view) + +import Data.Author as Author exposing (Author) +import Date exposing (Date) +import Element exposing (Element) +import Element.Font as Font +import Element.Region +import Head +import Head.Seo as Seo +import Json.Decode as Decode +import List.Extra +import OptimizedDecoder as D +import Pages +import Pages.ImagePath as ImagePath exposing (ImagePath) +import Pages.PagePath as PagePath exposing (PagePath) +import Pages.StaticHttp as StaticHttp +import Palette +import Secrets +import SiteConfig +import StructuredData +import Template + + +type Metadata + = Metadata MetadataRecord + + +type alias MetadataRecord = + { title : String + , description : String + , published : Date + , author : Author + , image : ImagePath Pages.PathKey + , draft : Bool + } + + +type Model + = Model + + +type Msg + = Msg + + +template : + List ( PagePath Pages.PathKey, globalMetadata ) + -> { metadata : Metadata, path : PagePath.PagePath Pages.PathKey } + -> StaticHttp.Request { view : Model -> ( a, List (Element msg) ) -> { title : String, body : Element msg }, head : List (Head.Tag Pages.PathKey) } +template = + Template.template + { staticData = staticData + , view = view + , head = head + } + + +decoder : Decode.Decoder Metadata +decoder = + Decode.map6 MetadataRecord + (Decode.field "title" Decode.string) + (Decode.field "description" Decode.string) + (Decode.field "published" + (Decode.string + |> Decode.andThen + (\isoString -> + case Date.fromIsoString isoString of + Ok date -> + Decode.succeed date + + Err error -> + Decode.fail error + ) + ) + ) + (Decode.field "author" Author.decoder) + (Decode.field "image" imageDecoder) + (Decode.field "draft" Decode.bool + |> Decode.maybe + |> Decode.map (Maybe.withDefault False) + ) + |> Decode.map Metadata + + +imageDecoder : Decode.Decoder (ImagePath Pages.PathKey) +imageDecoder = + Decode.string + |> Decode.andThen + (\imageAssetPath -> + case findMatchingImage imageAssetPath of + Nothing -> + Decode.fail "Couldn't find image." + + Just imagePath -> + Decode.succeed imagePath + ) + + +findMatchingImage : String -> Maybe (ImagePath Pages.PathKey) +findMatchingImage imageAssetPath = + List.Extra.find + (\image -> ImagePath.toString image == imageAssetPath) + Pages.allImages + + +init : Model +init = + Model + + +staticData : a -> StaticHttp.Request StaticData +staticData siteMetadata = + StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages") + (D.field "stargazers_count" D.int) + + +type alias StaticData = + Int + + +liftViewMsg : (Msg -> msg) -> ( a, List (Element msg) ) -> ( a, List (Element msg) ) +liftViewMsg liftMsg = + identity + + +view : StaticData -> Model -> Metadata -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view static model (Metadata blogPost) rendered = + { title = blogPost.title + , body = + Element.column [ Element.width Element.fill ] + [ Element.column + [ Element.padding 30 + , Element.spacing 40 + , Element.Region.mainContent + , Element.width (Element.fill |> Element.maximum 800) + , Element.centerX + ] + (Element.column [ Element.spacing 10 ] + [ Element.row [ Element.spacing 10 ] + [ Author.view [] blogPost.author + , Element.column [ Element.spacing 10, Element.width Element.fill ] + [ Element.paragraph [ Font.bold, Font.size 24 ] + [ Element.text blogPost.author.name + ] + , Element.paragraph [ Font.size 16 ] + [ Element.text blogPost.author.bio ] + ] + ] + ] + :: (publishedDateView blogPost |> Element.el [ Font.size 16, Font.color (Element.rgba255 0 0 0 0.6) ]) + :: Palette.blogHeading blogPost.title + :: articleImageView blogPost.image + :: Tuple.second rendered + ) + ] + } + + +head : StaticData -> PagePath.PagePath Pages.PathKey -> Metadata -> List (Head.Tag Pages.PathKey) +head static currentPath (Metadata meta) = + Head.structuredData + (StructuredData.article + { title = meta.title + , description = meta.description + , author = StructuredData.person { name = meta.author.name } + , publisher = StructuredData.person { name = "Dillon Kearns" } + , url = SiteConfig.canonicalUrl ++ "/" ++ PagePath.toString currentPath + , imageUrl = SiteConfig.canonicalUrl ++ "/" ++ ImagePath.toString meta.image + , datePublished = Date.toIsoString meta.published + , mainEntityOfPage = + StructuredData.softwareSourceCode + { codeRepositoryUrl = "https://github.com/dillonkearns/elm-pages" + , description = "A statically typed site generator for Elm." + , author = "Dillon Kearns" + , programmingLanguage = StructuredData.elmLang + } + } + ) + :: (Seo.summaryLarge + { canonicalUrlOverride = Nothing + , siteName = "elm-pages" + , image = + { url = meta.image + , alt = meta.description + , dimensions = Nothing + , mimeType = Nothing + } + , description = meta.description + , locale = Nothing + , title = meta.title + } + |> Seo.article + { tags = [] + , section = Nothing + , publishedTime = Just (Date.toIsoString meta.published) + , modifiedTime = Nothing + , expirationTime = Nothing + } + ) + + +publishedDateView : { a | published : Date.Date } -> Element msg +publishedDateView metadata = + Element.text + (metadata.published + |> Date.format "MMMM ddd, yyyy" + ) + + +articleImageView : ImagePath Pages.PathKey -> Element msg +articleImageView articleImage = + Element.image [ Element.width Element.fill ] + { src = ImagePath.toString articleImage + , description = "Article cover photo" + } diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm new file mode 100644 index 00000000..b23d23d2 --- /dev/null +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -0,0 +1,90 @@ +module TemplateDemultiplexer exposing (..) + +import Element exposing (Element) +import Global +import Head +import Html exposing (Html) +import MarkdownRenderer +import Pages +import Pages.PagePath exposing (PagePath) +import Pages.StaticHttp as StaticHttp +import Template.BlogPost +import Template.Showcase + + +type Metadata + = MetadataBlogPost Template.BlogPost.Metadata + | MetadataShowcase Template.Showcase.Metadata + + +type alias Model = + { global : Global.Model + , page : TemplateModel + } + + +type TemplateModel + = ModelBlogPost Template.BlogPost.Model + | ModelShowcase Template.Showcase.Model + + +type Msg + = MsgBlogPost Template.BlogPost.Msg + + +type alias View = + ( MarkdownRenderer.TableOfContents, List (Element Msg) ) + + +toView = + Debug.todo "" + + +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 + MetadataBlogPost metadata -> + StaticHttp.map2 + (\data globalData -> + { view = + \model rendered -> + case model.page of + ModelBlogPost subModel -> + Template.BlogPost.view data subModel metadata rendered + |> (\{ title, body } -> + Global.wrapBody + globalData + page + model.global + liftGlobalMsg + { title = title + , body = + -- Template.BlogPost.liftViewMsg + body + } + ) + + _ -> + { title = "", body = Html.text "" } + , head = Template.BlogPost.head data page.path metadata + } + ) + (Template.BlogPost.staticData siteMetadata) + (Global.staticData siteMetadata) + + MetadataShowcase metadata -> + Debug.todo "" + + +liftGlobalMsg = + Debug.todo "" From 48fd7a5fb54035c1638de929270685c6562c906d Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 23 May 2020 17:03:28 -0700 Subject: [PATCH 003/106] Wire up init function. --- examples/docs/src/Global.elm | 4 ++ examples/docs/src/Main.elm | 62 +++++++++++------- examples/docs/src/MetadataNew.elm | 51 +++++++++++++++ examples/docs/src/SiteConfig.elm | 21 +++++++ examples/docs/src/Template/BlogPost.elm | 6 +- examples/docs/src/Template/Showcase.elm | 6 ++ examples/docs/src/TemplateDemultiplexer.elm | 70 ++++++++++++++++++++- src/Pages/Internal/Platform.elm | 39 ++++++++---- src/Pages/Internal/Platform/Cli.elm | 9 ++- src/Pages/Platform.elm | 27 +++++--- 10 files changed, 242 insertions(+), 53 deletions(-) create mode 100644 examples/docs/src/MetadataNew.elm diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index 4c4ad300..ea45a4d3 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -34,6 +34,10 @@ type Msg | ToggleMobileMenu +init maybePagePath = + Debug.todo "" + + toView : Element msg -> Html msg toView = Debug.todo "" diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index d379ad4d..7d664375 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -21,6 +21,7 @@ import Json.Decode as Decode exposing (Decoder) import Json.Encode import MarkdownRenderer import Metadata exposing (Metadata) +import MetadataNew import MySitemap import OptimizedDecoder as D import Pages exposing (images, pages) @@ -36,9 +37,11 @@ import Rss import RssPlugin import Secrets import Showcase +import SiteConfig import StructuredData import Template.BlogPost import Template.Showcase +import TemplateDemultiplexer manifest : Manifest.Config Pages.PathKey @@ -61,34 +64,49 @@ type alias View = ( MarkdownRenderer.TableOfContents, List (Element Msg) ) -main : Pages.Platform.Program Model Msg Metadata View +main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg TemplateDemultiplexer.Metadata TemplateDemultiplexer.View main = - Pages.Platform.init - { init = init - , view = view - , update = update - , subscriptions = subscriptions - , documents = + TemplateDemultiplexer.mainTemplate + { documents = [ { extension = "md" - , metadata = Metadata.decoder + , metadata = MetadataNew.decoder , body = MarkdownRenderer.view } ] - , onPageChange = Just OnPageChange - , manifest = manifest - , canonicalSiteUrl = canonicalSiteUrl - , internals = Pages.internals + , manifest = SiteConfig.manifest + , canonicalSiteUrl = SiteConfig.canonicalUrl } - |> RssPlugin.generate - { siteTagline = siteTagline - , siteUrl = canonicalSiteUrl - , title = "elm-pages Blog" - , builtAt = Pages.builtAt - , indexPage = Pages.pages.blog.index - } - metadataToRssItem - |> MySitemap.install { siteUrl = canonicalSiteUrl } metadataToSitemapEntry - |> Pages.Platform.toProgram + + + +--main : Pages.Platform.Program Model Msg Metadata View +--main = +-- Pages.Platform.init +-- { init = init +-- , view = view +-- , update = update +-- , subscriptions = subscriptions +-- , documents = +-- [ { extension = "md" +-- , metadata = Metadata.decoder +-- , body = MarkdownRenderer.view +-- } +-- ] +-- , onPageChange = Just OnPageChange +-- , manifest = manifest +-- , canonicalSiteUrl = canonicalSiteUrl +-- , internals = Pages.internals +-- } +-- |> RssPlugin.generate +-- { siteTagline = siteTagline +-- , siteUrl = canonicalSiteUrl +-- , title = "elm-pages Blog" +-- , builtAt = Pages.builtAt +-- , indexPage = Pages.pages.blog.index +-- } +-- metadataToRssItem +-- |> MySitemap.install { siteUrl = canonicalSiteUrl } metadataToSitemapEntry +-- |> Pages.Platform.toProgram metadataToRssItem : diff --git a/examples/docs/src/MetadataNew.elm b/examples/docs/src/MetadataNew.elm new file mode 100644 index 00000000..083c2bd0 --- /dev/null +++ b/examples/docs/src/MetadataNew.elm @@ -0,0 +1,51 @@ +module MetadataNew exposing (DocMetadata, PageMetadata, decoder) + +import Json.Decode as Decode exposing (Decoder) +import Template.BlogPost +import Template.Showcase +import TemplateDemultiplexer as TD exposing (Metadata) + + +type alias DocMetadata = + { title : String + } + + +type alias PageMetadata = + { title : String } + + +decoder : Decoder Metadata +decoder = + Decode.field "type" Decode.string + |> Decode.andThen + (\pageType -> + case pageType of + --"doc" -> + -- Decode.field "title" Decode.string + -- |> Decode.map (\title -> Doc { title = title }) + -- + --"page" -> + -- Decode.field "title" Decode.string + -- |> Decode.map (\title -> Page { title = title }) + -- + --"blog-index" -> + -- Decode.succeed BlogIndex + "showcase" -> + Template.Showcase.decoder + |> Decode.map TD.MetadataShowcase + + -- + --"author" -> + -- Decode.map3 Data.Author.Author + -- (Decode.field "name" Decode.string) + -- (Decode.field "avatar" imageDecoder) + -- (Decode.field "bio" Decode.string) + -- |> Decode.map Author + "blog" -> + Template.BlogPost.decoder + |> Decode.map TD.MetadataBlogPost + + _ -> + Decode.fail <| "Unexpected page \"type\" " ++ pageType + ) diff --git a/examples/docs/src/SiteConfig.elm b/examples/docs/src/SiteConfig.elm index daf1cead..f11ffc57 100644 --- a/examples/docs/src/SiteConfig.elm +++ b/examples/docs/src/SiteConfig.elm @@ -1,6 +1,27 @@ module SiteConfig exposing (..) +import Color +import Pages exposing (images, pages) +import Pages.Manifest as Manifest +import Pages.Manifest.Category + canonicalUrl : String canonicalUrl = "https://elm-pages.com" + + +manifest : Manifest.Config Pages.PathKey +manifest = + { backgroundColor = Just Color.white + , categories = [ Pages.Manifest.Category.education ] + , displayMode = Manifest.Standalone + , orientation = Manifest.Portrait + , description = "elm-pages - A statically typed site generator." + , iarcRatingId = Nothing + , name = "elm-pages docs" + , themeColor = Just Color.white + , startUrl = pages.index + , shortName = Just "elm-pages" + , sourceIcon = images.iconPng + } diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 9214cab5..72458d19 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -1,4 +1,4 @@ -module Template.BlogPost exposing (Metadata(..), Model, Msg, decoder, head, liftViewMsg, staticData, template, view) +module Template.BlogPost exposing (Metadata(..), Model, Msg, decoder, head, init, liftViewMsg, staticData, template, view) import Data.Author as Author exposing (Author) import Date exposing (Date) @@ -103,8 +103,8 @@ findMatchingImage imageAssetPath = Pages.allImages -init : Model -init = +init : Metadata -> Model +init metadata = Model diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index b8f2899e..96ad3b1c 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -5,6 +5,7 @@ import Element.Font as Font import Head import Head.Seo as Seo import Html exposing (Html) +import Json.Decode as Decode exposing (Decoder) import MarkdownRenderer import Metadata as GlobalMetadata import OptimizedDecoder as D @@ -23,6 +24,11 @@ type Msg = Msg +decoder : Decoder Metadata +decoder = + Decode.succeed Metadata + + -- TODO wire in custom Model and Msg types --type Model diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index b23d23d2..421bce9c 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -5,9 +5,12 @@ import Global import Head import Html exposing (Html) import MarkdownRenderer +import Metadata import Pages import Pages.PagePath exposing (PagePath) +import Pages.Platform import Pages.StaticHttp as StaticHttp +import SiteConfig import Template.BlogPost import Template.Showcase @@ -30,6 +33,7 @@ type TemplateModel type Msg = MsgBlogPost Template.BlogPost.Msg + | MsgGlobal Global.Msg type alias View = @@ -66,7 +70,7 @@ view siteMetadata page = globalData page model.global - liftGlobalMsg + MsgGlobal { title = title , body = -- Template.BlogPost.liftViewMsg @@ -86,5 +90,65 @@ view siteMetadata page = Debug.todo "" -liftGlobalMsg = - Debug.todo "" +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 + MetadataBlogPost metadata -> + Template.BlogPost.init metadata + |> ModelBlogPost + + MetadataShowcase metadata -> + Debug.todo "" + } + , Cmd.none + ) + + +update : Msg -> Model -> ( Model, Cmd Msg ) +update msg model = + -- TODO + ( model, Cmd.none ) + + + +--main : Pages.Platform.Program Model Msg Metadata View + + +mainTemplate { documents, manifest, canonicalSiteUrl } = + Pages.Platform.init + { init = init + , view = view + , update = update + + --, subscriptions = subscriptions + , subscriptions = \_ -> Sub.none + , documents = documents + + --[ { extension = "md" + -- , metadata = Metadata.decoder + -- , body = MarkdownRenderer.view + -- } + --] + --, onPageChange = Just OnPageChange + , onPageChange = Nothing + , manifest = manifest -- SiteConfig.manifest + , canonicalSiteUrl = canonicalSiteUrl -- SiteConfig.canonicalUrl + , internals = Pages.internals + } + |> Pages.Platform.toProgram diff --git a/src/Pages/Internal/Platform.elm b/src/Pages/Internal/Platform.elm index 00beb429..1af8587b 100644 --- a/src/Pages/Internal/Platform.elm +++ b/src/Pages/Internal/Platform.elm @@ -282,9 +282,12 @@ init : -> Content -> (Maybe - { path : PagePath pathKey - , query : Maybe String - , fragment : Maybe String + { metadata : metadata + , path : + { path : PagePath pathKey + , query : Maybe String + , fragment : Maybe String + } } -> ( userModel, Cmd userMsg ) ) @@ -343,14 +346,18 @@ init pathKey canonicalSiteUrl document toJsPort viewFn content initUserModel fla DevClient False ( userModel, userCmd ) = - maybePagePath - |> Maybe.map - (\pagePath -> + Maybe.map2 + (\pagePath metadata -> + { path = { path = pagePath , query = url.query , fragment = url.fragment } - ) + , metadata = metadata + } + ) + maybePagePath + maybeMetadata |> initUserModel cmd = @@ -670,9 +677,12 @@ type HmrStatus application : { init : Maybe - { path : PagePath pathKey - , query : Maybe String - , fragment : Maybe String + { path : + { path : PagePath pathKey + , query : Maybe String + , fragment : Maybe String + } + , metadata : metadata } -> ( userModel, Cmd userMsg ) , update : userMsg -> userModel -> ( userModel, Cmd userMsg ) @@ -802,9 +812,12 @@ application config = cliApplication : { init : Maybe - { path : PagePath pathKey - , query : Maybe String - , fragment : Maybe String + { path : + { path : PagePath pathKey + , query : Maybe String + , fragment : Maybe String + } + , metadata : metadata } -> ( userModel, Cmd userMsg ) , update : userMsg -> userModel -> ( userModel, Cmd userMsg ) diff --git a/src/Pages/Internal/Platform/Cli.elm b/src/Pages/Internal/Platform/Cli.elm index b6313cc8..14ccb396 100644 --- a/src/Pages/Internal/Platform/Cli.elm +++ b/src/Pages/Internal/Platform/Cli.elm @@ -162,9 +162,12 @@ type Msg type alias Config pathKey userMsg userModel metadata view = { init : Maybe - { path : PagePath pathKey - , query : Maybe String - , fragment : Maybe String + { path : + { path : PagePath pathKey + , query : Maybe String + , fragment : Maybe String + } + , metadata : metadata } -> ( userModel, Cmd userMsg ) , update : userMsg -> userModel -> ( userModel, Cmd userMsg ) diff --git a/src/Pages/Platform.elm b/src/Pages/Platform.elm index 7f6447a3..898ab204 100644 --- a/src/Pages/Platform.elm +++ b/src/Pages/Platform.elm @@ -83,9 +83,12 @@ type Builder pathKey model msg metadata view = Builder { init : Maybe - { path : PagePath pathKey - , query : Maybe String - , fragment : Maybe String + { path : + { path : PagePath pathKey + , query : Maybe String + , fragment : Maybe String + } + , metadata : metadata } -> ( model, Cmd msg ) , update : msg -> model -> ( model, Cmd msg ) @@ -161,9 +164,12 @@ Here's a basic example. init : { init : Maybe - { path : PagePath pathKey - , query : Maybe String - , fragment : Maybe String + { path : + { path : PagePath pathKey + , query : Maybe String + , fragment : Maybe String + } + , metadata : metadata } -> ( model, Cmd msg ) , update : msg -> model -> ( model, Cmd msg ) @@ -313,9 +319,12 @@ toProgram (Builder config) = application : { init : Maybe - { path : PagePath pathKey - , query : Maybe String - , fragment : Maybe String + { path : + { path : PagePath pathKey + , query : Maybe String + , fragment : Maybe String + } + , metadata : metadata } -> ( model, Cmd msg ) , update : msg -> model -> ( model, Cmd msg ) From a26a84e4b6e68a57e457e25450e6caacf88a6c79 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 23 May 2020 18:59:07 -0700 Subject: [PATCH 004/106] Remove some debug todos. --- examples/docs/src/Global.elm | 14 ++++++++++---- examples/docs/src/TemplateDemultiplexer.elm | 14 +++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index ea45a4d3..33b8406c 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -35,12 +35,18 @@ type Msg init maybePagePath = - Debug.todo "" + { showMobileMenu = False + } -toView : Element msg -> Html msg -toView = - Debug.todo "" +update : Msg -> Model -> ( Model, Cmd Msg ) +update msg model = + case msg of + OnPageChange page -> + ( { model | showMobileMenu = False }, Cmd.none ) + + ToggleMobileMenu -> + ( { model | showMobileMenu = not model.showMobileMenu }, Cmd.none ) type alias StaticData = diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index 421bce9c..f6b6fac2 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -122,12 +122,16 @@ init maybePagePath = update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = - -- TODO - ( model, Cmd.none ) + case msg of + MsgBlogPost msg_ -> + ( model, Cmd.none ) - - ---main : Pages.Platform.Program Model Msg Metadata View + MsgGlobal msg_ -> + let + ( globalModel, globalCmd ) = + Global.update msg_ model.global + in + ( { model | global = globalModel }, globalCmd |> Cmd.map MsgGlobal ) mainTemplate { documents, manifest, canonicalSiteUrl } = From 3f946bdc4634eb0dfa7dfe9b204e9935cf716741 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 24 May 2020 08:36:40 -0700 Subject: [PATCH 005/106] Wire in the main Page template. --- examples/docs/src/Global.elm | 5 -- examples/docs/src/MetadataNew.elm | 8 ++- examples/docs/src/SiteConfig.elm | 5 ++ examples/docs/src/Template/Page.elm | 78 +++++++++++++++++++++ examples/docs/src/TemplateDemultiplexer.elm | 40 +++++++++-- 5 files changed, 124 insertions(+), 12 deletions(-) create mode 100644 examples/docs/src/Template/Page.elm diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index 33b8406c..394060a5 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -59,11 +59,6 @@ staticData siteMetadata = (D.field "stargazers_count" D.int) -testing : { body : Html msg, title : String } -testing = - Debug.todo "" - - wrapBody : StaticData -> { a | path : PagePath Pages.PathKey } diff --git a/examples/docs/src/MetadataNew.elm b/examples/docs/src/MetadataNew.elm index 083c2bd0..0c434b34 100644 --- a/examples/docs/src/MetadataNew.elm +++ b/examples/docs/src/MetadataNew.elm @@ -2,6 +2,7 @@ module MetadataNew exposing (DocMetadata, PageMetadata, decoder) import Json.Decode as Decode exposing (Decoder) import Template.BlogPost +import Template.Page import Template.Showcase import TemplateDemultiplexer as TD exposing (Metadata) @@ -25,9 +26,10 @@ decoder = -- Decode.field "title" Decode.string -- |> Decode.map (\title -> Doc { title = title }) -- - --"page" -> - -- Decode.field "title" Decode.string - -- |> Decode.map (\title -> Page { title = title }) + "page" -> + Template.Page.decoder + |> Decode.map TD.MetadataPage + -- --"blog-index" -> -- Decode.succeed BlogIndex diff --git a/examples/docs/src/SiteConfig.elm b/examples/docs/src/SiteConfig.elm index f11ffc57..8b6d9dab 100644 --- a/examples/docs/src/SiteConfig.elm +++ b/examples/docs/src/SiteConfig.elm @@ -25,3 +25,8 @@ manifest = , shortName = Just "elm-pages" , sourceIcon = images.iconPng } + + +tagline : String +tagline = + "A statically typed site generator - elm-pages" diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm new file mode 100644 index 00000000..6d7a3af3 --- /dev/null +++ b/examples/docs/src/Template/Page.elm @@ -0,0 +1,78 @@ +module Template.Page exposing (Metadata, Model, Msg, decoder, head, init, staticData, view) + +import Element exposing (Element) +import Element.Region +import Head +import Head.Seo as Seo +import Json.Decode as Decode +import Pages exposing (images) +import Pages.PagePath as PagePath +import Pages.StaticHttp as StaticHttp +import SiteConfig + + +type alias StaticData = + () + + +type Model + = Model + + +type Msg + = Msg + + +init : Metadata -> Model +init metadata = + Model + + +staticData : a -> StaticHttp.Request StaticData +staticData siteMetadata = + StaticHttp.succeed () + + +type alias Metadata = + { title : String } + + +decoder : Decode.Decoder Metadata +decoder = + Decode.map Metadata + (Decode.field "title" Decode.string) + + +head : StaticData -> PagePath.PagePath Pages.PathKey -> Metadata -> List (Head.Tag Pages.PathKey) +head static currentPath meta = + Seo.summary + { canonicalUrlOverride = Nothing + , siteName = "elm-pages" + , image = + { url = images.iconPng + , alt = "elm-pages logo" + , dimensions = Nothing + , mimeType = Nothing + } + , description = SiteConfig.tagline + , locale = Nothing + , title = meta.title + } + |> Seo.website + + +view : StaticData -> Model -> Metadata -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view data model metadata viewForPage = + { title = metadata.title + , body = + [ Element.column + [ Element.padding 50 + , Element.spacing 60 + , Element.Region.mainContent + ] + (Tuple.second viewForPage) + ] + |> Element.textColumn + [ Element.width Element.fill + ] + } diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index f6b6fac2..12dc3e32 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -12,12 +12,14 @@ import Pages.Platform import Pages.StaticHttp as StaticHttp import SiteConfig import Template.BlogPost +import Template.Page import Template.Showcase type Metadata = MetadataBlogPost Template.BlogPost.Metadata | MetadataShowcase Template.Showcase.Metadata + | MetadataPage Template.Page.Metadata type alias Model = @@ -29,6 +31,7 @@ type alias Model = type TemplateModel = ModelBlogPost Template.BlogPost.Model | ModelShowcase Template.Showcase.Model + | ModelPage Template.Page.Model type Msg @@ -40,10 +43,6 @@ type alias View = ( MarkdownRenderer.TableOfContents, List (Element Msg) ) -toView = - Debug.todo "" - - view : List ( PagePath Pages.PathKey, Metadata ) -> @@ -89,6 +88,35 @@ view siteMetadata page = MetadataShowcase metadata -> Debug.todo "" + MetadataPage metadata -> + StaticHttp.map2 + (\data globalData -> + { view = + \model rendered -> + case model.page of + ModelPage subModel -> + Template.Page.view data subModel metadata rendered + |> (\{ title, body } -> + Global.wrapBody + globalData + page + model.global + MsgGlobal + { title = title + , body = + -- Template.BlogPost.liftViewMsg + body + } + ) + + _ -> + { title = "", body = Html.text "" } + , head = Template.Page.head data page.path metadata + } + ) + (Template.Page.staticData siteMetadata) + (Global.staticData siteMetadata) + init : Maybe @@ -115,6 +143,10 @@ init maybePagePath = MetadataShowcase metadata -> Debug.todo "" + + MetadataPage metadata -> + Template.Page.init metadata + |> ModelPage } , Cmd.none ) From c42be6b8034eb7248a0835e87f1013e2d08d1ba4 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 24 May 2020 08:52:09 -0700 Subject: [PATCH 006/106] Wire in showcase template. --- examples/docs/src/Main.elm | 41 ----- examples/docs/src/Template/Showcase.elm | 160 +++++--------------- examples/docs/src/TemplateDemultiplexer.elm | 31 +++- 3 files changed, 67 insertions(+), 165 deletions(-) diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 7d664375..69e150f5 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -200,47 +200,6 @@ subscriptions _ = Sub.none -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 - Metadata.Showcase -> - Template.Showcase.view siteMetadata - { path = page.path - , frontmatter = Template.Showcase.Metadata - } - - Metadata.Article metadata -> - --Template.BlogPost.view metadata - Template.BlogPost.template siteMetadata - { metadata = Template.BlogPost.Metadata metadata - , path = page.path - } - |> StaticHttp.map (\thing -> Debug.todo "") - - _ -> - StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages") - (D.field "stargazers_count" D.int) - |> StaticHttp.map - (\stars -> - { view = - \model viewForPage -> - pageView stars model siteMetadata page viewForPage - |> wrapBody stars page model - , head = head page.path page.frontmatter - } - ) - - pageView : Int -> Model diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index 96ad3b1c..9bc40777 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -1,23 +1,18 @@ module Template.Showcase exposing (..) import Element exposing (Element) -import Element.Font as Font import Head import Head.Seo as Seo -import Html exposing (Html) import Json.Decode as Decode exposing (Decoder) import MarkdownRenderer -import Metadata as GlobalMetadata -import OptimizedDecoder as D import Pages exposing (images) -import Pages.PagePath exposing (PagePath) +import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp -import Secrets import Showcase -type Metadata - = Metadata +type alias Metadata = + {} type Msg @@ -29,130 +24,51 @@ decoder = Decode.succeed Metadata +staticData : a -> StaticHttp.Request StaticData +staticData siteMetadata = + Showcase.staticRequest --- TODO wire in custom Model and Msg types ---type Model --- = Model + +type alias StaticData = + List Showcase.Entry + + +init : Metadata -> Model +init metadata = + Model type alias Model = - { showMobileMenu : Bool - } + {} type alias View msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) -view : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) - -> - { path : PagePath Pages.PathKey - , frontmatter : Metadata - } - -> - StaticHttp.Request - { view : - Model - -> View msg - -> { title : String, body : Html msg } - , head : List (Head.Tag Pages.PathKey) - } -view siteMetadata page = - case page.frontmatter of - Metadata -> - StaticHttp.map2 - (\stars showcaseData -> - { view = - \model viewForPage -> - { title = "elm-pages blog" - , body = - Element.column [ Element.width Element.fill ] - [ Element.column [ Element.padding 20, Element.centerX ] [ Showcase.view showcaseData ] - ] - } - |> wrapBody stars page model - , head = head page.path page.frontmatter - } - ) - (StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages") - (D.field "stargazers_count" D.int) - ) - Showcase.staticRequest - - -siteTagline : String -siteTagline = - "A statically typed site generator - elm-pages" - - -head : PagePath Pages.PathKey -> Metadata -> List (Head.Tag Pages.PathKey) -head currentPath metadata = - case metadata of - Metadata -> - Seo.summary - { canonicalUrlOverride = Nothing - , siteName = "elm-pages" - , image = - { url = images.iconPng - , alt = "elm-pages logo" - , dimensions = Nothing - , mimeType = Nothing - } - , description = "See some neat sites built using elm-pages! (Or submit yours!)" - , locale = Nothing - , title = "elm-pages sites showcase" - } - |> Seo.website - - -canonicalSiteUrl : String -canonicalSiteUrl = - "https://elm-pages.com" - - -wrapBody : Int -> { a | path : PagePath Pages.PathKey } -> Model -> { c | body : Element msg, title : String } -> { body : Html msg, title : String } -wrapBody stars page model record = - { body = - Element.column [ Element.width Element.fill ] [ record.body ] - |> Element.layout - [ Element.width Element.fill - , Font.size 20 - , Font.family [ Font.typeface "Roboto" ] - , Font.color (Element.rgba255 0 0 0 0.8) - ] - , title = record.title +view : StaticData -> Model -> Metadata -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view data model metadata viewForPage = + { title = "elm-pages blog" + , body = + Element.column [ Element.width Element.fill ] + [ Element.column [ Element.padding 20, Element.centerX ] [ Showcase.view data ] + ] } - ---wrapBody : Int -> { a | path : PagePath Pages.PathKey } -> Model -> { c | body : Element Msg, title : String } -> { body : Html Msg, title : String } ---wrapBody stars page model record = --- { body = --- (if model.showMobileMenu then --- Element.column --- [ Element.width Element.fill --- , Element.padding 20 --- ] --- [ Element.row [ Element.width Element.fill, Element.spaceEvenly ] --- [ logoLinkMobile --- , FontAwesome.styledIcon "fas fa-bars" [ Element.Events.onClick ToggleMobileMenu ] --- ] --- , Element.column [ Element.centerX, Element.spacing 20 ] --- (navbarLinks stars page.path) --- ] --- --- else --- Element.column [ Element.width Element.fill ] --- [ header stars page.path --- , record.body --- ] --- ) --- |> Element.layout --- [ Element.width Element.fill --- , Font.size 20 --- , Font.family [ Font.typeface "Roboto" ] --- , Font.color (Element.rgba255 0 0 0 0.8) --- ] --- , title = record.title --- } +head : StaticData -> PagePath.PagePath Pages.PathKey -> Metadata -> List (Head.Tag Pages.PathKey) +head static currentPath metadata = + Seo.summary + { canonicalUrlOverride = Nothing + , siteName = "elm-pages" + , image = + { url = images.iconPng + , alt = "elm-pages logo" + , dimensions = Nothing + , mimeType = Nothing + } + , description = "See some neat sites built using elm-pages! (Or submit yours!)" + , locale = Nothing + , title = "elm-pages sites showcase" + } + |> Seo.website diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index 12dc3e32..37b66792 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -86,7 +86,33 @@ view siteMetadata page = (Global.staticData siteMetadata) MetadataShowcase metadata -> - Debug.todo "" + StaticHttp.map2 + (\data globalData -> + { view = + \model rendered -> + case model.page of + ModelShowcase subModel -> + Template.Showcase.view data subModel metadata rendered + |> (\{ title, body } -> + Global.wrapBody + globalData + page + model.global + MsgGlobal + { title = title + , body = + -- Template.BlogPost.liftViewMsg + body + } + ) + + _ -> + { title = "", body = Html.text "" } + , head = Template.Showcase.head data page.path metadata + } + ) + (Template.Showcase.staticData siteMetadata) + (Global.staticData siteMetadata) MetadataPage metadata -> StaticHttp.map2 @@ -142,7 +168,8 @@ init maybePagePath = |> ModelBlogPost MetadataShowcase metadata -> - Debug.todo "" + Template.Showcase.init metadata + |> ModelShowcase MetadataPage metadata -> Template.Page.init metadata From eee1d7de7128fb632ce11d46b1651d8323a1ffcd Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 24 May 2020 09:24:48 -0700 Subject: [PATCH 007/106] Wire in update function to call template inits. --- examples/docs/src/TemplateDemultiplexer.elm | 19 ++++++++- src/Pages/Internal/Platform.elm | 45 +++++++++++++++++---- src/Pages/Internal/Platform/Cli.elm | 1 + src/Pages/Platform.elm | 3 ++ 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index 37b66792..4fd524b3 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -37,6 +37,12 @@ type TemplateModel type Msg = MsgBlogPost Template.BlogPost.Msg | MsgGlobal Global.Msg + | OnPageChange + { path : PagePath Pages.PathKey + , query : Maybe String + , fragment : Maybe String + , metadata : Metadata + } type alias View = @@ -192,6 +198,17 @@ update msg model = 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 + } + mainTemplate { documents, manifest, canonicalSiteUrl } = Pages.Platform.init @@ -209,7 +226,7 @@ mainTemplate { documents, manifest, canonicalSiteUrl } = -- } --] --, onPageChange = Just OnPageChange - , onPageChange = Nothing + , onPageChange = Just OnPageChange , manifest = manifest -- SiteConfig.manifest , canonicalSiteUrl = canonicalSiteUrl -- SiteConfig.canonicalUrl , internals = Pages.internals diff --git a/src/Pages/Internal/Platform.elm b/src/Pages/Internal/Platform.elm index 1af8587b..ff1eac59 100644 --- a/src/Pages/Internal/Platform.elm +++ b/src/Pages/Internal/Platform.elm @@ -485,6 +485,7 @@ update : ({ path : PagePath pathKey , query : Maybe String , fragment : Maybe String + , metadata : metadata } -> userMsg ) @@ -609,14 +610,42 @@ update content allRoutes canonicalSiteUrl viewFunction pathKey maybeOnPageChange ( userModel, userCmd ) = case maybeOnPageChangeMsg of Just onPageChangeMsg -> - userUpdate - (onPageChangeMsg - { path = urlToPagePath pathKey url model.baseUrl - , query = url.query - , fragment = url.fragment + let + urls = + { currentUrl = url + , baseUrl = model.baseUrl } - ) - model.userModel + + maybeMetadata = + case ContentCache.lookup pathKey updatedCache urls of + Just ( pagePath, entry ) -> + case entry of + ContentCache.Parsed metadata viewResult -> + Just metadata + + ContentCache.NeedContent string metadata -> + Nothing + + ContentCache.Unparsed string metadata contentJson -> + Nothing + + Nothing -> + Nothing + in + maybeMetadata + |> Maybe.map + (\metadata -> + userUpdate + (onPageChangeMsg + { path = urlToPagePath pathKey url model.baseUrl + , query = url.query + , fragment = url.fragment + , metadata = metadata + } + ) + model.userModel + ) + |> Maybe.withDefault ( model.userModel, Cmd.none ) _ -> ( model.userModel, Cmd.none ) @@ -725,6 +754,7 @@ application : ({ path : PagePath pathKey , query : Maybe String , fragment : Maybe String + , metadata : metadata } -> userMsg ) @@ -860,6 +890,7 @@ cliApplication : ({ path : PagePath pathKey , query : Maybe String , fragment : Maybe String + , metadata : metadata } -> userMsg ) diff --git a/src/Pages/Internal/Platform/Cli.elm b/src/Pages/Internal/Platform/Cli.elm index 14ccb396..6ad6c2cc 100644 --- a/src/Pages/Internal/Platform/Cli.elm +++ b/src/Pages/Internal/Platform/Cli.elm @@ -210,6 +210,7 @@ type alias Config pathKey userMsg userModel metadata view = ({ path : PagePath pathKey , query : Maybe String , fragment : Maybe String + , metadata : metadata } -> userMsg ) diff --git a/src/Pages/Platform.elm b/src/Pages/Platform.elm index 898ab204..42f11ac2 100644 --- a/src/Pages/Platform.elm +++ b/src/Pages/Platform.elm @@ -126,6 +126,7 @@ type Builder pathKey model msg metadata view ({ path : PagePath pathKey , query : Maybe String , fragment : Maybe String + , metadata : metadata } -> msg ) @@ -196,6 +197,7 @@ init : ({ path : PagePath pathKey , query : Maybe String , fragment : Maybe String + , metadata : metadata } -> msg ) @@ -362,6 +364,7 @@ application : ({ path : PagePath pathKey , query : Maybe String , fragment : Maybe String + , metadata : metadata } -> msg ) From 8a9cc44a2bd51727889c77918826aa7c82d5f390 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 24 May 2020 10:34:57 -0700 Subject: [PATCH 008/106] Remove unused metadata type. --- examples/docs/src/Main.elm | 55 ---------------------------------- examples/docs/src/Metadata.elm | 8 ----- 2 files changed, 63 deletions(-) diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 69e150f5..d79f6fd4 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -281,26 +281,6 @@ pageView stars model siteMetadata page viewForPage = ] } - Metadata.Author author -> - { title = author.name - , body = - Element.column - [ Element.width Element.fill - ] - [ Element.column - [ Element.padding 30 - , Element.spacing 20 - , Element.Region.mainContent - , Element.width (Element.fill |> Element.maximum 800) - , Element.centerX - ] - [ Palette.blogHeading author.name - , Author.view [] author - , Element.paragraph [ Element.centerX, Font.center ] (Tuple.second viewForPage) - ] - ] - } - Metadata.BlogIndex -> { title = "elm-pages blog" , body = @@ -549,41 +529,6 @@ head currentPath metadata = } ) - 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 - } - Metadata.BlogIndex -> Seo.summary { canonicalUrlOverride = Nothing diff --git a/examples/docs/src/Metadata.elm b/examples/docs/src/Metadata.elm index 85748cf0..b769d9ae 100644 --- a/examples/docs/src/Metadata.elm +++ b/examples/docs/src/Metadata.elm @@ -15,7 +15,6 @@ type Metadata = Page PageMetadata | Article ArticleMetadata | Doc DocMetadata - | Author Data.Author.Author | BlogIndex | Showcase @@ -58,13 +57,6 @@ decoder = "showcase" -> Decode.succeed Showcase - "author" -> - Decode.map3 Data.Author.Author - (Decode.field "name" Decode.string) - (Decode.field "avatar" imageDecoder) - (Decode.field "bio" Decode.string) - |> Decode.map Author - "blog" -> Decode.map6 ArticleMetadata (Decode.field "title" Decode.string) From 2ff13c00e32a4bdf2d8aeb84df973198d7ac8f79 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 24 May 2020 12:33:17 -0700 Subject: [PATCH 009/106] Wire in blog index with an empty list of posts for now. --- examples/docs/src/AllMetadata.elm | 13 ++ examples/docs/src/Index.elm | 23 ++- examples/docs/src/Main.elm | 150 ++------------------ examples/docs/src/MetadataNew.elm | 16 ++- examples/docs/src/Template/BlogIndex.elm | 86 +++++++++++ examples/docs/src/Template/BlogPost.elm | 15 +- examples/docs/src/TemplateDemultiplexer.elm | 55 +++++-- 7 files changed, 174 insertions(+), 184 deletions(-) create mode 100644 examples/docs/src/AllMetadata.elm create mode 100644 examples/docs/src/Template/BlogIndex.elm diff --git a/examples/docs/src/AllMetadata.elm b/examples/docs/src/AllMetadata.elm new file mode 100644 index 00000000..573ebae9 --- /dev/null +++ b/examples/docs/src/AllMetadata.elm @@ -0,0 +1,13 @@ +module AllMetadata exposing (..) + +import Template.BlogIndex +import Template.BlogPost +import Template.Page +import Template.Showcase + + +type Metadata + = MetadataBlogPost Template.BlogPost.Metadata + | MetadataShowcase Template.Showcase.Metadata + | MetadataPage Template.Page.Metadata + | MetadataBlogIndex Template.BlogIndex.Metadata diff --git a/examples/docs/src/Index.elm b/examples/docs/src/Index.elm index 1862542a..f30e0267 100644 --- a/examples/docs/src/Index.elm +++ b/examples/docs/src/Index.elm @@ -1,15 +1,17 @@ module Index exposing (view) +--import Pages.Metadata as Metadata exposing (Metadata) + import Data.Author import Date import Element exposing (Element) import Element.Border import Element.Font -import Metadata exposing (Metadata) import Pages import Pages.ImagePath as ImagePath exposing (ImagePath) import Pages.PagePath as PagePath exposing (PagePath) import Pages.Platform exposing (Page) +import Template.BlogPost exposing (Metadata) view : @@ -20,16 +22,11 @@ view posts = (posts |> List.filterMap (\( path, metadata ) -> - case metadata of - Metadata.Article meta -> - if meta.draft then - Nothing + if metadata.draft then + Nothing - else - Just ( path, meta ) - - _ -> - Nothing + else + Just ( path, metadata ) ) |> List.sortBy (\( path, metadata ) -> @@ -42,7 +39,7 @@ view posts = postSummary : - ( PagePath Pages.PathKey, Metadata.ArticleMetadata ) + ( PagePath Pages.PathKey, Metadata ) -> Element msg postSummary ( postPath, post ) = articleIndex post |> linkToPost postPath @@ -66,7 +63,7 @@ title text = ] -articleIndex : Metadata.ArticleMetadata -> Element msg +articleIndex : Metadata -> Element msg articleIndex metadata = Element.el [ Element.centerX @@ -86,7 +83,7 @@ grey = Element.Font.color (Element.rgba255 0 0 0 0.5) -postPreview : Metadata.ArticleMetadata -> Element msg +postPreview : Metadata -> Element msg postPreview post = Element.textColumn [ Element.centerX diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index d79f6fd4..464feda5 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -1,5 +1,6 @@ module Main exposing (main) +import AllMetadata import Color import Data.Author as Author import Date @@ -54,7 +55,7 @@ manifest = , iarcRatingId = Nothing , name = "elm-pages docs" , themeColor = Just Color.white - , startUrl = pages.index + , startUrl = pages.blog.staticHttp , shortName = Just "elm-pages" , sourceIcon = images.iconPng } @@ -64,7 +65,7 @@ type alias View = ( MarkdownRenderer.TableOfContents, List (Element Msg) ) -main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg TemplateDemultiplexer.Metadata TemplateDemultiplexer.View +main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg AllMetadata.Metadata TemplateDemultiplexer.View main = TemplateDemultiplexer.mainTemplate { documents = @@ -209,52 +210,6 @@ pageView : -> { title : String, body : Element Msg } pageView stars model siteMetadata page viewForPage = case page.frontmatter of - Metadata.Page metadata -> - { title = metadata.title - , body = - [ Element.column - [ Element.padding 50 - , Element.spacing 60 - , Element.Region.mainContent - ] - (Tuple.second viewForPage) - ] - |> Element.textColumn - [ Element.width Element.fill - ] - } - - Metadata.Article metadata -> - { title = metadata.title - , body = - Element.column [ Element.width Element.fill ] - [ Element.column - [ Element.padding 30 - , Element.spacing 40 - , Element.Region.mainContent - , Element.width (Element.fill |> Element.maximum 800) - , Element.centerX - ] - (Element.column [ Element.spacing 10 ] - [ Element.row [ Element.spacing 10 ] - [ Author.view [] metadata.author - , Element.column [ Element.spacing 10, Element.width Element.fill ] - [ Element.paragraph [ Font.bold, Font.size 24 ] - [ Element.text metadata.author.name - ] - , Element.paragraph [ Font.size 16 ] - [ Element.text metadata.author.bio ] - ] - ] - ] - :: (publishedDateView metadata |> Element.el [ Font.size 16, Font.color (Element.rgba255 0 0 0 0.6) ]) - :: Palette.blogHeading metadata.title - :: articleImageView metadata.image - :: Tuple.second viewForPage - ) - ] - } - Metadata.Doc metadata -> { title = metadata.title , body = @@ -281,96 +236,8 @@ pageView stars model siteMetadata page viewForPage = ] } - Metadata.BlogIndex -> - { title = "elm-pages blog" - , body = - Element.column [ Element.width Element.fill ] - [ Element.column [ Element.padding 20, Element.centerX ] [ Index.view siteMetadata ] - ] - } - - Metadata.Showcase -> - { title = "elm-pages blog" - , body = - Element.column [ Element.width Element.fill ] - [--, Element.column [ Element.padding 20, Element.centerX ] [ Showcase.view siteMetadata ] - ] - } - - -wrapBody : Int -> { a | path : PagePath Pages.PathKey } -> Model -> { c | body : Element Msg, title : String } -> { body : Html Msg, title : String } -wrapBody stars page model record = - { body = - (if model.showMobileMenu then - Element.column - [ Element.width Element.fill - , Element.padding 20 - ] - [ Element.row [ Element.width Element.fill, Element.spaceEvenly ] - [ logoLinkMobile - , FontAwesome.styledIcon "fas fa-bars" [ Element.Events.onClick ToggleMobileMenu ] - ] - , Element.column [ Element.centerX, Element.spacing 20 ] - (navbarLinks stars page.path) - ] - - else - Element.column [ Element.width Element.fill ] - [ header stars page.path - , record.body - ] - ) - |> Element.layout - [ Element.width Element.fill - , Font.size 20 - , Font.family [ Font.typeface "Roboto" ] - , Font.color (Element.rgba255 0 0 0 0.8) - ] - , title = record.title - } - - -articleImageView : ImagePath Pages.PathKey -> Element msg -articleImageView articleImage = - Element.image [ Element.width Element.fill ] - { src = ImagePath.toString articleImage - , description = "Article cover photo" - } - - -header : Int -> PagePath Pages.PathKey -> Element Msg -header stars currentPath = - Element.column [ Element.width Element.fill ] - [ responsiveHeader - , Element.column - [ Element.width Element.fill - , Element.htmlAttribute (Attr.class "responsive-desktop") - ] - [ Element.el - [ Element.height (Element.px 4) - , Element.width Element.fill - , Element.Background.gradient - { angle = 0.2 - , steps = - [ Element.rgb255 0 242 96 - , Element.rgb255 5 117 230 - ] - } - ] - Element.none - , Element.row - [ Element.paddingXY 25 4 - , Element.spaceEvenly - , Element.width Element.fill - , Element.Region.navigation - , Element.Border.widthEach { bottom = 1, left = 0, right = 0, top = 0 } - , Element.Border.color (Element.rgba255 40 80 40 0.4) - ] - [ logoLink - , Element.row [ Element.spacing 15 ] (navbarLinks stars currentPath) - ] - ] - ] + _ -> + Debug.todo "" logoLink = @@ -405,9 +272,10 @@ logoLinkMobile = navbarLinks stars currentPath = [ elmDocsLink , githubRepoLink stars - , highlightableLink currentPath pages.docs.directory "Docs" - , highlightableLink currentPath pages.showcase.directory "Showcase" - , highlightableLink currentPath pages.blog.directory "Blog" + + --, highlightableLink currentPath pages.docs.directory "Docs" + --, highlightableLink currentPath pages.showcase.directory "Showcase" + --, highlightableLink currentPath pages.blog.directory "Blog" ] diff --git a/examples/docs/src/MetadataNew.elm b/examples/docs/src/MetadataNew.elm index 0c434b34..6a12adda 100644 --- a/examples/docs/src/MetadataNew.elm +++ b/examples/docs/src/MetadataNew.elm @@ -1,10 +1,11 @@ module MetadataNew exposing (DocMetadata, PageMetadata, decoder) +import AllMetadata as Metadata exposing (Metadata) import Json.Decode as Decode exposing (Decoder) +import Template.BlogIndex import Template.BlogPost import Template.Page import Template.Showcase -import TemplateDemultiplexer as TD exposing (Metadata) type alias DocMetadata = @@ -28,14 +29,15 @@ decoder = -- "page" -> Template.Page.decoder - |> Decode.map TD.MetadataPage + |> Decode.map Metadata.MetadataPage + + "blog-index" -> + Template.BlogIndex.decoder + |> Decode.map Metadata.MetadataBlogIndex - -- - --"blog-index" -> - -- Decode.succeed BlogIndex "showcase" -> Template.Showcase.decoder - |> Decode.map TD.MetadataShowcase + |> Decode.map Metadata.MetadataShowcase -- --"author" -> @@ -46,7 +48,7 @@ decoder = -- |> Decode.map Author "blog" -> Template.BlogPost.decoder - |> Decode.map TD.MetadataBlogPost + |> Decode.map Metadata.MetadataBlogPost _ -> Decode.fail <| "Unexpected page \"type\" " ++ pageType diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm new file mode 100644 index 00000000..a8a7e76f --- /dev/null +++ b/examples/docs/src/Template/BlogIndex.elm @@ -0,0 +1,86 @@ +module Template.BlogIndex exposing (..) + +import Element exposing (Element) +import Head +import Head.Seo as Seo +import Index +import Json.Decode as Decode exposing (Decoder) +import MarkdownRenderer +import Pages exposing (images) +import Pages.PagePath as PagePath exposing (PagePath) +import Pages.StaticHttp as StaticHttp +import Showcase +import SiteConfig + + +type alias Metadata = + {} + + +type Msg + = Msg + + +decoder : Decoder Metadata +decoder = + Decode.succeed Metadata + + +staticData : a -> StaticHttp.Request StaticData +staticData siteMetadata = + Showcase.staticRequest + + +type alias StaticData = + List Showcase.Entry + + +init : Metadata -> Model +init metadata = + Model + + +type alias Model = + {} + + +type alias View msg = + ( MarkdownRenderer.TableOfContents, List (Element msg) ) + + +view : StaticData -> Model -> Metadata -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view data model metadata viewForPage = + { title = "elm-pages blog" + , body = + Element.column [ Element.width Element.fill ] + [ Element.column [ Element.padding 20, Element.centerX ] + [ Index.view [] ] + ] + } + + + +--{ title = "elm-pages blog" +--, body = +-- Element.column [ Element.width Element.fill ] +-- [ Element.column [ Element.padding 20, Element.centerX ] [ Showcase.view data ] +-- ] +--} + + +head : StaticData -> PagePath.PagePath Pages.PathKey -> Metadata -> List (Head.Tag Pages.PathKey) +head static currentPath metadata = + Seo.summary + { canonicalUrlOverride = Nothing + , siteName = "elm-pages" + , image = + { url = images.iconPng + , alt = "elm-pages logo" + , dimensions = Nothing + , mimeType = Nothing + } + , description = SiteConfig.tagline + , locale = Nothing + , title = "elm-pages blog" + } + |> Seo.website diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 72458d19..658a8aac 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -1,4 +1,4 @@ -module Template.BlogPost exposing (Metadata(..), Model, Msg, decoder, head, init, liftViewMsg, staticData, template, view) +module Template.BlogPost exposing (Metadata, Model, Msg, decoder, head, init, liftViewMsg, staticData, template, view) import Data.Author as Author exposing (Author) import Date exposing (Date) @@ -21,11 +21,7 @@ import StructuredData import Template -type Metadata - = Metadata MetadataRecord - - -type alias MetadataRecord = +type alias Metadata = { title : String , description : String , published : Date @@ -57,7 +53,7 @@ template = decoder : Decode.Decoder Metadata decoder = - Decode.map6 MetadataRecord + Decode.map6 Metadata (Decode.field "title" Decode.string) (Decode.field "description" Decode.string) (Decode.field "published" @@ -79,7 +75,6 @@ decoder = |> Decode.maybe |> Decode.map (Maybe.withDefault False) ) - |> Decode.map Metadata imageDecoder : Decode.Decoder (ImagePath Pages.PathKey) @@ -124,7 +119,7 @@ liftViewMsg liftMsg = view : StaticData -> Model -> Metadata -> ( a, List (Element msg) ) -> { title : String, body : Element msg } -view static model (Metadata blogPost) rendered = +view static model blogPost rendered = { title = blogPost.title , body = Element.column [ Element.width Element.fill ] @@ -157,7 +152,7 @@ view static model (Metadata blogPost) rendered = head : StaticData -> PagePath.PagePath Pages.PathKey -> Metadata -> List (Head.Tag Pages.PathKey) -head static currentPath (Metadata meta) = +head static currentPath meta = Head.structuredData (StructuredData.article { title = meta.title diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index 4fd524b3..06368937 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -1,27 +1,22 @@ module TemplateDemultiplexer exposing (..) +import AllMetadata as M exposing (Metadata) import Element exposing (Element) import Global import Head import Html exposing (Html) import MarkdownRenderer -import Metadata 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.Page import Template.Showcase -type Metadata - = MetadataBlogPost Template.BlogPost.Metadata - | MetadataShowcase Template.Showcase.Metadata - | MetadataPage Template.Page.Metadata - - type alias Model = { global : Global.Model , page : TemplateModel @@ -32,6 +27,7 @@ type TemplateModel = ModelBlogPost Template.BlogPost.Model | ModelShowcase Template.Showcase.Model | ModelPage Template.Page.Model + | ModelBlogIndex Template.BlogIndex.Model type Msg @@ -62,7 +58,7 @@ view : } view siteMetadata page = case page.frontmatter of - MetadataBlogPost metadata -> + M.MetadataBlogPost metadata -> StaticHttp.map2 (\data globalData -> { view = @@ -91,7 +87,7 @@ view siteMetadata page = (Template.BlogPost.staticData siteMetadata) (Global.staticData siteMetadata) - MetadataShowcase metadata -> + M.MetadataShowcase metadata -> StaticHttp.map2 (\data globalData -> { view = @@ -120,7 +116,7 @@ view siteMetadata page = (Template.Showcase.staticData siteMetadata) (Global.staticData siteMetadata) - MetadataPage metadata -> + M.MetadataPage metadata -> StaticHttp.map2 (\data globalData -> { view = @@ -149,6 +145,35 @@ view siteMetadata page = (Template.Page.staticData siteMetadata) (Global.staticData siteMetadata) + M.MetadataBlogIndex metadata -> + StaticHttp.map2 + (\data globalData -> + { view = + \model rendered -> + case model.page of + ModelBlogIndex subModel -> + Template.BlogIndex.view data subModel metadata rendered + |> (\{ title, body } -> + Global.wrapBody + globalData + page + model.global + MsgGlobal + { title = title + , body = + -- Template.BlogPost.liftViewMsg + body + } + ) + + _ -> + { title = "", body = Html.text "" } + , head = Template.BlogIndex.head data page.path metadata + } + ) + (Template.BlogIndex.staticData siteMetadata) + (Global.staticData siteMetadata) + init : Maybe @@ -169,17 +194,21 @@ init maybePagePath = Just meta -> case meta of - MetadataBlogPost metadata -> + M.MetadataBlogPost metadata -> Template.BlogPost.init metadata |> ModelBlogPost - MetadataShowcase metadata -> + M.MetadataShowcase metadata -> Template.Showcase.init metadata |> ModelShowcase - MetadataPage metadata -> + M.MetadataPage metadata -> Template.Page.init metadata |> ModelPage + + M.MetadataBlogIndex metadata -> + Template.BlogIndex.init metadata + |> ModelBlogIndex } , Cmd.none ) From de49f37deec669f3fe50bf1618b5347672f05801 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 24 May 2020 12:36:01 -0700 Subject: [PATCH 010/106] Remove some unused code. --- examples/docs/src/Main.elm | 234 +------------------------------------ 1 file changed, 3 insertions(+), 231 deletions(-) diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 464feda5..fe119e59 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -2,29 +2,21 @@ module Main exposing (main) import AllMetadata import Color -import Data.Author as Author +import Data.Author import Date import DocSidebar import DocumentSvg import Element exposing (Element) -import Element.Background -import Element.Border import Element.Events import Element.Font as Font import Element.Region import FontAwesome import Head import Head.Seo as Seo -import Html exposing (Html) import Html.Attributes as Attr -import Index -import Json.Decode as Decode exposing (Decoder) -import Json.Encode import MarkdownRenderer import Metadata exposing (Metadata) import MetadataNew -import MySitemap -import OptimizedDecoder as D import Pages exposing (images, pages) import Pages.Directory as Directory exposing (Directory) import Pages.ImagePath as ImagePath exposing (ImagePath) @@ -32,16 +24,10 @@ import Pages.Manifest as Manifest import Pages.Manifest.Category import Pages.PagePath as PagePath exposing (PagePath) import Pages.Platform exposing (Page) -import Pages.StaticHttp as StaticHttp import Palette import Rss -import RssPlugin -import Secrets -import Showcase import SiteConfig import StructuredData -import Template.BlogPost -import Template.Showcase import TemplateDemultiplexer @@ -166,17 +152,6 @@ type alias Model = } -init : - Maybe - { path : PagePath Pages.PathKey - , query : Maybe String - , fragment : Maybe String - } - -> ( Model, Cmd Msg ) -init maybePagePath = - ( Model False, Cmd.none ) - - type Msg = OnPageChange { path : PagePath Pages.PathKey @@ -196,11 +171,6 @@ update msg model = ( { model | showMobileMenu = not model.showMobileMenu }, Cmd.none ) -subscriptions : Model -> Sub Msg -subscriptions _ = - Sub.none - - pageView : Int -> Model @@ -240,82 +210,6 @@ pageView stars model siteMetadata page viewForPage = Debug.todo "" -logoLink = - Element.link [] - { url = "/" - , label = - Element.row - [ Font.size 30 - , Element.spacing 16 - , Element.htmlAttribute (Attr.class "navbar-title") - ] - [ DocumentSvg.view - , Element.text "elm-pages" - ] - } - - -logoLinkMobile = - Element.link [] - { url = "/" - , label = - Element.row - [ Font.size 30 - , Element.spacing 16 - , Element.htmlAttribute (Attr.class "navbar-title") - ] - [ Element.text "elm-pages" - ] - } - - -navbarLinks stars currentPath = - [ elmDocsLink - , githubRepoLink stars - - --, highlightableLink currentPath pages.docs.directory "Docs" - --, highlightableLink currentPath pages.showcase.directory "Showcase" - --, highlightableLink currentPath pages.blog.directory "Blog" - ] - - -responsiveHeader = - Element.row - [ Element.width Element.fill - , Element.spaceEvenly - , Element.htmlAttribute (Attr.class "responsive-mobile") - , Element.width Element.fill - , Element.padding 20 - ] - [ logoLinkMobile - , FontAwesome.icon "fas fa-bars" |> Element.el [ Element.alignRight, Element.Events.onClick ToggleMobileMenu ] - ] - - -highlightableLink : - PagePath Pages.PathKey - -> Directory Pages.PathKey Directory.WithIndex - -> String - -> Element msg -highlightableLink currentPath linkDirectory displayName = - let - isHighlighted = - currentPath |> Directory.includes linkDirectory - in - Element.link - (if isHighlighted then - [ Font.underline - , Font.color Palette.color.primary - ] - - else - [] - ) - { url = linkDirectory |> Directory.indexPath |> PagePath.toString - , label = Element.text displayName - } - - {-| @@ -324,22 +218,6 @@ highlightableLink currentPath linkDirectory displayName = head : PagePath Pages.PathKey -> Metadata -> List (Head.Tag Pages.PathKey) head currentPath metadata = case metadata of - Metadata.Page meta -> - Seo.summary - { canonicalUrlOverride = Nothing - , siteName = "elm-pages" - , image = - { url = images.iconPng - , alt = "elm-pages logo" - , dimensions = Nothing - , mimeType = Nothing - } - , description = siteTagline - , locale = Nothing - , title = meta.title - } - |> Seo.website - Metadata.Doc meta -> Seo.summary { canonicalUrlOverride = Nothing @@ -356,78 +234,8 @@ head currentPath metadata = } |> Seo.website - Metadata.Article meta -> - Head.structuredData - (StructuredData.article - { title = meta.title - , description = meta.description - , author = StructuredData.person { name = meta.author.name } - , publisher = StructuredData.person { name = "Dillon Kearns" } - , url = canonicalSiteUrl ++ "/" ++ PagePath.toString currentPath - , imageUrl = canonicalSiteUrl ++ "/" ++ ImagePath.toString meta.image - , datePublished = Date.toIsoString meta.published - , mainEntityOfPage = - StructuredData.softwareSourceCode - { codeRepositoryUrl = "https://github.com/dillonkearns/elm-pages" - , description = "A statically typed site generator for Elm." - , author = "Dillon Kearns" - , programmingLanguage = StructuredData.elmLang - } - } - ) - :: (Seo.summaryLarge - { canonicalUrlOverride = Nothing - , siteName = "elm-pages" - , image = - { url = meta.image - , alt = meta.description - , dimensions = Nothing - , mimeType = Nothing - } - , description = meta.description - , locale = Nothing - , title = meta.title - } - |> Seo.article - { tags = [] - , section = Nothing - , publishedTime = Just (Date.toIsoString meta.published) - , modifiedTime = Nothing - , expirationTime = Nothing - } - ) - - Metadata.BlogIndex -> - Seo.summary - { canonicalUrlOverride = Nothing - , siteName = "elm-pages" - , image = - { url = images.iconPng - , alt = "elm-pages logo" - , dimensions = Nothing - , mimeType = Nothing - } - , description = siteTagline - , locale = Nothing - , title = "elm-pages blog" - } - |> Seo.website - - Metadata.Showcase -> - Seo.summary - { canonicalUrlOverride = Nothing - , siteName = "elm-pages" - , image = - { url = images.iconPng - , alt = "elm-pages logo" - , dimensions = Nothing - , mimeType = Nothing - } - , description = "See some neat sites built using elm-pages! (Or submit yours!)" - , locale = Nothing - , title = "elm-pages sites showcase" - } - |> Seo.website + _ -> + Debug.todo "" canonicalSiteUrl : String @@ -455,39 +263,3 @@ tocView toc = ) ) ] - - -publishedDateView metadata = - Element.text - (metadata.published - |> Date.format "MMMM ddd, yyyy" - ) - - -githubRepoLink : Int -> Element msg -githubRepoLink starCount = - Element.newTabLink [] - { url = "https://github.com/dillonkearns/elm-pages" - , label = - Element.row [ Element.spacing 5 ] - [ Element.image - [ Element.width (Element.px 22) - , Font.color Palette.color.primary - ] - { src = ImagePath.toString Pages.images.github, description = "Github repo" } - , Element.text <| String.fromInt starCount - ] - } - - -elmDocsLink : Element msg -elmDocsLink = - Element.newTabLink [] - { url = "https://package.elm-lang.org/packages/dillonkearns/elm-pages/latest/" - , label = - Element.image - [ Element.width (Element.px 22) - , Font.color Palette.color.primary - ] - { src = ImagePath.toString Pages.images.elmLogo, description = "Elm Package Docs" } - } From ec513fd0b8072868747d1e6414f724b762385565 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Tue, 26 May 2020 20:51:38 -0700 Subject: [PATCH 011/106] Move some metadata to an external module to prevent circular dependencies. --- examples/docs/src/AllMetadata.elm | 4 ++-- examples/docs/src/Index.elm | 20 +++++++++++-------- examples/docs/src/MetadataNew.elm | 3 ++- examples/docs/src/MetadataThing.elm | 0 examples/docs/src/Template/BlogIndex.elm | 20 +++++++------------ .../docs/src/Template/BlogIndexMetadata.elm | 12 +++++++++++ examples/docs/src/Template/Metadata.elm | 0 examples/docs/src/TemplateDemultiplexer.elm | 2 +- 8 files changed, 36 insertions(+), 25 deletions(-) create mode 100644 examples/docs/src/MetadataThing.elm create mode 100644 examples/docs/src/Template/BlogIndexMetadata.elm create mode 100644 examples/docs/src/Template/Metadata.elm diff --git a/examples/docs/src/AllMetadata.elm b/examples/docs/src/AllMetadata.elm index 573ebae9..cdaec812 100644 --- a/examples/docs/src/AllMetadata.elm +++ b/examples/docs/src/AllMetadata.elm @@ -1,6 +1,6 @@ module AllMetadata exposing (..) -import Template.BlogIndex +import Template.BlogIndexMetadata import Template.BlogPost import Template.Page import Template.Showcase @@ -10,4 +10,4 @@ type Metadata = MetadataBlogPost Template.BlogPost.Metadata | MetadataShowcase Template.Showcase.Metadata | MetadataPage Template.Page.Metadata - | MetadataBlogIndex Template.BlogIndex.Metadata + | MetadataBlogIndex Template.BlogIndexMetadata.Metadata diff --git a/examples/docs/src/Index.elm b/examples/docs/src/Index.elm index f30e0267..953bddd0 100644 --- a/examples/docs/src/Index.elm +++ b/examples/docs/src/Index.elm @@ -2,6 +2,7 @@ module Index exposing (view) --import Pages.Metadata as Metadata exposing (Metadata) +import AllMetadata import Data.Author import Date import Element exposing (Element) @@ -15,25 +16,28 @@ import Template.BlogPost exposing (Metadata) view : - List ( PagePath Pages.PathKey, Metadata ) + List ( PagePath Pages.PathKey, AllMetadata.Metadata ) -> Element msg view posts = Element.column [ Element.spacing 20 ] (posts |> List.filterMap (\( path, metadata ) -> - if metadata.draft then - Nothing + case metadata of + AllMetadata.MetadataBlogPost meta -> + if meta.draft then + Nothing - else - Just ( path, metadata ) + else + Just ( path, meta ) + + _ -> + Nothing ) |> List.sortBy (\( path, metadata ) -> - metadata.published - |> Date.toRataDie + -(metadata.published |> Date.toRataDie) ) - |> List.reverse |> List.map postSummary ) diff --git a/examples/docs/src/MetadataNew.elm b/examples/docs/src/MetadataNew.elm index 6a12adda..063b7e76 100644 --- a/examples/docs/src/MetadataNew.elm +++ b/examples/docs/src/MetadataNew.elm @@ -3,6 +3,7 @@ module MetadataNew exposing (DocMetadata, PageMetadata, decoder) import AllMetadata as Metadata exposing (Metadata) import Json.Decode as Decode exposing (Decoder) import Template.BlogIndex +import Template.BlogIndexMetadata import Template.BlogPost import Template.Page import Template.Showcase @@ -32,7 +33,7 @@ decoder = |> Decode.map Metadata.MetadataPage "blog-index" -> - Template.BlogIndex.decoder + Template.BlogIndexMetadata.decoder |> Decode.map Metadata.MetadataBlogIndex "showcase" -> diff --git a/examples/docs/src/MetadataThing.elm b/examples/docs/src/MetadataThing.elm new file mode 100644 index 00000000..e69de29b diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index a8a7e76f..4f5f0e68 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -1,31 +1,23 @@ module Template.BlogIndex exposing (..) +import AllMetadata import Element exposing (Element) import Head import Head.Seo as Seo import Index -import Json.Decode as Decode exposing (Decoder) import MarkdownRenderer import Pages exposing (images) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Showcase import SiteConfig - - -type alias Metadata = - {} +import Template.BlogIndexMetadata exposing (Metadata) type Msg = Msg -decoder : Decoder Metadata -decoder = - Decode.succeed Metadata - - staticData : a -> StaticHttp.Request StaticData staticData siteMetadata = Showcase.staticRequest @@ -48,13 +40,15 @@ type alias View msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) -view : StaticData -> Model -> Metadata -> ( a, List (Element msg) ) -> { title : String, body : Element msg } -view data model metadata viewForPage = +view : List ( PagePath Pages.PathKey, AllMetadata.Metadata ) -> StaticData -> Model -> Metadata -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view siteMetadata data model metadata viewForPage = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] [ Element.column [ Element.padding 20, Element.centerX ] - [ Index.view [] ] + [ siteMetadata + |> Index.view + ] ] } diff --git a/examples/docs/src/Template/BlogIndexMetadata.elm b/examples/docs/src/Template/BlogIndexMetadata.elm new file mode 100644 index 00000000..c0d433a2 --- /dev/null +++ b/examples/docs/src/Template/BlogIndexMetadata.elm @@ -0,0 +1,12 @@ +module Template.BlogIndexMetadata exposing (..) + +import Json.Decode as Decode exposing (Decoder) + + +type alias Metadata = + {} + + +decoder : Decoder Metadata +decoder = + Decode.succeed Metadata diff --git a/examples/docs/src/Template/Metadata.elm b/examples/docs/src/Template/Metadata.elm new file mode 100644 index 00000000..e69de29b diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index 06368937..24ea80cd 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -152,7 +152,7 @@ view siteMetadata page = \model rendered -> case model.page of ModelBlogIndex subModel -> - Template.BlogIndex.view data subModel metadata rendered + Template.BlogIndex.view siteMetadata data subModel metadata rendered |> (\{ title, body } -> Global.wrapBody globalData From fab5c09844296c8c7273427ed6e01a59d637e19d Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 27 May 2020 12:58:11 -0700 Subject: [PATCH 012/106] Move user-defined metadata to its own module. --- examples/docs/src/AllMetadata.elm | 13 +++---- examples/docs/src/Index.elm | 9 +++-- examples/docs/src/MetadataNew.elm | 4 +-- examples/docs/src/Template/BlogIndex.elm | 8 ++--- .../docs/src/Template/BlogIndexMetadata.elm | 12 ------- examples/docs/src/Template/BlogPost.elm | 35 ++++++++++--------- examples/docs/src/Template/Metadata.elm | 28 +++++++++++++++ examples/docs/src/Template/Page.elm | 17 ++++----- examples/docs/src/Template/Showcase.elm | 15 ++++---- 9 files changed, 73 insertions(+), 68 deletions(-) delete mode 100644 examples/docs/src/Template/BlogIndexMetadata.elm diff --git a/examples/docs/src/AllMetadata.elm b/examples/docs/src/AllMetadata.elm index cdaec812..f0832c5d 100644 --- a/examples/docs/src/AllMetadata.elm +++ b/examples/docs/src/AllMetadata.elm @@ -1,13 +1,10 @@ module AllMetadata exposing (..) -import Template.BlogIndexMetadata -import Template.BlogPost -import Template.Page -import Template.Showcase +import Template.Metadata type Metadata - = MetadataBlogPost Template.BlogPost.Metadata - | MetadataShowcase Template.Showcase.Metadata - | MetadataPage Template.Page.Metadata - | MetadataBlogIndex Template.BlogIndexMetadata.Metadata + = MetadataBlogPost Template.Metadata.BlogPost + | MetadataShowcase Template.Metadata.Showcase + | MetadataPage Template.Metadata.Page + | MetadataBlogIndex Template.Metadata.BlogIndex diff --git a/examples/docs/src/Index.elm b/examples/docs/src/Index.elm index 953bddd0..1a672e3f 100644 --- a/examples/docs/src/Index.elm +++ b/examples/docs/src/Index.elm @@ -11,8 +11,7 @@ import Element.Font import Pages import Pages.ImagePath as ImagePath exposing (ImagePath) import Pages.PagePath as PagePath exposing (PagePath) -import Pages.Platform exposing (Page) -import Template.BlogPost exposing (Metadata) +import Template.Metadata exposing (BlogPost) view : @@ -43,7 +42,7 @@ view posts = postSummary : - ( PagePath Pages.PathKey, Metadata ) + ( PagePath Pages.PathKey, BlogPost ) -> Element msg postSummary ( postPath, post ) = articleIndex post |> linkToPost postPath @@ -67,7 +66,7 @@ title text = ] -articleIndex : Metadata -> Element msg +articleIndex : BlogPost -> Element msg articleIndex metadata = Element.el [ Element.centerX @@ -87,7 +86,7 @@ grey = Element.Font.color (Element.rgba255 0 0 0 0.5) -postPreview : Metadata -> Element msg +postPreview : BlogPost -> Element msg postPreview post = Element.textColumn [ Element.centerX diff --git a/examples/docs/src/MetadataNew.elm b/examples/docs/src/MetadataNew.elm index 063b7e76..8b5ccbcb 100644 --- a/examples/docs/src/MetadataNew.elm +++ b/examples/docs/src/MetadataNew.elm @@ -2,8 +2,6 @@ module MetadataNew exposing (DocMetadata, PageMetadata, decoder) import AllMetadata as Metadata exposing (Metadata) import Json.Decode as Decode exposing (Decoder) -import Template.BlogIndex -import Template.BlogIndexMetadata import Template.BlogPost import Template.Page import Template.Showcase @@ -33,7 +31,7 @@ decoder = |> Decode.map Metadata.MetadataPage "blog-index" -> - Template.BlogIndexMetadata.decoder + Decode.succeed {} |> Decode.map Metadata.MetadataBlogIndex "showcase" -> diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 4f5f0e68..bd3c5b08 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -11,7 +11,7 @@ import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Showcase import SiteConfig -import Template.BlogIndexMetadata exposing (Metadata) +import Template.Metadata exposing (BlogIndex) type Msg @@ -27,7 +27,7 @@ type alias StaticData = List Showcase.Entry -init : Metadata -> Model +init : BlogIndex -> Model init metadata = Model @@ -40,7 +40,7 @@ type alias View msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) -view : List ( PagePath Pages.PathKey, AllMetadata.Metadata ) -> StaticData -> Model -> Metadata -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view : List ( PagePath Pages.PathKey, AllMetadata.Metadata ) -> StaticData -> Model -> BlogIndex -> ( a, List (Element msg) ) -> { title : String, body : Element msg } view siteMetadata data model metadata viewForPage = { title = "elm-pages blog" , body = @@ -62,7 +62,7 @@ view siteMetadata data model metadata viewForPage = --} -head : StaticData -> PagePath.PagePath Pages.PathKey -> Metadata -> List (Head.Tag Pages.PathKey) +head : StaticData -> PagePath.PagePath Pages.PathKey -> BlogIndex -> List (Head.Tag Pages.PathKey) head static currentPath metadata = Seo.summary { canonicalUrlOverride = Nothing diff --git a/examples/docs/src/Template/BlogIndexMetadata.elm b/examples/docs/src/Template/BlogIndexMetadata.elm deleted file mode 100644 index c0d433a2..00000000 --- a/examples/docs/src/Template/BlogIndexMetadata.elm +++ /dev/null @@ -1,12 +0,0 @@ -module Template.BlogIndexMetadata exposing (..) - -import Json.Decode as Decode exposing (Decoder) - - -type alias Metadata = - {} - - -decoder : Decoder Metadata -decoder = - Decode.succeed Metadata diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 658a8aac..d5de481e 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -1,4 +1,4 @@ -module Template.BlogPost exposing (Metadata, Model, Msg, decoder, head, init, liftViewMsg, staticData, template, view) +module Template.BlogPost exposing (Model, Msg, decoder, head, init, liftViewMsg, staticData, template, view) import Data.Author as Author exposing (Author) import Date exposing (Date) @@ -19,16 +19,7 @@ import Secrets import SiteConfig import StructuredData import Template - - -type alias Metadata = - { title : String - , description : String - , published : Date - , author : Author - , image : ImagePath Pages.PathKey - , draft : Bool - } +import Template.Metadata exposing (BlogPost) type Model @@ -41,7 +32,7 @@ type Msg template : List ( PagePath Pages.PathKey, globalMetadata ) - -> { metadata : Metadata, path : PagePath.PagePath Pages.PathKey } + -> { metadata : BlogPost, path : PagePath.PagePath Pages.PathKey } -> StaticHttp.Request { view : Model -> ( a, List (Element msg) ) -> { title : String, body : Element msg }, head : List (Head.Tag Pages.PathKey) } template = Template.template @@ -51,9 +42,19 @@ template = } -decoder : Decode.Decoder Metadata + +--type Template metadata model staticData renderedView templateView +-- = Template +-- { init : metadata -> model +-- , view : staticData -> model -> metadata -> renderedView -> templateView +-- } +-- +--template_ : Template { title : String, } Model StaticData + + +decoder : Decode.Decoder BlogPost decoder = - Decode.map6 Metadata + Decode.map6 BlogPost (Decode.field "title" Decode.string) (Decode.field "description" Decode.string) (Decode.field "published" @@ -98,7 +99,7 @@ findMatchingImage imageAssetPath = Pages.allImages -init : Metadata -> Model +init : BlogPost -> Model init metadata = Model @@ -118,7 +119,7 @@ liftViewMsg liftMsg = identity -view : StaticData -> Model -> Metadata -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view : StaticData -> Model -> BlogPost -> ( a, List (Element msg) ) -> { title : String, body : Element msg } view static model blogPost rendered = { title = blogPost.title , body = @@ -151,7 +152,7 @@ view static model blogPost rendered = } -head : StaticData -> PagePath.PagePath Pages.PathKey -> Metadata -> List (Head.Tag Pages.PathKey) +head : StaticData -> PagePath.PagePath Pages.PathKey -> BlogPost -> List (Head.Tag Pages.PathKey) head static currentPath meta = Head.structuredData (StructuredData.article diff --git a/examples/docs/src/Template/Metadata.elm b/examples/docs/src/Template/Metadata.elm index e69de29b..276526eb 100644 --- a/examples/docs/src/Template/Metadata.elm +++ b/examples/docs/src/Template/Metadata.elm @@ -0,0 +1,28 @@ +module Template.Metadata exposing (..) + +import Data.Author exposing (Author) +import Date exposing (Date) +import Pages +import Pages.ImagePath exposing (ImagePath) + + +type alias BlogIndex = + {} + + +type alias BlogPost = + { title : String + , description : String + , published : Date + , author : Author + , image : ImagePath Pages.PathKey + , draft : Bool + } + + +type alias Page = + { title : String } + + +type alias Showcase = + {} diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index 6d7a3af3..afc6351d 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -1,4 +1,4 @@ -module Template.Page exposing (Metadata, Model, Msg, decoder, head, init, staticData, view) +module Template.Page exposing (Model, Msg, decoder, head, init, staticData, view) import Element exposing (Element) import Element.Region @@ -9,6 +9,7 @@ import Pages exposing (images) import Pages.PagePath as PagePath import Pages.StaticHttp as StaticHttp import SiteConfig +import Template.Metadata exposing (Page) type alias StaticData = @@ -23,7 +24,7 @@ type Msg = Msg -init : Metadata -> Model +init : Page -> Model init metadata = Model @@ -33,17 +34,13 @@ staticData siteMetadata = StaticHttp.succeed () -type alias Metadata = - { title : String } - - -decoder : Decode.Decoder Metadata +decoder : Decode.Decoder Page decoder = - Decode.map Metadata + Decode.map Page (Decode.field "title" Decode.string) -head : StaticData -> PagePath.PagePath Pages.PathKey -> Metadata -> List (Head.Tag Pages.PathKey) +head : StaticData -> PagePath.PagePath Pages.PathKey -> Page -> List (Head.Tag Pages.PathKey) head static currentPath meta = Seo.summary { canonicalUrlOverride = Nothing @@ -61,7 +58,7 @@ head static currentPath meta = |> Seo.website -view : StaticData -> Model -> Metadata -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view : StaticData -> Model -> Page -> ( a, List (Element msg) ) -> { title : String, body : Element msg } view data model metadata viewForPage = { title = metadata.title , body = diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index 9bc40777..bdcd4c11 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -9,19 +9,16 @@ import Pages exposing (images) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Showcase - - -type alias Metadata = - {} +import Template.Metadata exposing (Showcase) type Msg = Msg -decoder : Decoder Metadata +decoder : Decoder Showcase decoder = - Decode.succeed Metadata + Decode.succeed Showcase staticData : a -> StaticHttp.Request StaticData @@ -33,7 +30,7 @@ type alias StaticData = List Showcase.Entry -init : Metadata -> Model +init : Showcase -> Model init metadata = Model @@ -46,7 +43,7 @@ type alias View msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) -view : StaticData -> Model -> Metadata -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view : StaticData -> Model -> Showcase -> ( a, List (Element msg) ) -> { title : String, body : Element msg } view data model metadata viewForPage = { title = "elm-pages blog" , body = @@ -56,7 +53,7 @@ view data model metadata viewForPage = } -head : StaticData -> PagePath.PagePath Pages.PathKey -> Metadata -> List (Head.Tag Pages.PathKey) +head : StaticData -> PagePath.PagePath Pages.PathKey -> Showcase -> List (Head.Tag Pages.PathKey) head static currentPath metadata = Seo.summary { canonicalUrlOverride = Nothing From 4bb89478df4f82f8d10380ebf0100c50eb087dbb Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 30 May 2020 18:51:22 -0700 Subject: [PATCH 013/106] Add template builder function. --- .../{AllMetadata.elm => GlobalMetadata.elm} | 2 +- examples/docs/src/Index.elm | 6 +- examples/docs/src/Main.elm | 4 +- examples/docs/src/MetadataNew.elm | 2 +- examples/docs/src/Template.elm | 68 +++++++++++++------ examples/docs/src/Template/BlogIndex.elm | 4 +- examples/docs/src/Template/BlogPost.elm | 54 +++++++++++---- examples/docs/src/TemplateDemultiplexer.elm | 5 +- examples/docs/src/TemplateDocument.elm | 19 ++++++ 9 files changed, 117 insertions(+), 47 deletions(-) rename examples/docs/src/{AllMetadata.elm => GlobalMetadata.elm} (86%) create mode 100644 examples/docs/src/TemplateDocument.elm diff --git a/examples/docs/src/AllMetadata.elm b/examples/docs/src/GlobalMetadata.elm similarity index 86% rename from examples/docs/src/AllMetadata.elm rename to examples/docs/src/GlobalMetadata.elm index f0832c5d..223917c1 100644 --- a/examples/docs/src/AllMetadata.elm +++ b/examples/docs/src/GlobalMetadata.elm @@ -1,4 +1,4 @@ -module AllMetadata exposing (..) +module GlobalMetadata exposing (..) import Template.Metadata diff --git a/examples/docs/src/Index.elm b/examples/docs/src/Index.elm index 1a672e3f..d47d6bea 100644 --- a/examples/docs/src/Index.elm +++ b/examples/docs/src/Index.elm @@ -2,12 +2,12 @@ module Index exposing (view) --import Pages.Metadata as Metadata exposing (Metadata) -import AllMetadata import Data.Author import Date import Element exposing (Element) import Element.Border import Element.Font +import GlobalMetadata import Pages import Pages.ImagePath as ImagePath exposing (ImagePath) import Pages.PagePath as PagePath exposing (PagePath) @@ -15,7 +15,7 @@ import Template.Metadata exposing (BlogPost) view : - List ( PagePath Pages.PathKey, AllMetadata.Metadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> Element msg view posts = Element.column [ Element.spacing 20 ] @@ -23,7 +23,7 @@ view posts = |> List.filterMap (\( path, metadata ) -> case metadata of - AllMetadata.MetadataBlogPost meta -> + GlobalMetadata.MetadataBlogPost meta -> if meta.draft then Nothing diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index fe119e59..4658f901 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -1,6 +1,5 @@ module Main exposing (main) -import AllMetadata import Color import Data.Author import Date @@ -11,6 +10,7 @@ import Element.Events import Element.Font as Font import Element.Region import FontAwesome +import GlobalMetadata import Head import Head.Seo as Seo import Html.Attributes as Attr @@ -51,7 +51,7 @@ type alias View = ( MarkdownRenderer.TableOfContents, List (Element Msg) ) -main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg AllMetadata.Metadata TemplateDemultiplexer.View +main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg GlobalMetadata.Metadata TemplateDemultiplexer.View main = TemplateDemultiplexer.mainTemplate { documents = diff --git a/examples/docs/src/MetadataNew.elm b/examples/docs/src/MetadataNew.elm index 8b5ccbcb..f0dd092f 100644 --- a/examples/docs/src/MetadataNew.elm +++ b/examples/docs/src/MetadataNew.elm @@ -1,6 +1,6 @@ module MetadataNew exposing (DocMetadata, PageMetadata, decoder) -import AllMetadata as Metadata exposing (Metadata) +import GlobalMetadata as Metadata exposing (Metadata) import Json.Decode as Decode exposing (Decoder) import Template.BlogPost import Template.Page diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 7c38412b..5bc9bc33 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -1,41 +1,65 @@ module Template exposing (..) import Head -import Pages import Pages.PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp template : { staticData : - List ( PagePath Pages.PathKey, globalMetadata ) + List ( PagePath pathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : templateStaticData -> templateModel -> templateMetadata -> renderedTemplate - -> view + -> templateView , head : templateStaticData - -> PagePath Pages.PathKey + -> PagePath pathKey -> templateMetadata - -> List (Head.Tag Pages.PathKey) + -> List (Head.Tag pathKey) + , init : templateMetadata -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateModel -> ( templateModel, Cmd templateMsg ) } - -> List ( PagePath Pages.PathKey, globalMetadata ) - -> { metadata : templateMetadata, path : PagePath Pages.PathKey } - -> - StaticHttp.Request - { view : templateModel -> renderedTemplate -> view - , head : List (Head.Tag Pages.PathKey) - } -template config siteMetadata page = - config.staticData siteMetadata - |> StaticHttp.map - (\staticData -> - { view = - \model rendered -> - config.view staticData model page.metadata rendered - , head = config.head staticData page.path page.metadata - } - ) + -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata +template config = + config + + +type alias Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata = + { staticData : + List ( PagePath pathKey, globalMetadata ) + -> StaticHttp.Request templateStaticData + , view : + templateStaticData + -> templateModel + -> templateMetadata + -> renderedTemplate + -> templateView + , head : + templateStaticData + -> PagePath pathKey + -> templateMetadata + -> List (Head.Tag pathKey) + , init : templateMetadata -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateModel -> ( templateModel, Cmd templateMsg ) + } + + + +--template : +-- { view : StaticData -> Model -> BlogPost -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +-- , head : StaticData -> PagePath Pages.PathKey -> BlogPost -> List (Head.Tag Pages.PathKey) +-- , staticData : b -> StaticHttp.Request StaticData +-- , init : BlogPost -> ( Model, Cmd Msg ) +-- , update : BlogPost -> Model -> ( Model, Cmd Msg ) +-- } +--template = +-- { view = view +-- , head = head +-- , staticData = staticData +-- , init = init +-- , update = update +-- } diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index bd3c5b08..8043df15 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -1,7 +1,7 @@ module Template.BlogIndex exposing (..) -import AllMetadata import Element exposing (Element) +import GlobalMetadata import Head import Head.Seo as Seo import Index @@ -40,7 +40,7 @@ type alias View msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) -view : List ( PagePath Pages.PathKey, AllMetadata.Metadata ) -> StaticData -> Model -> BlogIndex -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> BlogIndex -> ( a, List (Element msg) ) -> { title : String, body : Element msg } view siteMetadata data model metadata viewForPage = { title = "elm-pages blog" , body = diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index d5de481e..8b0d3613 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -20,6 +20,7 @@ import SiteConfig import StructuredData import Template import Template.Metadata exposing (BlogPost) +import TemplateDocument exposing (TemplateDocument) type Model @@ -30,19 +31,17 @@ type Msg = Msg -template : - List ( PagePath Pages.PathKey, globalMetadata ) - -> { metadata : BlogPost, path : PagePath.PagePath Pages.PathKey } - -> StaticHttp.Request { view : Model -> ( a, List (Element msg) ) -> { title : String, body : Element msg }, head : List (Head.Tag Pages.PathKey) } -template = - Template.template - { staticData = staticData - , view = view - , head = head - } - - +--template : +-- List ( PagePath Pages.PathKey, globalMetadata ) +-- -> { metadata : BlogPost, path : PagePath.PagePath Pages.PathKey } +-- -> StaticHttp.Request { view : Model -> ( a, List (Element msg) ) -> { title : String, body : Element msg }, head : List (Head.Tag Pages.PathKey) } +--template = +-- Template.template +-- { staticData = staticData +-- , view = view +-- , head = head +-- } --type Template metadata model staticData renderedView templateView -- = Template -- { init : metadata -> model @@ -50,6 +49,28 @@ template = -- } -- --template_ : Template { title : String, } Model StaticData +--template : +-- { view : StaticData -> Model -> BlogPost -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +-- , head : StaticData -> PagePath Pages.PathKey -> BlogPost -> List (Head.Tag Pages.PathKey) +-- , staticData : b -> StaticHttp.Request StaticData +-- , init : BlogPost -> ( Model, Cmd Msg ) +-- , update : BlogPost -> Model -> ( Model, Cmd Msg ) +-- } +--template : +-- List ( PagePath Pages.PathKey, globalMetadata ) +-- -> { metadata : BlogPost, path : PagePath Pages.PathKey } +-- -> StaticHttp.Request { view : Model -> ( a, List (Element msg) ) -> { title : String, body : Element msg }, head : List (Head.Tag Pages.PathKey) } + + +template : TemplateDocument BlogPost StaticData Model Msg +template = + Template.template + { view = view + , head = head + , staticData = staticData + , init = init + , update = update + } decoder : Decode.Decoder BlogPost @@ -99,9 +120,14 @@ findMatchingImage imageAssetPath = Pages.allImages -init : BlogPost -> Model +init : BlogPost -> ( Model, Cmd Msg ) init metadata = - Model + ( Model, Cmd.none ) + + +update : BlogPost -> Model -> ( Model, Cmd Msg ) +update metadata model = + ( Model, Cmd.none ) staticData : a -> StaticHttp.Request StaticData diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index 24ea80cd..2e56263e 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -1,8 +1,8 @@ module TemplateDemultiplexer exposing (..) -import AllMetadata as M exposing (Metadata) import Element exposing (Element) import Global +import GlobalMetadata as M exposing (Metadata) import Head import Html exposing (Html) import MarkdownRenderer @@ -195,7 +195,8 @@ init maybePagePath = Just meta -> case meta of M.MetadataBlogPost metadata -> - Template.BlogPost.init metadata + Template.BlogPost.template.init metadata + |> Tuple.first |> ModelBlogPost M.MetadataShowcase metadata -> diff --git a/examples/docs/src/TemplateDocument.elm b/examples/docs/src/TemplateDocument.elm new file mode 100644 index 00000000..89bc02fb --- /dev/null +++ b/examples/docs/src/TemplateDocument.elm @@ -0,0 +1,19 @@ +module TemplateDocument exposing (..) + +import Element exposing (Element) +import GlobalMetadata +import MarkdownRenderer +import Pages +import Template exposing (Template) + + +type alias View msg = + { title : String, body : Element msg } + + +type alias RenderedMarkdown msg = + ( MarkdownRenderer.TableOfContents, List (Element msg) ) + + +type alias TemplateDocument templateMetadata templateStaticData templateModel templateMsg = + Template Pages.PathKey templateMetadata (RenderedMarkdown Never) templateStaticData templateModel (View Never) templateMsg GlobalMetadata.Metadata From 923120d2f1cce0a254bd4f7da393162029bc761a Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 30 May 2020 18:56:53 -0700 Subject: [PATCH 014/106] Use exposed template value for another template. --- examples/docs/src/Template/Page.elm | 24 ++++++++++++++++++--- examples/docs/src/TemplateDemultiplexer.elm | 3 ++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index afc6351d..1bf62412 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -1,4 +1,4 @@ -module Template.Page exposing (Model, Msg, decoder, head, init, staticData, view) +module Template.Page exposing (Model, Msg, decoder, head, init, staticData, template, view) import Element exposing (Element) import Element.Region @@ -9,7 +9,9 @@ import Pages exposing (images) import Pages.PagePath as PagePath import Pages.StaticHttp as StaticHttp import SiteConfig +import Template import Template.Metadata exposing (Page) +import TemplateDocument exposing (TemplateDocument) type alias StaticData = @@ -24,9 +26,25 @@ type Msg = Msg -init : Page -> Model +template : TemplateDocument Page StaticData Model Msg +template = + Template.template + { view = view + , head = head + , staticData = staticData + , init = init + , update = update + } + + +init : Page -> ( Model, Cmd Msg ) init metadata = - Model + ( Model, Cmd.none ) + + +update : Page -> Model -> ( Model, Cmd Msg ) +update metadata model = + ( Model, Cmd.none ) staticData : a -> StaticHttp.Request StaticData diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index 2e56263e..a7ae7ae5 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -204,7 +204,8 @@ init maybePagePath = |> ModelShowcase M.MetadataPage metadata -> - Template.Page.init metadata + Template.Page.template.init metadata + |> Tuple.first |> ModelPage M.MetadataBlogIndex metadata -> From f4c7058d1446d314c7841cd13eccf114573b4d01 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 1 Jun 2020 19:57:07 -0700 Subject: [PATCH 015/106] Wire in Msgs to templates. --- examples/docs/src/Template.elm | 4 +- examples/docs/src/Template/BlogIndex.elm | 43 ++++++++++++------- examples/docs/src/Template/BlogPost.elm | 35 +--------------- examples/docs/src/Template/Page.elm | 4 +- examples/docs/src/TemplateDemultiplexer.elm | 46 +++++++++++++++++---- 5 files changed, 72 insertions(+), 60 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 5bc9bc33..6bada017 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -21,7 +21,7 @@ template : -> templateMetadata -> List (Head.Tag pathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateModel -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) } -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata template config = @@ -44,7 +44,7 @@ type alias Template pathKey templateMetadata renderedTemplate templateStaticData -> templateMetadata -> List (Head.Tag pathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateModel -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) } diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 8043df15..e476b777 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -11,13 +11,26 @@ import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Showcase import SiteConfig +import Template import Template.Metadata exposing (BlogIndex) +import TemplateDocument exposing (TemplateDocument) type Msg = Msg +template : TemplateDocument BlogIndex StaticData Model Msg +template = + Template.template + { view = view + , head = head + , staticData = staticData + , init = init + , update = update + } + + staticData : a -> StaticHttp.Request StaticData staticData siteMetadata = Showcase.staticRequest @@ -27,9 +40,14 @@ type alias StaticData = List Showcase.Entry -init : BlogIndex -> Model +init : BlogIndex -> ( Model, Cmd msg ) init metadata = - Model + ( Model, Cmd.none ) + + +update : BlogIndex -> Msg -> Model -> ( Model, Cmd Msg ) +update metadata msg model = + ( Model, Cmd.none ) type alias Model = @@ -40,28 +58,25 @@ type alias View msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) -view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> BlogIndex -> ( a, List (Element msg) ) -> { title : String, body : Element msg } -view siteMetadata data model metadata viewForPage = + +--view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> BlogIndex -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +--view siteMetadata data model metadata viewForPage = + + +view : StaticData -> Model -> BlogIndex -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view data model metadata viewForPage = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] [ Element.column [ Element.padding 20, Element.centerX ] - [ siteMetadata + [ --siteMetadata + [] |> Index.view ] ] } - ---{ title = "elm-pages blog" ---, body = --- Element.column [ Element.width Element.fill ] --- [ Element.column [ Element.padding 20, Element.centerX ] [ Showcase.view data ] --- ] ---} - - head : StaticData -> PagePath.PagePath Pages.PathKey -> BlogIndex -> List (Head.Tag Pages.PathKey) head static currentPath metadata = Seo.summary diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 8b0d3613..73db3905 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -31,37 +31,6 @@ type Msg = Msg - ---template : --- List ( PagePath Pages.PathKey, globalMetadata ) --- -> { metadata : BlogPost, path : PagePath.PagePath Pages.PathKey } --- -> StaticHttp.Request { view : Model -> ( a, List (Element msg) ) -> { title : String, body : Element msg }, head : List (Head.Tag Pages.PathKey) } ---template = --- Template.template --- { staticData = staticData --- , view = view --- , head = head --- } ---type Template metadata model staticData renderedView templateView --- = Template --- { init : metadata -> model --- , view : staticData -> model -> metadata -> renderedView -> templateView --- } --- ---template_ : Template { title : String, } Model StaticData ---template : --- { view : StaticData -> Model -> BlogPost -> ( a, List (Element msg) ) -> { title : String, body : Element msg } --- , head : StaticData -> PagePath Pages.PathKey -> BlogPost -> List (Head.Tag Pages.PathKey) --- , staticData : b -> StaticHttp.Request StaticData --- , init : BlogPost -> ( Model, Cmd Msg ) --- , update : BlogPost -> Model -> ( Model, Cmd Msg ) --- } ---template : --- List ( PagePath Pages.PathKey, globalMetadata ) --- -> { metadata : BlogPost, path : PagePath Pages.PathKey } --- -> StaticHttp.Request { view : Model -> ( a, List (Element msg) ) -> { title : String, body : Element msg }, head : List (Head.Tag Pages.PathKey) } - - template : TemplateDocument BlogPost StaticData Model Msg template = Template.template @@ -125,8 +94,8 @@ init metadata = ( Model, Cmd.none ) -update : BlogPost -> Model -> ( Model, Cmd Msg ) -update metadata model = +update : BlogPost -> Msg -> Model -> ( Model, Cmd Msg ) +update metadata msg model = ( Model, Cmd.none ) diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index 1bf62412..36d8ab9d 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -42,8 +42,8 @@ init metadata = ( Model, Cmd.none ) -update : Page -> Model -> ( Model, Cmd Msg ) -update metadata model = +update : Page -> Msg -> Model -> ( Model, Cmd Msg ) +update metadata msg model = ( Model, Cmd.none ) diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index a7ae7ae5..b47c1e93 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -1,5 +1,6 @@ module TemplateDemultiplexer exposing (..) +import Browser import Element exposing (Element) import Global import GlobalMetadata as M exposing (Metadata) @@ -32,6 +33,7 @@ type TemplateModel type Msg = MsgBlogPost Template.BlogPost.Msg + | MsgBlogIndex Template.BlogIndex.Msg | MsgGlobal Global.Msg | OnPageChange { path : PagePath Pages.PathKey @@ -42,7 +44,7 @@ type Msg type alias View = - ( MarkdownRenderer.TableOfContents, List (Element Msg) ) + ( MarkdownRenderer.TableOfContents, List (Element Never) ) view : @@ -75,7 +77,7 @@ view siteMetadata page = { title = title , body = -- Template.BlogPost.liftViewMsg - body + Element.map never body } ) @@ -104,7 +106,7 @@ view siteMetadata page = { title = title , body = -- Template.BlogPost.liftViewMsg - body + Element.map never body } ) @@ -133,7 +135,7 @@ view siteMetadata page = { title = title , body = -- Template.BlogPost.liftViewMsg - body + Element.map never body } ) @@ -152,7 +154,12 @@ view siteMetadata page = \model rendered -> case model.page of ModelBlogIndex subModel -> - Template.BlogIndex.view siteMetadata data subModel metadata rendered + --Template.BlogIndex.view siteMetadata data subModel metadata rendered + Template.BlogIndex.template.view + data + subModel + metadata + rendered |> (\{ title, body } -> Global.wrapBody globalData @@ -160,9 +167,7 @@ view siteMetadata page = model.global MsgGlobal { title = title - , body = - -- Template.BlogPost.liftViewMsg - body + , body = Element.map never body } ) @@ -209,7 +214,8 @@ init maybePagePath = |> ModelPage M.MetadataBlogIndex metadata -> - Template.BlogIndex.init metadata + Template.BlogIndex.template.init metadata + |> Tuple.first |> ModelBlogIndex } , Cmd.none @@ -240,6 +246,21 @@ update msg model = , 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 @@ -263,3 +284,10 @@ mainTemplate { documents, manifest, canonicalSiteUrl } = , 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) + } From f1aaa85b92b53ebe0e495b8d74df3cf41a4b6841 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 6 Jun 2020 16:04:25 -0700 Subject: [PATCH 016/106] Remove extra exports. --- examples/docs/src/Template/BlogPost.elm | 2 +- examples/docs/src/TemplateDemultiplexer.elm | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 73db3905..b83b02df 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -1,4 +1,4 @@ -module Template.BlogPost exposing (Model, Msg, decoder, head, init, liftViewMsg, staticData, template, view) +module Template.BlogPost exposing (Model, Msg, decoder, template) import Data.Author as Author exposing (Author) import Date exposing (Date) diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index b47c1e93..e7c42dbf 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -67,7 +67,10 @@ view siteMetadata page = \model rendered -> case model.page of ModelBlogPost subModel -> - Template.BlogPost.view data subModel metadata rendered + Template.BlogPost.template.view data + subModel + metadata + rendered |> (\{ title, body } -> Global.wrapBody globalData @@ -83,10 +86,10 @@ view siteMetadata page = _ -> { title = "", body = Html.text "" } - , head = Template.BlogPost.head data page.path metadata + , head = Template.BlogPost.template.head data page.path metadata } ) - (Template.BlogPost.staticData siteMetadata) + (Template.BlogPost.template.staticData siteMetadata) (Global.staticData siteMetadata) M.MetadataShowcase metadata -> From 033fb21f7b8980171d7f25fe7b43481adcd77e0f Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 6 Jun 2020 16:06:10 -0700 Subject: [PATCH 017/106] Remove extra exports. --- examples/docs/src/Template/BlogIndex.elm | 2 +- examples/docs/src/TemplateDemultiplexer.elm | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index e476b777..83e2ab6b 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -1,4 +1,4 @@ -module Template.BlogIndex exposing (..) +module Template.BlogIndex exposing (Model, Msg, template) import Element exposing (Element) import GlobalMetadata diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index e7c42dbf..f476ded9 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -176,10 +176,10 @@ view siteMetadata page = _ -> { title = "", body = Html.text "" } - , head = Template.BlogIndex.head data page.path metadata + , head = Template.BlogIndex.template.head data page.path metadata } ) - (Template.BlogIndex.staticData siteMetadata) + (Template.BlogIndex.template.staticData siteMetadata) (Global.staticData siteMetadata) From feeef824c7f8328236d7b39ec6fb66a3bff833f6 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 6 Jun 2020 16:07:26 -0700 Subject: [PATCH 018/106] Remove extra exports. --- examples/docs/src/Template/Page.elm | 2 +- examples/docs/src/TemplateDemultiplexer.elm | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index 36d8ab9d..fe2741d3 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -1,4 +1,4 @@ -module Template.Page exposing (Model, Msg, decoder, head, init, staticData, template, view) +module Template.Page exposing (Model, Msg, decoder, template) import Element exposing (Element) import Element.Region diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index f476ded9..9db76f64 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -128,7 +128,7 @@ view siteMetadata page = \model rendered -> case model.page of ModelPage subModel -> - Template.Page.view data subModel metadata rendered + Template.Page.template.view data subModel metadata rendered |> (\{ title, body } -> Global.wrapBody globalData @@ -144,10 +144,10 @@ view siteMetadata page = _ -> { title = "", body = Html.text "" } - , head = Template.Page.head data page.path metadata + , head = Template.Page.template.head data page.path metadata } ) - (Template.Page.staticData siteMetadata) + (Template.Page.template.staticData siteMetadata) (Global.staticData siteMetadata) M.MetadataBlogIndex metadata -> From 0e0446c3978077456ffd97ebf66f4ff25bfe6077 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 6 Jun 2020 16:10:18 -0700 Subject: [PATCH 019/106] Use template builder for Showcase template module. --- examples/docs/src/Template/Showcase.elm | 24 ++++++++++++++++++--- examples/docs/src/TemplateDemultiplexer.elm | 9 ++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index bdcd4c11..e73196ce 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -1,4 +1,4 @@ -module Template.Showcase exposing (..) +module Template.Showcase exposing (Model, Msg, decoder, template) import Element exposing (Element) import Head @@ -9,13 +9,31 @@ import Pages exposing (images) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Showcase +import Template import Template.Metadata exposing (Showcase) +import TemplateDocument exposing (TemplateDocument) type Msg = Msg +template : TemplateDocument Showcase StaticData Model Msg +template = + Template.template + { view = view + , head = head + , staticData = staticData + , init = init + , update = update + } + + +update : Showcase -> Msg -> Model -> ( Model, Cmd Msg ) +update metadata msg model = + ( Model, Cmd.none ) + + decoder : Decoder Showcase decoder = Decode.succeed Showcase @@ -30,9 +48,9 @@ type alias StaticData = List Showcase.Entry -init : Showcase -> Model +init : Showcase -> ( Model, Cmd Msg ) init metadata = - Model + ( Model, Cmd.none ) type alias Model = diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index 9db76f64..b39accb7 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -99,7 +99,7 @@ view siteMetadata page = \model rendered -> case model.page of ModelShowcase subModel -> - Template.Showcase.view data subModel metadata rendered + Template.Showcase.template.view data subModel metadata rendered |> (\{ title, body } -> Global.wrapBody globalData @@ -115,10 +115,10 @@ view siteMetadata page = _ -> { title = "", body = Html.text "" } - , head = Template.Showcase.head data page.path metadata + , head = Template.Showcase.template.head data page.path metadata } ) - (Template.Showcase.staticData siteMetadata) + (Template.Showcase.template.staticData siteMetadata) (Global.staticData siteMetadata) M.MetadataPage metadata -> @@ -208,7 +208,8 @@ init maybePagePath = |> ModelBlogPost M.MetadataShowcase metadata -> - Template.Showcase.init metadata + Template.Showcase.template.init metadata + |> Tuple.first |> ModelShowcase M.MetadataPage metadata -> From 6c06f06c1b59e7102cc8e99f885c1e66abbdfe40 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 6 Jun 2020 16:20:24 -0700 Subject: [PATCH 020/106] Add documentation page template. --- examples/docs/src/GlobalMetadata.elm | 1 + examples/docs/src/MetadataNew.elm | 15 +-- examples/docs/src/Template/Documentation.elm | 129 +++++++++++++++++++ examples/docs/src/Template/Metadata.elm | 4 + examples/docs/src/TemplateDemultiplexer.elm | 36 ++++++ 5 files changed, 174 insertions(+), 11 deletions(-) create mode 100644 examples/docs/src/Template/Documentation.elm diff --git a/examples/docs/src/GlobalMetadata.elm b/examples/docs/src/GlobalMetadata.elm index 223917c1..2e6e8dfc 100644 --- a/examples/docs/src/GlobalMetadata.elm +++ b/examples/docs/src/GlobalMetadata.elm @@ -8,3 +8,4 @@ type Metadata | MetadataShowcase Template.Metadata.Showcase | MetadataPage Template.Metadata.Page | MetadataBlogIndex Template.Metadata.BlogIndex + | MetadataDocumentation Template.Metadata.Documentation diff --git a/examples/docs/src/MetadataNew.elm b/examples/docs/src/MetadataNew.elm index f0dd092f..343bfeda 100644 --- a/examples/docs/src/MetadataNew.elm +++ b/examples/docs/src/MetadataNew.elm @@ -22,10 +22,10 @@ decoder = |> Decode.andThen (\pageType -> case pageType of - --"doc" -> - -- Decode.field "title" Decode.string - -- |> Decode.map (\title -> Doc { title = title }) - -- + "doc" -> + Decode.field "title" Decode.string + |> Decode.map (\title -> Metadata.MetadataDocumentation { title = title }) + "page" -> Template.Page.decoder |> Decode.map Metadata.MetadataPage @@ -38,13 +38,6 @@ decoder = Template.Showcase.decoder |> Decode.map Metadata.MetadataShowcase - -- - --"author" -> - -- Decode.map3 Data.Author.Author - -- (Decode.field "name" Decode.string) - -- (Decode.field "avatar" imageDecoder) - -- (Decode.field "bio" Decode.string) - -- |> Decode.map Author "blog" -> Template.BlogPost.decoder |> Decode.map Metadata.MetadataBlogPost diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm new file mode 100644 index 00000000..093fa671 --- /dev/null +++ b/examples/docs/src/Template/Documentation.elm @@ -0,0 +1,129 @@ +module Template.Documentation exposing (Model, Msg, decoder, template) + +import DocSidebar +import Element exposing (Element) +import Element.Font as Font +import Element.Region +import Head +import Head.Seo as Seo +import Json.Decode as Decode +import MarkdownRenderer +import Pages exposing (images) +import Pages.PagePath as PagePath +import Pages.StaticHttp as StaticHttp +import Palette +import SiteConfig +import Template +import Template.Metadata exposing (Documentation) +import TemplateDocument exposing (TemplateDocument) + + +type alias StaticData = + () + + +type Model + = Model + + +type Msg + = Msg + + +template : TemplateDocument Documentation StaticData Model Msg +template = + Template.template + { view = view + , head = head + , staticData = staticData + , init = init + , update = update + } + + +init : Documentation -> ( Model, Cmd Msg ) +init metadata = + ( Model, Cmd.none ) + + +update : Documentation -> Msg -> Model -> ( Model, Cmd Msg ) +update metadata msg model = + ( Model, Cmd.none ) + + +staticData : a -> StaticHttp.Request StaticData +staticData siteMetadata = + StaticHttp.succeed () + + +decoder : Decode.Decoder Documentation +decoder = + Decode.map Documentation + (Decode.field "title" Decode.string) + + +head : StaticData -> PagePath.PagePath Pages.PathKey -> Documentation -> List (Head.Tag Pages.PathKey) +head static currentPath meta = + Seo.summary + { canonicalUrlOverride = Nothing + , siteName = "elm-pages" + , image = + { url = images.iconPng + , alt = "elm-pages logo" + , dimensions = Nothing + , mimeType = Nothing + } + , description = SiteConfig.tagline + , locale = Nothing + , title = meta.title + } + |> Seo.website + + +view : StaticData -> Model -> Documentation -> ( MarkdownRenderer.TableOfContents, List (Element msg) ) -> { title : String, body : Element msg } +view data model metadata viewForPage = + { title = metadata.title + , body = + [ Element.row [] + [ DocSidebar.view + -- page.path + Pages.pages.index + [] + -- siteMetadata + |> Element.el [ Element.width (Element.fillPortion 2), Element.alignTop, Element.height Element.fill ] + , Element.column [ Element.width (Element.fillPortion 8), Element.padding 35, Element.spacing 15 ] + [ Palette.heading 1 [ Element.text metadata.title ] + , Element.column [ Element.spacing 20 ] + [ tocView (Tuple.first viewForPage) + , Element.column + [ Element.padding 50 + , Element.spacing 30 + , Element.Region.mainContent + ] + (Tuple.second viewForPage) + ] + ] + ] + ] + |> Element.textColumn + [ Element.width Element.fill + , Element.height Element.fill + ] + } + + +tocView : MarkdownRenderer.TableOfContents -> Element msg +tocView toc = + Element.column [ Element.alignTop, Element.spacing 20 ] + [ Element.el [ Font.bold, Font.size 22 ] (Element.text "Table of Contents") + , Element.column [ Element.spacing 10 ] + (toc + |> List.map + (\heading -> + Element.link [ Font.color (Element.rgb255 100 100 100) ] + { url = "#" ++ heading.anchorId + , label = Element.text heading.name + } + ) + ) + ] diff --git a/examples/docs/src/Template/Metadata.elm b/examples/docs/src/Template/Metadata.elm index 276526eb..72c9868d 100644 --- a/examples/docs/src/Template/Metadata.elm +++ b/examples/docs/src/Template/Metadata.elm @@ -26,3 +26,7 @@ type alias Page = type alias Showcase = {} + + +type alias Documentation = + { title : String } diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index b39accb7..dcfa557e 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -14,6 +14,7 @@ import Pages.StaticHttp as StaticHttp import SiteConfig import Template.BlogIndex import Template.BlogPost +import Template.Documentation import Template.Page import Template.Showcase @@ -28,6 +29,7 @@ type TemplateModel = ModelBlogPost Template.BlogPost.Model | ModelShowcase Template.Showcase.Model | ModelPage Template.Page.Model + | ModelDocumentation Template.Documentation.Model | ModelBlogIndex Template.BlogIndex.Model @@ -182,6 +184,35 @@ view siteMetadata page = (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 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 @@ -221,6 +252,11 @@ init maybePagePath = Template.BlogIndex.template.init metadata |> Tuple.first |> ModelBlogIndex + + M.MetadataDocumentation metadata -> + Template.Documentation.template.init metadata + |> Tuple.first + |> ModelDocumentation } , Cmd.none ) From 9de74530ad416a47d21f09c97d434e174e6d9437 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 22 Aug 2020 17:37:00 -0700 Subject: [PATCH 021/106] Wire in global metadata. --- examples/docs/src/Template.elm | 6 ++++-- examples/docs/src/Template/BlogIndex.elm | 8 +++----- examples/docs/src/Template/BlogPost.elm | 5 +++-- examples/docs/src/Template/Documentation.elm | 7 ++++--- examples/docs/src/Template/Page.elm | 7 ++++--- examples/docs/src/Template/Showcase.elm | 5 +++-- examples/docs/src/TemplateDemultiplexer.elm | 11 +++++++---- 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 6bada017..2186d31a 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -10,7 +10,8 @@ template : List ( PagePath pathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - templateStaticData + List ( PagePath pathKey, globalMetadata ) + -> templateStaticData -> templateModel -> templateMetadata -> renderedTemplate @@ -33,7 +34,8 @@ type alias Template pathKey templateMetadata renderedTemplate templateStaticData List ( PagePath pathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - templateStaticData + List ( PagePath pathKey, globalMetadata ) + -> templateStaticData -> templateModel -> templateMetadata -> renderedTemplate diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 83e2ab6b..22c77b3c 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -63,15 +63,13 @@ type alias View msg = --view siteMetadata data model metadata viewForPage = -view : StaticData -> Model -> BlogIndex -> ( a, List (Element msg) ) -> { title : String, body : Element msg } -view data model metadata viewForPage = +view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> BlogIndex -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view allMetadata data model metadata viewForPage = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] [ Element.column [ Element.padding 20, Element.centerX ] - [ --siteMetadata - [] - |> Index.view + [ Index.view allMetadata ] ] } diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index b83b02df..83bcc750 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -5,6 +5,7 @@ import Date exposing (Date) import Element exposing (Element) import Element.Font as Font import Element.Region +import GlobalMetadata import Head import Head.Seo as Seo import Json.Decode as Decode @@ -114,8 +115,8 @@ liftViewMsg liftMsg = identity -view : StaticData -> Model -> BlogPost -> ( a, List (Element msg) ) -> { title : String, body : Element msg } -view static model blogPost rendered = +view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> BlogPost -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view allMetadata static model blogPost rendered = { title = blogPost.title , body = Element.column [ Element.width Element.fill ] diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 093fa671..a4517e1a 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -4,12 +4,13 @@ import DocSidebar import Element exposing (Element) import Element.Font as Font import Element.Region +import GlobalMetadata import Head import Head.Seo as Seo import Json.Decode as Decode import MarkdownRenderer import Pages exposing (images) -import Pages.PagePath as PagePath +import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Palette import SiteConfig @@ -80,8 +81,8 @@ head static currentPath meta = |> Seo.website -view : StaticData -> Model -> Documentation -> ( MarkdownRenderer.TableOfContents, List (Element msg) ) -> { title : String, body : Element msg } -view data model metadata viewForPage = +view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> Documentation -> ( MarkdownRenderer.TableOfContents, List (Element msg) ) -> { title : String, body : Element msg } +view allMetadata data model metadata viewForPage = { title = metadata.title , body = [ Element.row [] diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index fe2741d3..0310040f 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -2,11 +2,12 @@ module Template.Page exposing (Model, Msg, decoder, template) import Element exposing (Element) import Element.Region +import GlobalMetadata import Head import Head.Seo as Seo import Json.Decode as Decode import Pages exposing (images) -import Pages.PagePath as PagePath +import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import SiteConfig import Template @@ -76,8 +77,8 @@ head static currentPath meta = |> Seo.website -view : StaticData -> Model -> Page -> ( a, List (Element msg) ) -> { title : String, body : Element msg } -view data model metadata viewForPage = +view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> Page -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view allMetadata data model metadata viewForPage = { title = metadata.title , body = [ Element.column diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index e73196ce..aa94d042 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -1,6 +1,7 @@ module Template.Showcase exposing (Model, Msg, decoder, template) import Element exposing (Element) +import GlobalMetadata import Head import Head.Seo as Seo import Json.Decode as Decode exposing (Decoder) @@ -61,8 +62,8 @@ type alias View msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) -view : StaticData -> Model -> Showcase -> ( a, List (Element msg) ) -> { title : String, body : Element msg } -view data model metadata viewForPage = +view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> Showcase -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view allMetadata data model metadata viewForPage = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index dcfa557e..36400f20 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -69,7 +69,9 @@ view siteMetadata page = \model rendered -> case model.page of ModelBlogPost subModel -> - Template.BlogPost.template.view data + Template.BlogPost.template.view + siteMetadata + data subModel metadata rendered @@ -101,7 +103,7 @@ view siteMetadata page = \model rendered -> case model.page of ModelShowcase subModel -> - Template.Showcase.template.view data subModel metadata rendered + Template.Showcase.template.view siteMetadata data subModel metadata rendered |> (\{ title, body } -> Global.wrapBody globalData @@ -130,7 +132,7 @@ view siteMetadata page = \model rendered -> case model.page of ModelPage subModel -> - Template.Page.template.view data subModel metadata rendered + Template.Page.template.view siteMetadata data subModel metadata rendered |> (\{ title, body } -> Global.wrapBody globalData @@ -161,6 +163,7 @@ view siteMetadata page = ModelBlogIndex subModel -> --Template.BlogIndex.view siteMetadata data subModel metadata rendered Template.BlogIndex.template.view + siteMetadata data subModel metadata @@ -191,7 +194,7 @@ view siteMetadata page = \model rendered -> case model.page of ModelDocumentation subModel -> - Template.Documentation.template.view data subModel metadata rendered + Template.Documentation.template.view siteMetadata data subModel metadata rendered |> (\{ title, body } -> Global.wrapBody globalData From 15797e52eac07e2e55ed6ea1f7cc8299e960b51e Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 22 Aug 2020 20:51:18 -0700 Subject: [PATCH 022/106] Remove unsued. --- examples/docs/src/Template/BlogPost.elm | 5 -- examples/docs/src/TemplateHardcoded.elm | 67 +++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 examples/docs/src/TemplateHardcoded.elm diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 83bcc750..e13d9c08 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -110,11 +110,6 @@ type alias StaticData = Int -liftViewMsg : (Msg -> msg) -> ( a, List (Element msg) ) -> ( a, List (Element msg) ) -liftViewMsg liftMsg = - identity - - view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> BlogPost -> ( a, List (Element msg) ) -> { title : String, body : Element msg } view allMetadata static model blogPost rendered = { title = blogPost.title diff --git a/examples/docs/src/TemplateHardcoded.elm b/examples/docs/src/TemplateHardcoded.elm new file mode 100644 index 00000000..2186d31a --- /dev/null +++ b/examples/docs/src/TemplateHardcoded.elm @@ -0,0 +1,67 @@ +module Template exposing (..) + +import Head +import Pages.PagePath exposing (PagePath) +import Pages.StaticHttp as StaticHttp + + +template : + { staticData : + List ( PagePath pathKey, globalMetadata ) + -> StaticHttp.Request templateStaticData + , view : + List ( PagePath pathKey, globalMetadata ) + -> templateStaticData + -> templateModel + -> templateMetadata + -> renderedTemplate + -> templateView + , head : + templateStaticData + -> PagePath pathKey + -> templateMetadata + -> List (Head.Tag pathKey) + , init : templateMetadata -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) + } + -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata +template config = + config + + +type alias Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata = + { staticData : + List ( PagePath pathKey, globalMetadata ) + -> StaticHttp.Request templateStaticData + , view : + List ( PagePath pathKey, globalMetadata ) + -> templateStaticData + -> templateModel + -> templateMetadata + -> renderedTemplate + -> templateView + , head : + templateStaticData + -> PagePath pathKey + -> templateMetadata + -> List (Head.Tag pathKey) + , init : templateMetadata -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) + } + + + +--template : +-- { view : StaticData -> Model -> BlogPost -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +-- , head : StaticData -> PagePath Pages.PathKey -> BlogPost -> List (Head.Tag Pages.PathKey) +-- , staticData : b -> StaticHttp.Request StaticData +-- , init : BlogPost -> ( Model, Cmd Msg ) +-- , update : BlogPost -> Model -> ( Model, Cmd Msg ) +-- } +--template = +-- { view = view +-- , head = head +-- , staticData = staticData +-- , init = init +-- , update = update +-- } From c6a3eac95b167f0b56686cb35f8963e5f373ad6b Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 22 Aug 2020 21:09:36 -0700 Subject: [PATCH 023/106] Remove unused. --- examples/docs/src/TemplateDemultiplexer.elm | 9 --------- 1 file changed, 9 deletions(-) diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index 36400f20..dc669b9f 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -310,17 +310,8 @@ mainTemplate { documents, manifest, canonicalSiteUrl } = { init = init , view = view , update = update - - --, subscriptions = subscriptions , subscriptions = \_ -> Sub.none , documents = documents - - --[ { extension = "md" - -- , metadata = Metadata.decoder - -- , body = MarkdownRenderer.view - -- } - --] - --, onPageChange = Just OnPageChange , onPageChange = Just OnPageChange , manifest = manifest -- SiteConfig.manifest , canonicalSiteUrl = canonicalSiteUrl -- SiteConfig.canonicalUrl From 493f8d363458c926e2df890f3c354a2d9f4a6cfb Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 22 Aug 2020 21:34:47 -0700 Subject: [PATCH 024/106] Add hardcoded generate file function to seed snapshot. --- .../src/generate-template-module-connector.js | 332 ++++++++++++++++++ .../generated-files.test.js.snap | 331 +++++++++++++++++ tests/generated-files.test.js | 9 + 3 files changed, 672 insertions(+) create mode 100644 generator/src/generate-template-module-connector.js diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js new file mode 100644 index 00000000..1b0111de --- /dev/null +++ b/generator/src/generate-template-module-connector.js @@ -0,0 +1,332 @@ +function generateTemplateModuleConnector(staticRoutes) { + return `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) + } +` +} + +module.exports = { generateTemplateModuleConnector } diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index 73dbe838..36de2967 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -113,3 +113,334 @@ 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) + } +" +`; diff --git a/tests/generated-files.test.js b/tests/generated-files.test.js index 7e65d1a7..7d1b19de 100644 --- a/tests/generated-files.test.js +++ b/tests/generated-files.test.js @@ -1,4 +1,5 @@ const { elmPagesCliFile, elmPagesUiFile } = require("../generator/src/elm-file-constants.js"); +const { generateTemplateModuleConnector } = require("../generator/src/generate-template-module-connector.js"); const generateRecords = require("../generator/src/generate-records.js"); test('generate UI file', async () => { @@ -8,3 +9,11 @@ test('generate UI file', async () => { global.builtAt = new Date("Sun, 17 May 2020 16:53:22 GMT"); expect(elmPagesUiFile(staticRoutes, [])).toMatchSnapshot(); }); + +test('generate template module connector', async () => { + process.chdir(__dirname); + const staticRoutes = await generateRecords(); + const generated = await generateTemplateModuleConnector(staticRoutes); + + expect(generated).toMatchSnapshot(); +}); From 3983c06006309bc43548d188d169bce6431f964c Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 22 Aug 2020 22:17:02 -0700 Subject: [PATCH 025/106] Remove some hardcoding. --- .../src/generate-template-module-connector.js | 12 +- tests/src/Template/BlogIndex.elm | 0 tests/src/Template/BlogPost.elm | 202 ++++++++++++++++++ tests/src/Template/Documentation.elm | 0 tests/src/Template/Page.elm | 1 + tests/src/Template/Showcase.elm | 1 + 6 files changed, 211 insertions(+), 5 deletions(-) create mode 100644 tests/src/Template/BlogIndex.elm create mode 100644 tests/src/Template/BlogPost.elm create mode 100644 tests/src/Template/Documentation.elm create mode 100644 tests/src/Template/Page.elm create mode 100644 tests/src/Template/Showcase.elm diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 1b0111de..0ac6de74 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -1,4 +1,10 @@ +const globby = require("globby") +const path = require("path") + + function generateTemplateModuleConnector(staticRoutes) { + const templates = globby.sync(["src/Template/*.elm"], {}).map(file => path.basename(file, '.elm')) + return `module TemplateDemultiplexer exposing (..) import Browser @@ -13,11 +19,7 @@ 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 +${templates.map(name => `import Template.${name}`).join("\n")} type alias Model = diff --git a/tests/src/Template/BlogIndex.elm b/tests/src/Template/BlogIndex.elm new file mode 100644 index 00000000..e69de29b diff --git a/tests/src/Template/BlogPost.elm b/tests/src/Template/BlogPost.elm new file mode 100644 index 00000000..e13d9c08 --- /dev/null +++ b/tests/src/Template/BlogPost.elm @@ -0,0 +1,202 @@ +module Template.BlogPost exposing (Model, Msg, decoder, template) + +import Data.Author as Author exposing (Author) +import Date exposing (Date) +import Element exposing (Element) +import Element.Font as Font +import Element.Region +import GlobalMetadata +import Head +import Head.Seo as Seo +import Json.Decode as Decode +import List.Extra +import OptimizedDecoder as D +import Pages +import Pages.ImagePath as ImagePath exposing (ImagePath) +import Pages.PagePath as PagePath exposing (PagePath) +import Pages.StaticHttp as StaticHttp +import Palette +import Secrets +import SiteConfig +import StructuredData +import Template +import Template.Metadata exposing (BlogPost) +import TemplateDocument exposing (TemplateDocument) + + +type Model + = Model + + +type Msg + = Msg + + +template : TemplateDocument BlogPost StaticData Model Msg +template = + Template.template + { view = view + , head = head + , staticData = staticData + , init = init + , update = update + } + + +decoder : Decode.Decoder BlogPost +decoder = + Decode.map6 BlogPost + (Decode.field "title" Decode.string) + (Decode.field "description" Decode.string) + (Decode.field "published" + (Decode.string + |> Decode.andThen + (\isoString -> + case Date.fromIsoString isoString of + Ok date -> + Decode.succeed date + + Err error -> + Decode.fail error + ) + ) + ) + (Decode.field "author" Author.decoder) + (Decode.field "image" imageDecoder) + (Decode.field "draft" Decode.bool + |> Decode.maybe + |> Decode.map (Maybe.withDefault False) + ) + + +imageDecoder : Decode.Decoder (ImagePath Pages.PathKey) +imageDecoder = + Decode.string + |> Decode.andThen + (\imageAssetPath -> + case findMatchingImage imageAssetPath of + Nothing -> + Decode.fail "Couldn't find image." + + Just imagePath -> + Decode.succeed imagePath + ) + + +findMatchingImage : String -> Maybe (ImagePath Pages.PathKey) +findMatchingImage imageAssetPath = + List.Extra.find + (\image -> ImagePath.toString image == imageAssetPath) + Pages.allImages + + +init : BlogPost -> ( Model, Cmd Msg ) +init metadata = + ( Model, Cmd.none ) + + +update : BlogPost -> Msg -> Model -> ( Model, Cmd Msg ) +update metadata msg model = + ( Model, Cmd.none ) + + +staticData : a -> StaticHttp.Request StaticData +staticData siteMetadata = + StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages") + (D.field "stargazers_count" D.int) + + +type alias StaticData = + Int + + +view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> BlogPost -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view allMetadata static model blogPost rendered = + { title = blogPost.title + , body = + Element.column [ Element.width Element.fill ] + [ Element.column + [ Element.padding 30 + , Element.spacing 40 + , Element.Region.mainContent + , Element.width (Element.fill |> Element.maximum 800) + , Element.centerX + ] + (Element.column [ Element.spacing 10 ] + [ Element.row [ Element.spacing 10 ] + [ Author.view [] blogPost.author + , Element.column [ Element.spacing 10, Element.width Element.fill ] + [ Element.paragraph [ Font.bold, Font.size 24 ] + [ Element.text blogPost.author.name + ] + , Element.paragraph [ Font.size 16 ] + [ Element.text blogPost.author.bio ] + ] + ] + ] + :: (publishedDateView blogPost |> Element.el [ Font.size 16, Font.color (Element.rgba255 0 0 0 0.6) ]) + :: Palette.blogHeading blogPost.title + :: articleImageView blogPost.image + :: Tuple.second rendered + ) + ] + } + + +head : StaticData -> PagePath.PagePath Pages.PathKey -> BlogPost -> List (Head.Tag Pages.PathKey) +head static currentPath meta = + Head.structuredData + (StructuredData.article + { title = meta.title + , description = meta.description + , author = StructuredData.person { name = meta.author.name } + , publisher = StructuredData.person { name = "Dillon Kearns" } + , url = SiteConfig.canonicalUrl ++ "/" ++ PagePath.toString currentPath + , imageUrl = SiteConfig.canonicalUrl ++ "/" ++ ImagePath.toString meta.image + , datePublished = Date.toIsoString meta.published + , mainEntityOfPage = + StructuredData.softwareSourceCode + { codeRepositoryUrl = "https://github.com/dillonkearns/elm-pages" + , description = "A statically typed site generator for Elm." + , author = "Dillon Kearns" + , programmingLanguage = StructuredData.elmLang + } + } + ) + :: (Seo.summaryLarge + { canonicalUrlOverride = Nothing + , siteName = "elm-pages" + , image = + { url = meta.image + , alt = meta.description + , dimensions = Nothing + , mimeType = Nothing + } + , description = meta.description + , locale = Nothing + , title = meta.title + } + |> Seo.article + { tags = [] + , section = Nothing + , publishedTime = Just (Date.toIsoString meta.published) + , modifiedTime = Nothing + , expirationTime = Nothing + } + ) + + +publishedDateView : { a | published : Date.Date } -> Element msg +publishedDateView metadata = + Element.text + (metadata.published + |> Date.format "MMMM ddd, yyyy" + ) + + +articleImageView : ImagePath Pages.PathKey -> Element msg +articleImageView articleImage = + Element.image [ Element.width Element.fill ] + { src = ImagePath.toString articleImage + , description = "Article cover photo" + } diff --git a/tests/src/Template/Documentation.elm b/tests/src/Template/Documentation.elm new file mode 100644 index 00000000..e69de29b diff --git a/tests/src/Template/Page.elm b/tests/src/Template/Page.elm new file mode 100644 index 00000000..13ffe000 --- /dev/null +++ b/tests/src/Template/Page.elm @@ -0,0 +1 @@ +module Main exposing (..) diff --git a/tests/src/Template/Showcase.elm b/tests/src/Template/Showcase.elm new file mode 100644 index 00000000..13ffe000 --- /dev/null +++ b/tests/src/Template/Showcase.elm @@ -0,0 +1 @@ +module Main exposing (..) From 8978187ca6bb19331f88024184dfaad79c5c938c Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 22 Aug 2020 22:25:58 -0700 Subject: [PATCH 026/106] Remove some more hardcoding. --- .../src/generate-template-module-connector.js | 11 +++-------- .../generated-files.test.js.snap | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 0ac6de74..2e8d28d0 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -29,23 +29,18 @@ type alias Model = type TemplateModel - = ModelBlogPost Template.BlogPost.Model - | ModelShowcase Template.Showcase.Model - | ModelPage Template.Page.Model - | ModelDocumentation Template.Documentation.Model - | ModelBlogIndex Template.BlogIndex.Model + = ${templates.map(name => `Model${name} Template.${name}.Model\n`).join(" | ")} type Msg - = MsgBlogPost Template.BlogPost.Msg - | MsgBlogIndex Template.BlogIndex.Msg - | MsgGlobal Global.Msg + = MsgGlobal Global.Msg | OnPageChange { path : PagePath Pages.PathKey , query : Maybe String , fragment : Maybe String , metadata : Metadata } + | ${templates.map(name => `Msg${name} Template.${name}.Msg\n`).join(" | ")} type alias View = diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index 36de2967..a6a7acfc 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -143,23 +143,28 @@ type alias Model = type TemplateModel - = ModelBlogPost Template.BlogPost.Model - | ModelShowcase Template.Showcase.Model - | ModelPage Template.Page.Model + = ModelBlogIndex Template.BlogIndex.Model + | ModelBlogPost Template.BlogPost.Model | ModelDocumentation Template.Documentation.Model - | ModelBlogIndex Template.BlogIndex.Model + | ModelPage Template.Page.Model + | ModelShowcase Template.Showcase.Model + type Msg - = MsgBlogPost Template.BlogPost.Msg - | MsgBlogIndex Template.BlogIndex.Msg - | MsgGlobal Global.Msg + = MsgGlobal Global.Msg | OnPageChange { path : PagePath Pages.PathKey , query : Maybe String , fragment : Maybe String , metadata : Metadata } + | MsgBlogIndex Template.BlogIndex.Msg + | MsgBlogPost Template.BlogPost.Msg + | MsgDocumentation Template.Documentation.Msg + | MsgPage Template.Page.Msg + | MsgShowcase Template.Showcase.Msg + type alias View = From 15a8881eec41cd7897386937f0f59cb8906338dc Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 22 Aug 2020 22:35:39 -0700 Subject: [PATCH 027/106] Remove more hardcoding. --- .../src/generate-template-module-connector.js | 135 +----------- .../generated-files.test.js.snap | 203 ++++++++++-------- 2 files changed, 121 insertions(+), 217 deletions(-) diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 2e8d28d0..310b4f64 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -60,14 +60,15 @@ view : } view siteMetadata page = case page.frontmatter of - M.MetadataBlogPost metadata -> + ${templates.map(name => + `M.Metadata${name} metadata -> StaticHttp.map2 (\data globalData -> { view = \model rendered -> case model.page of - ModelBlogPost subModel -> - Template.BlogPost.template.view + Model${name} subModel -> + Template.${name}.template.view siteMetadata data subModel @@ -88,131 +89,13 @@ view siteMetadata page = _ -> { title = "", body = Html.text "" } - , head = Template.BlogPost.template.head data page.path metadata + , head = Template.${name}.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) + (Template.${name}.template.staticData siteMetadata) (Global.staticData siteMetadata) +`).join("\n\n ") + } init : @@ -326,4 +209,4 @@ mapDocument document = ` } -module.exports = { generateTemplateModuleConnector } +module.exports = { generateTemplateModuleConnector } \ No newline at end of file diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index a6a7acfc..ed18b4b5 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -184,6 +184,41 @@ view : } view siteMetadata page = case page.frontmatter of + M.MetadataBlogIndex metadata -> + StaticHttp.map2 + (data globalData -> + { view = + model rendered -> + case model.page of + ModelBlogIndex subModel -> + Template.BlogIndex.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.BlogIndex.template.head data page.path metadata + } + ) + (Template.BlogIndex.template.staticData siteMetadata) + (Global.staticData siteMetadata) + + M.MetadataBlogPost metadata -> StaticHttp.map2 (data globalData -> @@ -218,6 +253,77 @@ view siteMetadata page = (Template.BlogPost.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.Documentation.template.head data page.path metadata + } + ) + (Template.Documentation.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.MetadataShowcase metadata -> StaticHttp.map2 (data globalData -> @@ -225,7 +331,12 @@ view siteMetadata page = model rendered -> case model.page of ModelShowcase subModel -> - Template.Showcase.template.view siteMetadata data subModel metadata rendered + Template.Showcase.template.view + siteMetadata + data + subModel + metadata + rendered |> ({ title, body } -> Global.wrapBody globalData @@ -247,96 +358,6 @@ view siteMetadata page = (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 : From 56028a1d41dd431f7714763358798ecaa5962f77 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 23 Aug 2020 07:21:40 -0700 Subject: [PATCH 028/106] Remove hardcoding of init function. --- .../src/generate-template-module-connector.js | 26 +++---------------- .../generated-files.test.js.snap | 26 ++++++++++++------- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 310b4f64..8adfb5e1 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -117,30 +117,12 @@ init maybePagePath = Just meta -> case meta of - M.MetadataBlogPost metadata -> - Template.BlogPost.template.init metadata + ${templates.map(name => `M.Metadata${name} metadata -> + Template.${name}.template.init metadata |> Tuple.first - |> ModelBlogPost + |> Model${name} - 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 +`).join("\n ")} } , Cmd.none ) diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index ed18b4b5..4c4a0078 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -379,30 +379,36 @@ init maybePagePath = Just meta -> case meta of + M.MetadataBlogIndex metadata -> + Template.BlogIndex.template.init metadata + |> Tuple.first + |> ModelBlogIndex + + M.MetadataBlogPost metadata -> Template.BlogPost.template.init metadata |> Tuple.first |> ModelBlogPost - M.MetadataShowcase metadata -> - Template.Showcase.template.init metadata + + M.MetadataDocumentation metadata -> + Template.Documentation.template.init metadata |> Tuple.first - |> ModelShowcase + |> ModelDocumentation + 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 + M.MetadataShowcase metadata -> + Template.Showcase.template.init metadata |> Tuple.first - |> ModelDocumentation + |> ModelShowcase + + } , Cmd.none ) From 0ce57d275077ae9c4e5cfdd14ed9dff4fe9b7d5c Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 23 Aug 2020 07:34:09 -0700 Subject: [PATCH 029/106] Use wildcard for update function for now. --- examples/docs/src/TemplateDemultiplexer.elm | 35 ++++++++++--------- .../src/generate-template-module-connector.js | 19 ++-------- .../generated-files.test.js.snap | 19 ++-------- 3 files changed, 25 insertions(+), 48 deletions(-) diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm index dc669b9f..74263716 100644 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ b/examples/docs/src/TemplateDemultiplexer.elm @@ -268,9 +268,6 @@ init maybePagePath = update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of - MsgBlogPost msg_ -> - ( model, Cmd.none ) - MsgGlobal msg_ -> let ( globalModel, globalCmd ) = @@ -289,20 +286,26 @@ update msg model = , 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, Cmd.none ) - _ -> - ( model.page, Cmd.none ) - in - ( { model | page = updatedPageModel }, pageCmd ) + + +-- TODO need to change Debug.todo with the page's metadata, but it's not wired through by the internals yet. +--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 } = diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 8adfb5e1..b40cce21 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -131,9 +131,6 @@ init maybePagePath = update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of - MsgBlogPost msg_ -> - ( model, Cmd.none ) - MsgGlobal msg_ -> let ( globalModel, globalCmd ) = @@ -152,20 +149,10 @@ update msg model = , 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) + _ -> + -- not implemented yet + ( model, Cmd.none ) - _ -> - ( model.page, Cmd.none ) - in - ( { model | page = updatedPageModel }, pageCmd ) mainTemplate { documents, manifest, canonicalSiteUrl } = diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index 4c4a0078..a83b9506 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -417,9 +417,6 @@ init maybePagePath = update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of - MsgBlogPost msg_ -> - ( model, Cmd.none ) - MsgGlobal msg_ -> let ( globalModel, globalCmd ) = @@ -438,20 +435,10 @@ update msg model = , 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) + _ -> + -- not implemented yet + ( model, Cmd.none ) - _ -> - ( model.page, Cmd.none ) - in - ( { model | page = updatedPageModel }, pageCmd ) mainTemplate { documents, manifest, canonicalSiteUrl } = From 6de2a556ebc69d143e845c8d0c7d824501b57829 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 23 Aug 2020 07:35:03 -0700 Subject: [PATCH 030/106] Remove unused argument. --- generator/src/generate-template-module-connector.js | 2 +- tests/generated-files.test.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index b40cce21..61b516e7 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -2,7 +2,7 @@ const globby = require("globby") const path = require("path") -function generateTemplateModuleConnector(staticRoutes) { +function generateTemplateModuleConnector() { const templates = globby.sync(["src/Template/*.elm"], {}).map(file => path.basename(file, '.elm')) return `module TemplateDemultiplexer exposing (..) diff --git a/tests/generated-files.test.js b/tests/generated-files.test.js index 7d1b19de..8a4cbac9 100644 --- a/tests/generated-files.test.js +++ b/tests/generated-files.test.js @@ -12,8 +12,7 @@ test('generate UI file', async () => { test('generate template module connector', async () => { process.chdir(__dirname); - const staticRoutes = await generateRecords(); - const generated = await generateTemplateModuleConnector(staticRoutes); + const generated = await generateTemplateModuleConnector(); expect(generated).toMatchSnapshot(); }); From fdc02b768277198f2a8fa07ae196970b5759b282 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 23 Aug 2020 07:35:28 -0700 Subject: [PATCH 031/106] Ignore coverage folder. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 333588be..3bb0057e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ dist/ .cache/ generator/src/Main.js elm-pages-*.tgz +coverage \ No newline at end of file From 375006e34215127f14c833fdba23cfa5c0f0977e Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 23 Aug 2020 08:00:49 -0700 Subject: [PATCH 032/106] Escape literal backslashes and wire in code generation. --- examples/docs/src/GlobalMetadata.elm | 12 +- examples/docs/src/Index.elm | 2 +- examples/docs/src/Template/BlogIndex.elm | 2 +- examples/docs/src/Template/BlogPost.elm | 2 +- examples/docs/src/Template/Documentation.elm | 2 +- examples/docs/src/Template/Page.elm | 2 +- examples/docs/src/Template/Showcase.elm | 2 +- examples/docs/src/TemplateDemultiplexer.elm | 330 ------------------ examples/docs/src/TemplateHardcoded.elm | 77 ++-- .../Metadata.elm => TemplateMetadata.elm} | 2 +- generator/src/generate-elm-stuff.js | 5 + .../src/generate-template-module-connector.js | 8 +- .../generated-files.test.js.snap | 32 +- 13 files changed, 69 insertions(+), 409 deletions(-) delete mode 100644 examples/docs/src/TemplateDemultiplexer.elm rename examples/docs/src/{Template/Metadata.elm => TemplateMetadata.elm} (92%) diff --git a/examples/docs/src/GlobalMetadata.elm b/examples/docs/src/GlobalMetadata.elm index 2e6e8dfc..312c984a 100644 --- a/examples/docs/src/GlobalMetadata.elm +++ b/examples/docs/src/GlobalMetadata.elm @@ -1,11 +1,11 @@ module GlobalMetadata exposing (..) -import Template.Metadata +import TemplateMetadata type Metadata - = MetadataBlogPost Template.Metadata.BlogPost - | MetadataShowcase Template.Metadata.Showcase - | MetadataPage Template.Metadata.Page - | MetadataBlogIndex Template.Metadata.BlogIndex - | MetadataDocumentation Template.Metadata.Documentation + = MetadataBlogPost TemplateMetadata.BlogPost + | MetadataShowcase TemplateMetadata.Showcase + | MetadataPage TemplateMetadata.Page + | MetadataBlogIndex TemplateMetadata.BlogIndex + | MetadataDocumentation TemplateMetadata.Documentation diff --git a/examples/docs/src/Index.elm b/examples/docs/src/Index.elm index d47d6bea..09ae4c7e 100644 --- a/examples/docs/src/Index.elm +++ b/examples/docs/src/Index.elm @@ -11,7 +11,7 @@ import GlobalMetadata import Pages import Pages.ImagePath as ImagePath exposing (ImagePath) import Pages.PagePath as PagePath exposing (PagePath) -import Template.Metadata exposing (BlogPost) +import TemplateMetadata exposing (BlogPost) view : diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 22c77b3c..576b847a 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -12,8 +12,8 @@ import Pages.StaticHttp as StaticHttp import Showcase import SiteConfig import Template -import Template.Metadata exposing (BlogIndex) import TemplateDocument exposing (TemplateDocument) +import TemplateMetadata exposing (BlogIndex) type Msg diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index e13d9c08..d4acf2e8 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -20,8 +20,8 @@ import Secrets import SiteConfig import StructuredData import Template -import Template.Metadata exposing (BlogPost) import TemplateDocument exposing (TemplateDocument) +import TemplateMetadata exposing (BlogPost) type Model diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index a4517e1a..dc7647ca 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -15,8 +15,8 @@ import Pages.StaticHttp as StaticHttp import Palette import SiteConfig import Template -import Template.Metadata exposing (Documentation) import TemplateDocument exposing (TemplateDocument) +import TemplateMetadata exposing (Documentation) type alias StaticData = diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index 0310040f..b17906dc 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -11,8 +11,8 @@ import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import SiteConfig import Template -import Template.Metadata exposing (Page) import TemplateDocument exposing (TemplateDocument) +import TemplateMetadata exposing (Page) type alias StaticData = diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index aa94d042..4a7dca28 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -11,8 +11,8 @@ import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Showcase import Template -import Template.Metadata exposing (Showcase) import TemplateDocument exposing (TemplateDocument) +import TemplateMetadata exposing (Showcase) type Msg diff --git a/examples/docs/src/TemplateDemultiplexer.elm b/examples/docs/src/TemplateDemultiplexer.elm deleted file mode 100644 index 74263716..00000000 --- a/examples/docs/src/TemplateDemultiplexer.elm +++ /dev/null @@ -1,330 +0,0 @@ -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 - 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 - } - - _ -> - ( model, Cmd.none ) - - - --- TODO need to change Debug.todo with the page's metadata, but it's not wired through by the internals yet. ---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) - } diff --git a/examples/docs/src/TemplateHardcoded.elm b/examples/docs/src/TemplateHardcoded.elm index 2186d31a..d7dbd347 100644 --- a/examples/docs/src/TemplateHardcoded.elm +++ b/examples/docs/src/TemplateHardcoded.elm @@ -1,67 +1,52 @@ -module Template exposing (..) +module TemplateHardcoded exposing (..) +import GlobalMetadata import Head +import Pages import Pages.PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp template : { staticData : - List ( PagePath pathKey, globalMetadata ) - -> StaticHttp.Request templateStaticData + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> StaticHttp.Request staticData , view : - List ( PagePath pathKey, globalMetadata ) - -> templateStaticData - -> templateModel - -> templateMetadata + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> staticData + -> model + -> metadata -> renderedTemplate - -> templateView + -> view , head : - templateStaticData - -> PagePath pathKey - -> templateMetadata - -> List (Head.Tag pathKey) - , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) + staticData + -> PagePath Pages.PathKey + -> metadata + -> List (Head.Tag Pages.PathKey) + , init : metadata -> ( model, Cmd templateMsg ) + , update : metadata -> templateMsg -> model -> ( model, Cmd templateMsg ) } - -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata + -> Template metadata renderedTemplate staticData model view templateMsg template config = config -type alias Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata = +type alias Template metadata renderedTemplate staticData model view templateMsg = { staticData : - List ( PagePath pathKey, globalMetadata ) - -> StaticHttp.Request templateStaticData + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> StaticHttp.Request staticData , view : - List ( PagePath pathKey, globalMetadata ) - -> templateStaticData - -> templateModel - -> templateMetadata + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> staticData + -> model + -> metadata -> renderedTemplate - -> templateView + -> view , head : - templateStaticData - -> PagePath pathKey - -> templateMetadata - -> List (Head.Tag pathKey) - , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) + staticData + -> PagePath Pages.PathKey + -> metadata + -> List (Head.Tag Pages.PathKey) + , init : metadata -> ( model, Cmd templateMsg ) + , update : metadata -> templateMsg -> model -> ( model, Cmd templateMsg ) } - - - ---template : --- { view : StaticData -> Model -> BlogPost -> ( a, List (Element msg) ) -> { title : String, body : Element msg } --- , head : StaticData -> PagePath Pages.PathKey -> BlogPost -> List (Head.Tag Pages.PathKey) --- , staticData : b -> StaticHttp.Request StaticData --- , init : BlogPost -> ( Model, Cmd Msg ) --- , update : BlogPost -> Model -> ( Model, Cmd Msg ) --- } ---template = --- { view = view --- , head = head --- , staticData = staticData --- , init = init --- , update = update --- } diff --git a/examples/docs/src/Template/Metadata.elm b/examples/docs/src/TemplateMetadata.elm similarity index 92% rename from examples/docs/src/Template/Metadata.elm rename to examples/docs/src/TemplateMetadata.elm index 72c9868d..fb595ce2 100644 --- a/examples/docs/src/Template/Metadata.elm +++ b/examples/docs/src/TemplateMetadata.elm @@ -1,4 +1,4 @@ -module Template.Metadata exposing (..) +module TemplateMetadata exposing (..) import Data.Author exposing (Author) import Date exposing (Date) diff --git a/generator/src/generate-elm-stuff.js b/generator/src/generate-elm-stuff.js index 5ce3de57..7d652572 100644 --- a/generator/src/generate-elm-stuff.js +++ b/generator/src/generate-elm-stuff.js @@ -2,6 +2,7 @@ const fs = require("fs"); const runElm = require("./compile-elm.js"); const copyModifiedElmJson = require("./rewrite-elm-json.js"); const { elmPagesCliFile, elmPagesUiFile } = require("./elm-file-constants.js"); +const { generateTemplateModuleConnector } = require("./generate-template-module-connector.js"); const path = require("path"); const { ensureDirSync, deleteIfExists } = require('./file-helpers.js') let wasEqualBefore = false @@ -22,6 +23,7 @@ module.exports = function run( const uiFileContent = elmPagesUiFile(staticRoutes, markdownContent) + const templateConnectorFile = generateTemplateModuleConnector() // TODO should just write it once, but webpack doesn't seem to pick up the changes // so this wasEqualBefore code causes it to get written twice to make sure the changes come through for HMR @@ -39,6 +41,7 @@ module.exports = function run( "./gen/Pages.elm", uiFileContent ); + fs.writeFileSync("./gen/TemplateDemultiplexer.elm", templateConnectorFile); } global.previousUiFileContent = uiFileContent @@ -49,6 +52,8 @@ module.exports = function run( elmPagesCliFile(staticRoutes, markdownContent) ); + fs.writeFileSync("./elm-stuff/elm-pages/TemplateDemultiplexer.elm", templateConnectorFile); + // write modified elm.json to elm-stuff/elm-pages/ copyModifiedElmJson(); diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 61b516e7..9d7ea9e3 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -63,9 +63,9 @@ view siteMetadata page = ${templates.map(name => `M.Metadata${name} metadata -> StaticHttp.map2 - (\data globalData -> + (\\data globalData -> { view = - \model rendered -> + \\model rendered -> case model.page of Model${name} subModel -> Template.${name}.template.view @@ -74,7 +74,7 @@ view siteMetadata page = subModel metadata rendered - |> (\{ title, body } -> + |> (\\{ title, body } -> Global.wrapBody globalData page @@ -160,7 +160,7 @@ mainTemplate { documents, manifest, canonicalSiteUrl } = { init = init , view = view , update = update - , subscriptions = \_ -> Sub.none + , subscriptions = \\_ -> Sub.none , documents = documents , onPageChange = Just OnPageChange , manifest = manifest -- SiteConfig.manifest diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index a83b9506..06f75d3a 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -186,9 +186,9 @@ view siteMetadata page = case page.frontmatter of M.MetadataBlogIndex metadata -> StaticHttp.map2 - (data globalData -> + (\\\\data globalData -> { view = - model rendered -> + \\\\model rendered -> case model.page of ModelBlogIndex subModel -> Template.BlogIndex.template.view @@ -197,7 +197,7 @@ view siteMetadata page = subModel metadata rendered - |> ({ title, body } -> + |> (\\\\{ title, body } -> Global.wrapBody globalData page @@ -221,9 +221,9 @@ view siteMetadata page = M.MetadataBlogPost metadata -> StaticHttp.map2 - (data globalData -> + (\\\\data globalData -> { view = - model rendered -> + \\\\model rendered -> case model.page of ModelBlogPost subModel -> Template.BlogPost.template.view @@ -232,7 +232,7 @@ view siteMetadata page = subModel metadata rendered - |> ({ title, body } -> + |> (\\\\{ title, body } -> Global.wrapBody globalData page @@ -256,9 +256,9 @@ view siteMetadata page = M.MetadataDocumentation metadata -> StaticHttp.map2 - (data globalData -> + (\\\\data globalData -> { view = - model rendered -> + \\\\model rendered -> case model.page of ModelDocumentation subModel -> Template.Documentation.template.view @@ -267,7 +267,7 @@ view siteMetadata page = subModel metadata rendered - |> ({ title, body } -> + |> (\\\\{ title, body } -> Global.wrapBody globalData page @@ -291,9 +291,9 @@ view siteMetadata page = M.MetadataPage metadata -> StaticHttp.map2 - (data globalData -> + (\\\\data globalData -> { view = - model rendered -> + \\\\model rendered -> case model.page of ModelPage subModel -> Template.Page.template.view @@ -302,7 +302,7 @@ view siteMetadata page = subModel metadata rendered - |> ({ title, body } -> + |> (\\\\{ title, body } -> Global.wrapBody globalData page @@ -326,9 +326,9 @@ view siteMetadata page = M.MetadataShowcase metadata -> StaticHttp.map2 - (data globalData -> + (\\\\data globalData -> { view = - model rendered -> + \\\\model rendered -> case model.page of ModelShowcase subModel -> Template.Showcase.template.view @@ -337,7 +337,7 @@ view siteMetadata page = subModel metadata rendered - |> ({ title, body } -> + |> (\\\\{ title, body } -> Global.wrapBody globalData page @@ -446,7 +446,7 @@ mainTemplate { documents, manifest, canonicalSiteUrl } = { init = init , view = view , update = update - , subscriptions = _ -> Sub.none + , subscriptions = \\\\_ -> Sub.none , documents = documents , onPageChange = Just OnPageChange , manifest = manifest -- SiteConfig.manifest From 0ac6caaf0b0627deb6c2f99cdf2ca9d6f0e78101 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 23 Aug 2020 10:39:51 -0700 Subject: [PATCH 033/106] Implement update wiring in Template Connector. --- .../src/generate-template-module-connector.js | 31 +++++- .../generated-files.test.js.snap | 98 ++++++++++++++++++- 2 files changed, 123 insertions(+), 6 deletions(-) diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 9d7ea9e3..4d31d03c 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -25,6 +25,15 @@ ${templates.map(name => `import Template.${name}`).join("\n")} type alias Model = { global : Global.Model , page : TemplateModel + , current : + Maybe + { path : + { path : PagePath Pages.PathKey + , query : Maybe String + , fragment : Maybe String + } + , metadata : Metadata + } } @@ -123,6 +132,7 @@ init maybePagePath = |> Model${name} `).join("\n ")} + , current = maybePagePath } , Cmd.none ) @@ -149,9 +159,24 @@ update msg model = , metadata = record.metadata } - _ -> - -- not implemented yet - ( model, Cmd.none ) + ${templates.map(name => ` + Msg${name} msg_ -> + let + ( updatedPageModel, pageCmd ) = + case ( model.page, model.current |> Maybe.map .metadata ) of + ( Model${name} pageModel, Just (M.Metadata${name} metadata) ) -> + Template.${name}.template.update + metadata + msg_ + pageModel + |> Tuple.mapBoth Model${name} (Cmd.map Msg${name}) + + _ -> + ( model.page, Cmd.none ) + in + ( { model | page = updatedPageModel }, pageCmd ) +` + ).join("\n ")} diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index 06f75d3a..53fb7c04 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -139,6 +139,15 @@ import Template.Showcase type alias Model = { global : Global.Model , page : TemplateModel + , current : + Maybe + { path : + { path : PagePath Pages.PathKey + , query : Maybe String + , fragment : Maybe String + } + , metadata : Metadata + } } @@ -409,6 +418,7 @@ init maybePagePath = |> ModelShowcase + , current = maybePagePath } , Cmd.none ) @@ -435,9 +445,91 @@ update msg model = , metadata = record.metadata } - _ -> - -- not implemented yet - ( model, Cmd.none ) + + MsgBlogIndex msg_ -> + let + ( updatedPageModel, pageCmd ) = + case ( model.page, model.current |> Maybe.map .metadata ) of + ( ModelBlogIndex pageModel, Just (M.MetadataBlogIndex metadata) ) -> + Template.BlogIndex.template.update + metadata + msg_ + pageModel + |> Tuple.mapBoth ModelBlogIndex (Cmd.map MsgBlogIndex) + + _ -> + ( model.page, Cmd.none ) + in + ( { model | page = updatedPageModel }, pageCmd ) + + + MsgBlogPost msg_ -> + let + ( updatedPageModel, pageCmd ) = + case ( model.page, model.current |> Maybe.map .metadata ) of + ( ModelBlogPost pageModel, Just (M.MetadataBlogPost metadata) ) -> + Template.BlogPost.template.update + metadata + msg_ + pageModel + |> Tuple.mapBoth ModelBlogPost (Cmd.map MsgBlogPost) + + _ -> + ( model.page, Cmd.none ) + in + ( { model | page = updatedPageModel }, pageCmd ) + + + MsgDocumentation msg_ -> + let + ( updatedPageModel, pageCmd ) = + case ( model.page, model.current |> Maybe.map .metadata ) of + ( ModelDocumentation pageModel, Just (M.MetadataDocumentation metadata) ) -> + Template.Documentation.template.update + metadata + msg_ + pageModel + |> Tuple.mapBoth ModelDocumentation (Cmd.map MsgDocumentation) + + _ -> + ( model.page, Cmd.none ) + in + ( { model | page = updatedPageModel }, pageCmd ) + + + MsgPage msg_ -> + let + ( updatedPageModel, pageCmd ) = + case ( model.page, model.current |> Maybe.map .metadata ) of + ( ModelPage pageModel, Just (M.MetadataPage metadata) ) -> + Template.Page.template.update + metadata + msg_ + pageModel + |> Tuple.mapBoth ModelPage (Cmd.map MsgPage) + + _ -> + ( model.page, Cmd.none ) + in + ( { model | page = updatedPageModel }, pageCmd ) + + + MsgShowcase msg_ -> + let + ( updatedPageModel, pageCmd ) = + case ( model.page, model.current |> Maybe.map .metadata ) of + ( ModelShowcase pageModel, Just (M.MetadataShowcase metadata) ) -> + Template.Showcase.template.update + metadata + msg_ + pageModel + |> Tuple.mapBoth ModelShowcase (Cmd.map MsgShowcase) + + _ -> + ( model.page, Cmd.none ) + in + ( { model | page = updatedPageModel }, pageCmd ) + From 959130aae0dc0c7f431e5ed5792b2d304559861f Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 23 Aug 2020 10:44:00 -0700 Subject: [PATCH 034/106] Pass in subscriptions explicitly to template builder, and let caller pipe through toProgram. --- examples/docs/src/Main.elm | 2 ++ generator/src/generate-template-module-connector.js | 5 ++--- tests/__snapshots__/generated-files.test.js.snap | 5 ++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 4658f901..925a7141 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -62,7 +62,9 @@ main = ] , manifest = SiteConfig.manifest , canonicalSiteUrl = SiteConfig.canonicalUrl + , subscriptions = \_ -> Sub.none } + |> Pages.Platform.toProgram diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 4d31d03c..0f74a203 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -180,19 +180,18 @@ update msg model = -mainTemplate { documents, manifest, canonicalSiteUrl } = +mainTemplate { documents, manifest, canonicalSiteUrl, subscriptions } = Pages.Platform.init { init = init , view = view , update = update - , subscriptions = \\_ -> Sub.none + , subscriptions = subscriptions , 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 diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index 53fb7c04..57a49f6f 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -533,19 +533,18 @@ update msg model = -mainTemplate { documents, manifest, canonicalSiteUrl } = +mainTemplate { documents, manifest, canonicalSiteUrl, subscriptions } = Pages.Platform.init { init = init , view = view , update = update - , subscriptions = \\\\_ -> Sub.none + , subscriptions = subscriptions , 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 From d98d94747afc7c46aab1894c88ace6decc54ea78 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 23 Aug 2020 13:15:15 -0700 Subject: [PATCH 035/106] Remove coupling to elm-ui and elm-markdown packages in generated template connector. --- examples/docs/src/Global.elm | 13 ++++++- examples/docs/src/Main.elm | 3 +- examples/docs/src/TemplateDocument.elm | 2 + .../src/generate-template-module-connector.js | 14 +------ .../generated-files.test.js.snap | 38 +++---------------- 5 files changed, 23 insertions(+), 47 deletions(-) diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index 394060a5..7dfeb5f9 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -10,6 +10,7 @@ import Element.Region import FontAwesome import Html exposing (Html) import Html.Attributes as Attr +import MarkdownRenderer import OptimizedDecoder as D import Pages exposing (pages) import Pages.Directory as Directory exposing (Directory) @@ -25,6 +26,14 @@ type alias Model = } +type alias View = + ( MarkdownRenderer.TableOfContents, List (Element Never) ) + + +type alias RenderedMarkdown msg = + ( MarkdownRenderer.TableOfContents, List (Element msg) ) + + type Msg = OnPageChange { path : PagePath Pages.PathKey @@ -64,7 +73,7 @@ wrapBody : -> { a | path : PagePath Pages.PathKey } -> Model -> (Msg -> msg) - -> { body : Element msg, title : String } + -> { body : Element Never, title : String } -> { body : Html msg, title : String } wrapBody stars page model liftMsg record = { body = @@ -85,7 +94,7 @@ wrapBody stars page model liftMsg record = else Element.column [ Element.width Element.fill ] [ header stars page.path |> Element.map liftMsg - , record.body + , record.body |> Element.map never ] ) |> Element.layout diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 925a7141..6aba877f 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -10,6 +10,7 @@ import Element.Events import Element.Font as Font import Element.Region import FontAwesome +import Global import GlobalMetadata import Head import Head.Seo as Seo @@ -51,7 +52,7 @@ type alias View = ( MarkdownRenderer.TableOfContents, List (Element Msg) ) -main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg GlobalMetadata.Metadata TemplateDemultiplexer.View +main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg GlobalMetadata.Metadata Global.View main = TemplateDemultiplexer.mainTemplate { documents = diff --git a/examples/docs/src/TemplateDocument.elm b/examples/docs/src/TemplateDocument.elm index 89bc02fb..a5392405 100644 --- a/examples/docs/src/TemplateDocument.elm +++ b/examples/docs/src/TemplateDocument.elm @@ -1,7 +1,9 @@ module TemplateDocument exposing (..) +import Browser import Element exposing (Element) import GlobalMetadata +import Html exposing (Html) import MarkdownRenderer import Pages import Template exposing (Template) diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 0f74a203..04ceaa8e 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -8,12 +8,10 @@ function generateTemplateModuleConnector() { return `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 @@ -52,10 +50,6 @@ type Msg | ${templates.map(name => `Msg${name} Template.${name}.Msg\n`).join(" | ")} -type alias View = - ( MarkdownRenderer.TableOfContents, List (Element Never) ) - - view : List ( PagePath Pages.PathKey, Metadata ) -> @@ -64,7 +58,7 @@ view : } -> StaticHttp.Request - { view : Model -> View -> { title : String, body : Html Msg } + { view : Model -> Global.View -> { title : String, body : Html Msg } , head : List (Head.Tag Pages.PathKey) } view siteMetadata page = @@ -89,11 +83,7 @@ view siteMetadata page = page model.global MsgGlobal - { title = title - , body = - -- Template.BlogPost.liftViewMsg - Element.map never body - } + { title = title, body = body } ) _ -> diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index 57a49f6f..2ef7a28f 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -118,12 +118,10 @@ 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 @@ -176,10 +174,6 @@ type Msg -type alias View = - ( MarkdownRenderer.TableOfContents, List (Element Never) ) - - view : List ( PagePath Pages.PathKey, Metadata ) -> @@ -188,7 +182,7 @@ view : } -> StaticHttp.Request - { view : Model -> View -> { title : String, body : Html Msg } + { view : Model -> Global.View -> { title : String, body : Html Msg } , head : List (Head.Tag Pages.PathKey) } view siteMetadata page = @@ -212,11 +206,7 @@ view siteMetadata page = page model.global MsgGlobal - { title = title - , body = - -- Template.BlogPost.liftViewMsg - Element.map never body - } + { title = title, body = body } ) _ -> @@ -247,11 +237,7 @@ view siteMetadata page = page model.global MsgGlobal - { title = title - , body = - -- Template.BlogPost.liftViewMsg - Element.map never body - } + { title = title, body = body } ) _ -> @@ -282,11 +268,7 @@ view siteMetadata page = page model.global MsgGlobal - { title = title - , body = - -- Template.BlogPost.liftViewMsg - Element.map never body - } + { title = title, body = body } ) _ -> @@ -317,11 +299,7 @@ view siteMetadata page = page model.global MsgGlobal - { title = title - , body = - -- Template.BlogPost.liftViewMsg - Element.map never body - } + { title = title, body = body } ) _ -> @@ -352,11 +330,7 @@ view siteMetadata page = page model.global MsgGlobal - { title = title - , body = - -- Template.BlogPost.liftViewMsg - Element.map never body - } + { title = title, body = body } ) _ -> From 534d204323451868dac19c29b027f659c1250394 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 23 Aug 2020 20:56:25 -0700 Subject: [PATCH 036/106] Wire in site metadata to docs sidebar. --- examples/docs/src/DocSidebar.elm | 5 +++-- examples/docs/src/Main.elm | 2 +- examples/docs/src/Template/Documentation.elm | 4 +--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/docs/src/DocSidebar.elm b/examples/docs/src/DocSidebar.elm index 8eb136ff..e6f3b9be 100644 --- a/examples/docs/src/DocSidebar.elm +++ b/examples/docs/src/DocSidebar.elm @@ -3,6 +3,7 @@ module DocSidebar exposing (view) import Element exposing (Element) import Element.Border as Border import Element.Font +import GlobalMetadata import Metadata exposing (Metadata) import Pages import Pages.PagePath as PagePath exposing (PagePath) @@ -11,7 +12,7 @@ import Palette view : PagePath Pages.PathKey - -> List ( PagePath Pages.PathKey, Metadata ) + -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> Element msg view currentPage posts = Element.column @@ -25,7 +26,7 @@ view currentPage posts = |> List.filterMap (\( path, metadata ) -> case metadata of - Metadata.Doc meta -> + GlobalMetadata.MetadataDocumentation meta -> Just ( currentPage == path, path, meta ) _ -> diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 6aba877f..5baf4137 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -177,7 +177,7 @@ update msg model = pageView : Int -> Model - -> List ( PagePath Pages.PathKey, Metadata ) + -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> { path : PagePath Pages.PathKey, frontmatter : Metadata } -> ( MarkdownRenderer.TableOfContents, List (Element Msg) ) -> { title : String, body : Element Msg } diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index dc7647ca..0191369e 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -87,10 +87,8 @@ view allMetadata data model metadata viewForPage = , body = [ Element.row [] [ DocSidebar.view - -- page.path Pages.pages.index - [] - -- siteMetadata + allMetadata |> Element.el [ Element.width (Element.fillPortion 2), Element.alignTop, Element.height Element.fill ] , Element.column [ Element.width (Element.fillPortion 8), Element.padding 35, Element.spacing 15 ] [ Palette.heading 1 [ Element.text metadata.title ] From c3dadba35d900c423004d5a191ba7984467f91b2 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 23 Aug 2020 21:10:31 -0700 Subject: [PATCH 037/106] Update docs. --- .../docs/content/docs/directory-structure.md | 75 ++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/examples/docs/content/docs/directory-structure.md b/examples/docs/content/docs/directory-structure.md index e19b455b..915097c4 100644 --- a/examples/docs/content/docs/directory-structure.md +++ b/examples/docs/content/docs/directory-structure.md @@ -17,6 +17,9 @@ your files (both code and content). ├── index.js ├── package.json └── src/ + └── Template/ + ├── Bio.elm # user-defined template modules + └── Catalog.elm └── Main.elm ``` @@ -74,6 +77,74 @@ markdownDocument = ``` -## Metadata +## Modules -You define how your metadata is parsed +### Templates +`src/Template/*.elm` + +A template represents a type of page. For example, a BlogPost template could live in `src/Template/BlogPost.elm`. Any files in your `content/` folder with frontmatter that you decode into type `GlobalMetadata.BlogPost` will be rendered using your `BlogPost` template. + +Think of each template as having its own mini `elm-pages architecture` lifecycle. + +Imagine you have a site called thegreatcomposers.com that lists the greatest works of Classical composers. + +Let's say you have a file called `content/catalog/sibelius.md` with these contents: + +```markdown +--- +template: catalog +composer: Sibelius +--- +## Symphony 2, Op. 47 +### Notable Recordings +Bernstein Vienna Philharmonic +``` + +You have a metadata decoder like this: + +```elm +module Metadata exposing (Metadata, decoder) + +type Metadata = Catalog Composer | Bio Composer + +type Composer = Sibelius | Mozart + +decoder = + Decode.string + |> Decode.field "template" + |> Decode.andThen (\template -> + case template of + "catalog" -> Decode.map Catalog decodeComposer + "bio" -> Decode.map Bio decodeComposer + ) +``` + +Now say you navigate to `/catalog/sibelius`. Let's look at the `elm-pages architecture` lifecycle steps that kick in. + +### Build + +* `staticData` - When you build your site (using `elm-pages build` for prod or `elm-pages develop` in dev mode), the `staticData` will be fetched for this page. Your `staticData` request has access to the page's `Metadata`. So if you wanted to request `api.composers.com/portrait-images/` to get the list of images for each composer's catalog page, you could. Behind the scenes, `elm-pages` will make sure this data is loaded for you in the browser so you have access to this data, even though the API is only hit during the initial build and then stored as a JSON asset for your site. +#### Page Load +* `init` - the page for Sibelius' catalog has its own state. Let's display a Carousel that shows photos of the composer. `init` is called when you navigate to this page. If you navigate to another composer's catalog page, like Mozart, it will call the same `init` function to get a fresh Model for the new page, passing in the metadata for the Mozart page (from the frontmatter in `content/catalog/mozart`. +* `view` given the page's state, metadata, and StaticHttp data, you can render the catalog for Sibelius. +#### Page Interaction +* `update` - if you click the Carousel, the page's state gets updated. + + +### Global +`src/Global.elm` +* `staticData` (loaded per-app, not per-page) +* `View` - the data type that pages render to in your app +* `view` - the top-level view function for your app + +### Build +`src/Build.elm` +* `staticData` (build-only) +* `manifest` +* `generateFiles` + + +### Global Metadata +`src/GlobalMetadata.elm` + +This module must define a variant for each template module. \ No newline at end of file From dc4ba8105db8205ceb6983b035d3f101c6692704 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 23 Aug 2020 21:27:51 -0700 Subject: [PATCH 038/106] Remove Debug.todo. --- generator/src/generate-template-module-connector.js | 4 +++- tests/__snapshots__/generated-files.test.js.snap | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 04ceaa8e..9718fa04 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -37,6 +37,8 @@ type alias Model = type TemplateModel = ${templates.map(name => `Model${name} Template.${name}.Model\n`).join(" | ")} + | NotFound + type Msg @@ -112,7 +114,7 @@ init maybePagePath = , page = case maybePagePath |> Maybe.map .metadata of Nothing -> - Debug.todo "" + NotFound Just meta -> case meta of diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index 2ef7a28f..ee3d6064 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -156,6 +156,8 @@ type TemplateModel | ModelPage Template.Page.Model | ModelShowcase Template.Showcase.Model + | NotFound + type Msg @@ -358,7 +360,7 @@ init maybePagePath = , page = case maybePagePath |> Maybe.map .metadata of Nothing -> - Debug.todo \\"\\" + NotFound Just meta -> case meta of From 1e3bfe373af4daf11d075267d41af98e19f04eca Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 23 Aug 2020 21:32:32 -0700 Subject: [PATCH 039/106] Remove unused code. --- examples/docs/src/Main.elm | 67 -------------------------------------- 1 file changed, 67 deletions(-) diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 5baf4137..c9657c29 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -174,73 +174,6 @@ update msg model = ( { model | showMobileMenu = not model.showMobileMenu }, Cmd.none ) -pageView : - Int - -> Model - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) - -> { path : PagePath Pages.PathKey, frontmatter : Metadata } - -> ( MarkdownRenderer.TableOfContents, List (Element Msg) ) - -> { title : String, body : Element Msg } -pageView stars model siteMetadata page viewForPage = - case page.frontmatter of - Metadata.Doc metadata -> - { title = metadata.title - , body = - [ Element.row [] - [ DocSidebar.view page.path siteMetadata - |> Element.el [ Element.width (Element.fillPortion 2), Element.alignTop, Element.height Element.fill ] - , Element.column [ Element.width (Element.fillPortion 8), Element.padding 35, Element.spacing 15 ] - [ Palette.heading 1 [ Element.text metadata.title ] - , Element.column [ Element.spacing 20 ] - [ tocView (Tuple.first viewForPage) - , Element.column - [ Element.padding 50 - , Element.spacing 30 - , Element.Region.mainContent - ] - (Tuple.second viewForPage) - ] - ] - ] - ] - |> Element.textColumn - [ Element.width Element.fill - , Element.height Element.fill - ] - } - - _ -> - Debug.todo "" - - -{-| - - - --} -head : PagePath Pages.PathKey -> Metadata -> List (Head.Tag Pages.PathKey) -head currentPath metadata = - case metadata of - Metadata.Doc meta -> - Seo.summary - { canonicalUrlOverride = Nothing - , siteName = "elm-pages" - , image = - { url = images.iconPng - , alt = "elm pages logo" - , dimensions = Nothing - , mimeType = Nothing - } - , locale = Nothing - , description = siteTagline - , title = meta.title - } - |> Seo.website - - _ -> - Debug.todo "" - - canonicalSiteUrl : String canonicalSiteUrl = "https://elm-pages.com" From 98bd2d56fc931e24d421ad1653109022122c8ce0 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 24 Aug 2020 21:14:19 -0700 Subject: [PATCH 040/106] Rename type. --- examples/docs/src/Global.elm | 2 +- examples/docs/src/TemplateDocument.elm | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index 7dfeb5f9..dd450abe 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -30,7 +30,7 @@ type alias View = ( MarkdownRenderer.TableOfContents, List (Element Never) ) -type alias RenderedMarkdown msg = +type alias RenderedBody msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) diff --git a/examples/docs/src/TemplateDocument.elm b/examples/docs/src/TemplateDocument.elm index a5392405..f62b16ea 100644 --- a/examples/docs/src/TemplateDocument.elm +++ b/examples/docs/src/TemplateDocument.elm @@ -13,9 +13,9 @@ type alias View msg = { title : String, body : Element msg } -type alias RenderedMarkdown msg = +type alias RenderedBody msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) type alias TemplateDocument templateMetadata templateStaticData templateModel templateMsg = - Template Pages.PathKey templateMetadata (RenderedMarkdown Never) templateStaticData templateModel (View Never) templateMsg GlobalMetadata.Metadata + Template Pages.PathKey templateMetadata (RenderedBody Never) templateStaticData templateModel (View Never) templateMsg GlobalMetadata.Metadata From 307f1bdf25f2b38daaac7f210ec9fa44c1cd84a5 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 24 Aug 2020 21:56:38 -0700 Subject: [PATCH 041/106] Wire in toMsg and toGlobalMsg. --- examples/docs/src/Template.elm | 13 +++++++++---- examples/docs/src/Template/BlogIndex.elm | 15 ++++++++++++--- examples/docs/src/Template/BlogPost.elm | 15 ++++++++++++--- examples/docs/src/Template/Documentation.elm | 19 ++++++++++++++----- examples/docs/src/Template/Page.elm | 17 +++++++++++++---- examples/docs/src/Template/Showcase.elm | 17 +++++++++++++---- examples/docs/src/TemplateDocument.elm | 5 +++-- .../src/generate-template-module-connector.js | 2 ++ .../generated-files.test.js.snap | 10 ++++++++++ 9 files changed, 88 insertions(+), 25 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 2186d31a..a2c2a257 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -1,5 +1,6 @@ module Template exposing (..) +import Global import Head import Pages.PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp @@ -10,7 +11,9 @@ template : List ( PagePath pathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - List ( PagePath pathKey, globalMetadata ) + (templateMsg -> msg) + -> (Global.Msg -> msg) + -> List ( PagePath pathKey, globalMetadata ) -> templateStaticData -> templateModel -> templateMetadata @@ -24,17 +27,19 @@ template : , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) } - -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata + -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata msg template config = config -type alias Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata = +type alias Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata msg = { staticData : List ( PagePath pathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - List ( PagePath pathKey, globalMetadata ) + (templateMsg -> msg) + -> (Global.Msg -> msg) + -> List ( PagePath pathKey, globalMetadata ) -> templateStaticData -> templateModel -> templateMetadata diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 576b847a..b333e15d 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -1,6 +1,7 @@ module Template.BlogIndex exposing (Model, Msg, template) import Element exposing (Element) +import Global import GlobalMetadata import Head import Head.Seo as Seo @@ -20,7 +21,7 @@ type Msg = Msg -template : TemplateDocument BlogIndex StaticData Model Msg +template : TemplateDocument BlogIndex StaticData Model Msg msg template = Template.template { view = view @@ -63,8 +64,16 @@ type alias View msg = --view siteMetadata data model metadata viewForPage = -view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> BlogIndex -> ( a, List (Element msg) ) -> { title : String, body : Element msg } -view allMetadata data model metadata viewForPage = +view : + (Msg -> msg) + -> (Global.Msg -> msg) + -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> StaticData + -> Model + -> BlogIndex + -> Global.RenderedBody Never + -> { title : String, body : Element Never } +view toMsg toGlobalMsg allMetadata static model metadata rendered = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index d4acf2e8..cc515f72 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -5,6 +5,7 @@ import Date exposing (Date) import Element exposing (Element) import Element.Font as Font import Element.Region +import Global import GlobalMetadata import Head import Head.Seo as Seo @@ -32,7 +33,7 @@ type Msg = Msg -template : TemplateDocument BlogPost StaticData Model Msg +template : TemplateDocument BlogPost StaticData Model Msg msg template = Template.template { view = view @@ -110,8 +111,16 @@ type alias StaticData = Int -view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> BlogPost -> ( a, List (Element msg) ) -> { title : String, body : Element msg } -view allMetadata static model blogPost rendered = +view : + (Msg -> msg) + -> (Global.Msg -> msg) + -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> StaticData + -> Model + -> BlogPost + -> Global.RenderedBody Never + -> { title : String, body : Element Never } +view toMsg toGlobalMsg allMetadata static model blogPost rendered = { title = blogPost.title , body = Element.column [ Element.width Element.fill ] diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 0191369e..75e1668e 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -4,6 +4,7 @@ import DocSidebar import Element exposing (Element) import Element.Font as Font import Element.Region +import Global import GlobalMetadata import Head import Head.Seo as Seo @@ -31,7 +32,7 @@ type Msg = Msg -template : TemplateDocument Documentation StaticData Model Msg +template : TemplateDocument Documentation StaticData Model Msg msg template = Template.template { view = view @@ -81,8 +82,16 @@ head static currentPath meta = |> Seo.website -view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> Documentation -> ( MarkdownRenderer.TableOfContents, List (Element msg) ) -> { title : String, body : Element msg } -view allMetadata data model metadata viewForPage = +view : + (Msg -> msg) + -> (Global.Msg -> msg) + -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> StaticData + -> Model + -> Documentation + -> Global.RenderedBody Never + -> { title : String, body : Element Never } +view toMsg toGlobalMsg allMetadata static model metadata rendered = { title = metadata.title , body = [ Element.row [] @@ -93,13 +102,13 @@ view allMetadata data model metadata viewForPage = , Element.column [ Element.width (Element.fillPortion 8), Element.padding 35, Element.spacing 15 ] [ Palette.heading 1 [ Element.text metadata.title ] , Element.column [ Element.spacing 20 ] - [ tocView (Tuple.first viewForPage) + [ tocView (Tuple.first rendered) , Element.column [ Element.padding 50 , Element.spacing 30 , Element.Region.mainContent ] - (Tuple.second viewForPage) + (Tuple.second rendered) ] ] ] diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index b17906dc..ddcad4b8 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -2,6 +2,7 @@ module Template.Page exposing (Model, Msg, decoder, template) import Element exposing (Element) import Element.Region +import Global import GlobalMetadata import Head import Head.Seo as Seo @@ -27,7 +28,7 @@ type Msg = Msg -template : TemplateDocument Page StaticData Model Msg +template : TemplateDocument Page StaticData Model Msg msg template = Template.template { view = view @@ -77,8 +78,16 @@ head static currentPath meta = |> Seo.website -view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> Page -> ( a, List (Element msg) ) -> { title : String, body : Element msg } -view allMetadata data model metadata viewForPage = +view : + (Msg -> msg) + -> (Global.Msg -> msg) + -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> StaticData + -> Model + -> Page + -> Global.RenderedBody Never + -> { title : String, body : Element Never } +view toMsg toGlobalMsg allMetadata static model metadata rendered = { title = metadata.title , body = [ Element.column @@ -86,7 +95,7 @@ view allMetadata data model metadata viewForPage = , Element.spacing 60 , Element.Region.mainContent ] - (Tuple.second viewForPage) + (Tuple.second rendered) ] |> Element.textColumn [ Element.width Element.fill diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index 4a7dca28..6e158e1d 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -1,6 +1,7 @@ module Template.Showcase exposing (Model, Msg, decoder, template) import Element exposing (Element) +import Global import GlobalMetadata import Head import Head.Seo as Seo @@ -19,7 +20,7 @@ type Msg = Msg -template : TemplateDocument Showcase StaticData Model Msg +template : TemplateDocument Showcase StaticData Model Msg msg template = Template.template { view = view @@ -62,12 +63,20 @@ type alias View msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) -view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> Showcase -> ( a, List (Element msg) ) -> { title : String, body : Element msg } -view allMetadata data model metadata viewForPage = +view : + (Msg -> msg) + -> (Global.Msg -> msg) + -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> StaticData + -> Model + -> Showcase + -> Global.RenderedBody Never + -> { title : String, body : Element Never } +view toMsg toGlobalMsg allMetadata static model metadata rendered = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] - [ Element.column [ Element.padding 20, Element.centerX ] [ Showcase.view data ] + [ Element.column [ Element.padding 20, Element.centerX ] [ Showcase.view static ] ] } diff --git a/examples/docs/src/TemplateDocument.elm b/examples/docs/src/TemplateDocument.elm index f62b16ea..b8486aa5 100644 --- a/examples/docs/src/TemplateDocument.elm +++ b/examples/docs/src/TemplateDocument.elm @@ -2,6 +2,7 @@ module TemplateDocument exposing (..) import Browser import Element exposing (Element) +import Global import GlobalMetadata import Html exposing (Html) import MarkdownRenderer @@ -17,5 +18,5 @@ type alias RenderedBody msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) -type alias TemplateDocument templateMetadata templateStaticData templateModel templateMsg = - Template Pages.PathKey templateMetadata (RenderedBody Never) templateStaticData templateModel (View Never) templateMsg GlobalMetadata.Metadata +type alias TemplateDocument templateMetadata templateStaticData templateModel templateMsg internalMsg = + Template Pages.PathKey templateMetadata (RenderedBody Never) templateStaticData templateModel (View Never) templateMsg GlobalMetadata.Metadata internalMsg diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 9718fa04..add51491 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -74,6 +74,8 @@ view siteMetadata page = case model.page of Model${name} subModel -> Template.${name}.template.view + Msg${name} + MsgGlobal siteMetadata data subModel diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index ee3d6064..ead73ea2 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -197,6 +197,8 @@ view siteMetadata page = case model.page of ModelBlogIndex subModel -> Template.BlogIndex.template.view + MsgBlogIndex + MsgGlobal siteMetadata data subModel @@ -228,6 +230,8 @@ view siteMetadata page = case model.page of ModelBlogPost subModel -> Template.BlogPost.template.view + MsgBlogPost + MsgGlobal siteMetadata data subModel @@ -259,6 +263,8 @@ view siteMetadata page = case model.page of ModelDocumentation subModel -> Template.Documentation.template.view + MsgDocumentation + MsgGlobal siteMetadata data subModel @@ -290,6 +296,8 @@ view siteMetadata page = case model.page of ModelPage subModel -> Template.Page.template.view + MsgPage + MsgGlobal siteMetadata data subModel @@ -321,6 +329,8 @@ view siteMetadata page = case model.page of ModelShowcase subModel -> Template.Showcase.template.view + MsgShowcase + MsgGlobal siteMetadata data subModel From 50ba51864e3b12550d0555ec59a16636192a4179 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 26 Aug 2020 20:07:50 -0700 Subject: [PATCH 042/106] Use type alias and rename variable. --- examples/docs/src/Global.elm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index dd450abe..d3ce5640 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -34,6 +34,10 @@ type alias RenderedBody msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) +type alias PageView msg = + { title : String, body : Element msg } + + type Msg = OnPageChange { path : PagePath Pages.PathKey @@ -73,9 +77,9 @@ wrapBody : -> { a | path : PagePath Pages.PathKey } -> Model -> (Msg -> msg) - -> { body : Element Never, title : String } + -> PageView Never -> { body : Html msg, title : String } -wrapBody stars page model liftMsg record = +wrapBody stars page model liftMsg pageView = { body = (if model.showMobileMenu then Element.column @@ -94,7 +98,7 @@ wrapBody stars page model liftMsg record = else Element.column [ Element.width Element.fill ] [ header stars page.path |> Element.map liftMsg - , record.body |> Element.map never + , pageView.body |> Element.map never ] ) |> Element.layout @@ -105,7 +109,7 @@ wrapBody stars page model liftMsg record = ] --|> Html.map liftMsg - , title = record.title + , title = pageView.title } From 0308587581d2b60dea6bc385d29fb2314d2860c3 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 26 Aug 2020 20:31:49 -0700 Subject: [PATCH 043/106] Make a simpler constructor function. --- examples/docs/src/Template.elm | 29 +++++++++++++++++++++++++ examples/docs/src/Template/BlogPost.elm | 24 +++++--------------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index a2c2a257..1c75d03a 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -6,6 +6,35 @@ import Pages.PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp +simpler : + { view : + (templateMsg -> msg) + -> (Global.Msg -> msg) + -> List ( PagePath pathKey, globalMetadata ) + -> templateModel + -> templateMetadata + -> renderedTemplate + -> templateView + , head : + PagePath pathKey + -> templateMetadata + -> List (Head.Tag pathKey) + , init : templateMetadata -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) + } + -> Template pathKey templateMetadata renderedTemplate () templateModel templateView templateMsg globalMetadata msg +simpler config = + template + { view = + \toMsg toGlobalMsg allMetadata static model blogPost rendered -> + config.view toMsg toGlobalMsg allMetadata model blogPost rendered + , head = \() -> config.head + , staticData = \_ -> StaticHttp.succeed () + , init = config.init + , update = config.update + } + + template : { staticData : List ( PagePath pathKey, globalMetadata ) diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index cc515f72..50e49894 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -11,13 +11,11 @@ import Head import Head.Seo as Seo import Json.Decode as Decode import List.Extra -import OptimizedDecoder as D import Pages import Pages.ImagePath as ImagePath exposing (ImagePath) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Palette -import Secrets import SiteConfig import StructuredData import Template @@ -33,12 +31,11 @@ type Msg = Msg -template : TemplateDocument BlogPost StaticData Model Msg msg +template : TemplateDocument BlogPost () Model Msg msg template = - Template.template + Template.simpler { view = view , head = head - , staticData = staticData , init = init , update = update } @@ -101,26 +98,15 @@ update metadata msg model = ( Model, Cmd.none ) -staticData : a -> StaticHttp.Request StaticData -staticData siteMetadata = - StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages") - (D.field "stargazers_count" D.int) - - -type alias StaticData = - Int - - view : (Msg -> msg) -> (Global.Msg -> msg) -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) - -> StaticData -> Model -> BlogPost -> Global.RenderedBody Never -> { title : String, body : Element Never } -view toMsg toGlobalMsg allMetadata static model blogPost rendered = +view toMsg toGlobalMsg allMetadata model blogPost rendered = { title = blogPost.title , body = Element.column [ Element.width Element.fill ] @@ -152,8 +138,8 @@ view toMsg toGlobalMsg allMetadata static model blogPost rendered = } -head : StaticData -> PagePath.PagePath Pages.PathKey -> BlogPost -> List (Head.Tag Pages.PathKey) -head static currentPath meta = +head : PagePath.PagePath Pages.PathKey -> BlogPost -> List (Head.Tag Pages.PathKey) +head currentPath meta = Head.structuredData (StructuredData.article { title = meta.title From e2c5919466e802a1ad76f62f7adc809fbef1687e Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 26 Aug 2020 21:14:52 -0700 Subject: [PATCH 044/106] Introduce new template constructor. --- examples/docs/src/Template.elm | 60 ++++++++++++++++++++++++- examples/docs/src/Template/BlogPost.elm | 1 - examples/docs/src/Template/Page.elm | 20 ++++----- examples/docs/src/Template/Showcase.elm | 30 +++---------- 4 files changed, 73 insertions(+), 38 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 1c75d03a..a9ea8880 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -6,6 +6,33 @@ import Pages.PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp +simplest : + { view : + (templateMsg -> msg) + -> (Global.Msg -> msg) + -> List ( PagePath pathKey, globalMetadata ) + -> () + -> templateMetadata + -> renderedTemplate + -> templateView + , head : + PagePath pathKey + -> templateMetadata + -> List (Head.Tag pathKey) + } + -> Template pathKey templateMetadata renderedTemplate () () templateView templateMsg globalMetadata msg +simplest config = + template + { view = + \toMsg toGlobalMsg allMetadata () model blogPost rendered -> + config.view toMsg toGlobalMsg allMetadata model blogPost rendered + , head = \() -> config.head + , staticData = \_ -> StaticHttp.succeed () + , init = \_ -> ( (), Cmd.none ) + , update = \_ _ _ -> ( (), Cmd.none ) + } + + simpler : { view : (templateMsg -> msg) @@ -26,7 +53,7 @@ simpler : simpler config = template { view = - \toMsg toGlobalMsg allMetadata static model blogPost rendered -> + \toMsg toGlobalMsg allMetadata () model blogPost rendered -> config.view toMsg toGlobalMsg allMetadata model blogPost rendered , head = \() -> config.head , staticData = \_ -> StaticHttp.succeed () @@ -35,6 +62,37 @@ simpler config = } +stateless : + { staticData : + List ( PagePath pathKey, globalMetadata ) + -> StaticHttp.Request templateStaticData + , view : + (templateMsg -> msg) + -> (Global.Msg -> msg) + -> List ( PagePath pathKey, globalMetadata ) + -> templateStaticData + -> templateMetadata + -> renderedTemplate + -> templateView + , head : + templateStaticData + -> PagePath pathKey + -> templateMetadata + -> List (Head.Tag pathKey) + } + -> Template pathKey templateMetadata renderedTemplate templateStaticData () templateView templateMsg globalMetadata msg +stateless config = + template + { view = + \toMsg toGlobalMsg allMetadata staticData () blogPost rendered -> + config.view toMsg toGlobalMsg allMetadata staticData blogPost rendered + , head = config.head + , staticData = config.staticData + , init = \_ -> ( (), Cmd.none ) + , update = \_ _ _ -> ( (), Cmd.none ) + } + + template : { staticData : List ( PagePath pathKey, globalMetadata ) diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 50e49894..93364b9d 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -14,7 +14,6 @@ import List.Extra import Pages import Pages.ImagePath as ImagePath exposing (ImagePath) import Pages.PagePath as PagePath exposing (PagePath) -import Pages.StaticHttp as StaticHttp import Palette import SiteConfig import StructuredData diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index ddcad4b8..d2d09cbe 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -20,8 +20,8 @@ type alias StaticData = () -type Model - = Model +type alias Model = + () type Msg @@ -30,23 +30,20 @@ type Msg template : TemplateDocument Page StaticData Model Msg msg template = - Template.template + Template.simplest { view = view , head = head - , staticData = staticData - , init = init - , update = update } init : Page -> ( Model, Cmd Msg ) init metadata = - ( Model, Cmd.none ) + ( (), Cmd.none ) update : Page -> Msg -> Model -> ( Model, Cmd Msg ) update metadata msg model = - ( Model, Cmd.none ) + ( (), Cmd.none ) staticData : a -> StaticHttp.Request StaticData @@ -60,8 +57,8 @@ decoder = (Decode.field "title" Decode.string) -head : StaticData -> PagePath.PagePath Pages.PathKey -> Page -> List (Head.Tag Pages.PathKey) -head static currentPath meta = +head : PagePath.PagePath Pages.PathKey -> Page -> List (Head.Tag Pages.PathKey) +head currentPath meta = Seo.summary { canonicalUrlOverride = Nothing , siteName = "elm-pages" @@ -82,12 +79,11 @@ view : (Msg -> msg) -> (Global.Msg -> msg) -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) - -> StaticData -> Model -> Page -> Global.RenderedBody Never -> { title : String, body : Element Never } -view toMsg toGlobalMsg allMetadata static model metadata rendered = +view toMsg toGlobalMsg allMetadata model metadata rendered = { title = metadata.title , body = [ Element.column diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index 6e158e1d..bcc491a4 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -6,7 +6,6 @@ import GlobalMetadata import Head import Head.Seo as Seo import Json.Decode as Decode exposing (Decoder) -import MarkdownRenderer import Pages exposing (images) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp @@ -16,26 +15,23 @@ import TemplateDocument exposing (TemplateDocument) import TemplateMetadata exposing (Showcase) +type alias Model = + () + + type Msg = Msg template : TemplateDocument Showcase StaticData Model Msg msg template = - Template.template + Template.stateless { view = view , head = head , staticData = staticData - , init = init - , update = update } -update : Showcase -> Msg -> Model -> ( Model, Cmd Msg ) -update metadata msg model = - ( Model, Cmd.none ) - - decoder : Decoder Showcase decoder = Decode.succeed Showcase @@ -50,29 +46,15 @@ type alias StaticData = List Showcase.Entry -init : Showcase -> ( Model, Cmd Msg ) -init metadata = - ( Model, Cmd.none ) - - -type alias Model = - {} - - -type alias View msg = - ( MarkdownRenderer.TableOfContents, List (Element msg) ) - - view : (Msg -> msg) -> (Global.Msg -> msg) -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData - -> Model -> Showcase -> Global.RenderedBody Never -> { title : String, body : Element Never } -view toMsg toGlobalMsg allMetadata static model metadata rendered = +view toMsg toGlobalMsg allMetadata static metadata rendered = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] From 7a6e9b77f20a7654f15df0a114d00a9ba12a1151 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 26 Aug 2020 22:05:12 -0700 Subject: [PATCH 045/106] Rename function. --- examples/docs/src/Global.elm | 4 ++-- generator/src/generate-template-module-connector.js | 2 +- tests/__snapshots__/generated-files.test.js.snap | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index d3ce5640..a188fd19 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -72,14 +72,14 @@ staticData siteMetadata = (D.field "stargazers_count" D.int) -wrapBody : +view : StaticData -> { a | path : PagePath Pages.PathKey } -> Model -> (Msg -> msg) -> PageView Never -> { body : Html msg, title : String } -wrapBody stars page model liftMsg pageView = +view stars page model liftMsg pageView = { body = (if model.showMobileMenu then Element.column diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index add51491..a33580d6 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -82,7 +82,7 @@ view siteMetadata page = metadata rendered |> (\\{ title, body } -> - Global.wrapBody + Global.view globalData page model.global diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index ead73ea2..808836e7 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -205,7 +205,7 @@ view siteMetadata page = metadata rendered |> (\\\\{ title, body } -> - Global.wrapBody + Global.view globalData page model.global @@ -238,7 +238,7 @@ view siteMetadata page = metadata rendered |> (\\\\{ title, body } -> - Global.wrapBody + Global.view globalData page model.global @@ -271,7 +271,7 @@ view siteMetadata page = metadata rendered |> (\\\\{ title, body } -> - Global.wrapBody + Global.view globalData page model.global @@ -304,7 +304,7 @@ view siteMetadata page = metadata rendered |> (\\\\{ title, body } -> - Global.wrapBody + Global.view globalData page model.global @@ -337,7 +337,7 @@ view siteMetadata page = metadata rendered |> (\\\\{ title, body } -> - Global.wrapBody + Global.view globalData page model.global From 94f018e2ae85646f35774e282ecdec8d307c2b99 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Tue, 1 Sep 2020 17:11:54 -0700 Subject: [PATCH 046/106] Add save and load functions. --- examples/docs/src/Template.elm | 10 ++++++++++ examples/docs/src/Template/BlogIndex.elm | 12 ++++++++++++ examples/docs/src/Template/Documentation.elm | 12 ++++++++++++ 3 files changed, 34 insertions(+) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index a9ea8880..c62930bb 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -30,6 +30,8 @@ simplest config = , staticData = \_ -> StaticHttp.succeed () , init = \_ -> ( (), Cmd.none ) , update = \_ _ _ -> ( (), Cmd.none ) + , save = \_ globalModel -> globalModel + , load = \_ model -> ( model, Cmd.none ) } @@ -59,6 +61,8 @@ simpler config = , staticData = \_ -> StaticHttp.succeed () , init = config.init , update = config.update + , save = \_ globalModel -> globalModel + , load = \_ model -> ( model, Cmd.none ) } @@ -90,6 +94,8 @@ stateless config = , staticData = config.staticData , init = \_ -> ( (), Cmd.none ) , update = \_ _ _ -> ( (), Cmd.none ) + , save = \_ globalModel -> globalModel + , load = \_ model -> ( model, Cmd.none ) } @@ -113,6 +119,8 @@ template : -> List (Head.Tag pathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) + , save : templateModel -> Global.Model -> Global.Model + , load : Global.Model -> templateModel -> ( templateModel, Cmd templateMsg ) } -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata msg template config = @@ -139,6 +147,8 @@ type alias Template pathKey templateMetadata renderedTemplate templateStaticData -> List (Head.Tag pathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) + , save : templateModel -> Global.Model -> Global.Model + , load : Global.Model -> templateModel -> ( templateModel, Cmd templateMsg ) } diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index b333e15d..50fed074 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -29,9 +29,21 @@ template = , staticData = staticData , init = init , update = update + , load = load + , save = save } +load : Global.Model -> Model -> ( Model, Cmd Msg ) +load globalModel model = + ( model, Cmd.none ) + + +save : Model -> Global.Model -> Global.Model +save model globalModel = + globalModel + + staticData : a -> StaticHttp.Request StaticData staticData siteMetadata = Showcase.staticRequest diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 75e1668e..26d0f08d 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -40,9 +40,21 @@ template = , staticData = staticData , init = init , update = update + , load = load + , save = save } +load : Global.Model -> Model -> ( Model, Cmd Msg ) +load globalModel model = + ( model, Cmd.none ) + + +save : Model -> Global.Model -> Global.Model +save model globalModel = + globalModel + + init : Documentation -> ( Model, Cmd Msg ) init metadata = ( Model, Cmd.none ) From 3a0196b69db0a31e12d7dc6e9fc767d5fc145190 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Tue, 1 Sep 2020 17:39:05 -0700 Subject: [PATCH 047/106] Use save function on template model updates. --- .../src/generate-template-module-connector.js | 15 +++++++- .../generated-files.test.js.snap | 34 ++++++++++++++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index a33580d6..7195dcad 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -168,12 +168,25 @@ update msg model = _ -> ( model.page, Cmd.none ) in - ( { model | page = updatedPageModel }, pageCmd ) + ( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd ) ` ).join("\n ")} +save : TemplateModel -> Global.Model -> Global.Model +save model globalModel= + case model of + ${templates.map(name => `Model${name} m -> + Template.${name}.template.save m globalModel +` + ).join("\n ")} + + NotFound -> + globalModel + + + mainTemplate { documents, manifest, canonicalSiteUrl, subscriptions } = Pages.Platform.init { init = init diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index 808836e7..e851b40d 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -446,7 +446,7 @@ update msg model = _ -> ( model.page, Cmd.none ) in - ( { model | page = updatedPageModel }, pageCmd ) + ( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd ) MsgBlogPost msg_ -> @@ -463,7 +463,7 @@ update msg model = _ -> ( model.page, Cmd.none ) in - ( { model | page = updatedPageModel }, pageCmd ) + ( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd ) MsgDocumentation msg_ -> @@ -480,7 +480,7 @@ update msg model = _ -> ( model.page, Cmd.none ) in - ( { model | page = updatedPageModel }, pageCmd ) + ( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd ) MsgPage msg_ -> @@ -497,7 +497,7 @@ update msg model = _ -> ( model.page, Cmd.none ) in - ( { model | page = updatedPageModel }, pageCmd ) + ( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd ) MsgShowcase msg_ -> @@ -514,11 +514,35 @@ update msg model = _ -> ( model.page, Cmd.none ) in - ( { model | page = updatedPageModel }, pageCmd ) + ( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd ) +save : TemplateModel -> Global.Model -> Global.Model +save model globalModel= + case model of + ModelBlogIndex m -> + Template.BlogIndex.template.save m globalModel + + ModelBlogPost m -> + Template.BlogPost.template.save m globalModel + + ModelDocumentation m -> + Template.Documentation.template.save m globalModel + + ModelPage m -> + Template.Page.template.save m globalModel + + ModelShowcase m -> + Template.Showcase.template.save m globalModel + + + NotFound -> + globalModel + + + mainTemplate { documents, manifest, canonicalSiteUrl, subscriptions } = Pages.Platform.init { init = init From 40b86aba833eae34fc40db8a86b35c90c905ac43 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Tue, 1 Sep 2020 17:44:00 -0700 Subject: [PATCH 048/106] Rename function. --- examples/docs/src/Global.elm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index a188fd19..3a4ed0fa 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -79,7 +79,7 @@ view : -> (Msg -> msg) -> PageView Never -> { body : Html msg, title : String } -view stars page model liftMsg pageView = +view stars page model toMsg pageView = { body = (if model.showMobileMenu then Element.column @@ -87,9 +87,9 @@ view stars page model liftMsg pageView = , Element.padding 20 ] [ Element.row [ Element.width Element.fill, Element.spaceEvenly ] - [ logoLinkMobile |> Element.map liftMsg + [ logoLinkMobile |> Element.map toMsg , FontAwesome.styledIcon "fas fa-bars" [ Element.Events.onClick ToggleMobileMenu ] - |> Element.map liftMsg + |> Element.map toMsg ] , Element.column [ Element.centerX, Element.spacing 20 ] (navbarLinks stars page.path) @@ -97,7 +97,7 @@ view stars page model liftMsg pageView = else Element.column [ Element.width Element.fill ] - [ header stars page.path |> Element.map liftMsg + [ header stars page.path |> Element.map toMsg , pageView.body |> Element.map never ] ) From bddcd0214157fe51a684ad2983a2efbf625b2b40 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Tue, 1 Sep 2020 17:50:40 -0700 Subject: [PATCH 049/106] Add example of global state. --- examples/docs/src/Global.elm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index 3a4ed0fa..f9b5fd5f 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -23,6 +23,7 @@ import Secrets type alias Model = { showMobileMenu : Bool + , counter : Int } @@ -45,10 +46,13 @@ type Msg , fragment : Maybe String } | ToggleMobileMenu + | Increment +init : a -> Model init maybePagePath = { showMobileMenu = False + , counter = 0 } @@ -61,6 +65,9 @@ update msg model = ToggleMobileMenu -> ( { model | showMobileMenu = not model.showMobileMenu }, Cmd.none ) + Increment -> + ( { model | counter = model.counter + 1 }, Cmd.none ) + type alias StaticData = Int @@ -98,6 +105,7 @@ view stars page model toMsg pageView = else Element.column [ Element.width Element.fill ] [ header stars page.path |> Element.map toMsg + , incrementView model |> Element.map toMsg , pageView.body |> Element.map never ] ) @@ -107,12 +115,15 @@ view stars page model toMsg pageView = , Font.family [ Font.typeface "Roboto" ] , Font.color (Element.rgba255 0 0 0 0.8) ] - - --|> Html.map liftMsg , title = pageView.title } +incrementView : Model -> Element Msg +incrementView model = + Element.el [ Element.Events.onClick Increment ] (Element.text <| String.fromInt model.counter) + + logoLinkMobile = Element.link [] { url = "/" From 9e8659b30569b2d4eaf54ea66c4ddd067416c262 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Tue, 1 Sep 2020 22:38:57 -0700 Subject: [PATCH 050/106] Remove toMsg and toGlobalMsg and change msg type for rendered document. --- examples/docs/src/Global.elm | 23 +++++++--- examples/docs/src/Main.elm | 6 +-- examples/docs/src/Template.elm | 42 +++++++------------ examples/docs/src/Template/BlogIndex.elm | 12 +++--- examples/docs/src/Template/BlogPost.elm | 13 +++--- examples/docs/src/Template/Documentation.elm | 22 ++++++---- examples/docs/src/Template/Page.elm | 14 +++---- examples/docs/src/Template/Showcase.elm | 12 +++--- examples/docs/src/TemplateDocument.elm | 4 +- .../src/generate-template-module-connector.js | 8 ++-- 10 files changed, 76 insertions(+), 80 deletions(-) diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index f9b5fd5f..b1cf2bb6 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -27,14 +27,27 @@ type alias Model = } -type alias View = - ( MarkdownRenderer.TableOfContents, List (Element Never) ) +map : (msg1 -> msg2) -> PageView msg1 -> PageView msg2 +map fn doc = + { title = doc.title + , body = Element.map fn doc.body + } -type alias RenderedBody msg = + +--mapRendered : (msg1 -> msg2) -> RenderedBody msg1 -> RenderedBody msg2 +--mapRendered fn ( first, second ) = +-- ( first, second |> List.map (Element.map fn) ) + + +type alias View msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) +type alias RenderedBody = + ( MarkdownRenderer.TableOfContents, List (Element Never) ) + + type alias PageView msg = { title : String, body : Element msg } @@ -84,7 +97,7 @@ view : -> { a | path : PagePath Pages.PathKey } -> Model -> (Msg -> msg) - -> PageView Never + -> PageView msg -> { body : Html msg, title : String } view stars page model toMsg pageView = { body = @@ -106,7 +119,7 @@ view stars page model toMsg pageView = Element.column [ Element.width Element.fill ] [ header stars page.path |> Element.map toMsg , incrementView model |> Element.map toMsg - , pageView.body |> Element.map never + , pageView.body ] ) |> Element.layout diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index c9657c29..6d8b3d78 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -48,11 +48,7 @@ manifest = } -type alias View = - ( MarkdownRenderer.TableOfContents, List (Element Msg) ) - - -main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg GlobalMetadata.Metadata Global.View +main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg GlobalMetadata.Metadata Global.RenderedBody main = TemplateDemultiplexer.mainTemplate { documents = diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index c62930bb..51391a62 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -8,9 +8,7 @@ import Pages.StaticHttp as StaticHttp simplest : { view : - (templateMsg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath pathKey, globalMetadata ) + List ( PagePath pathKey, globalMetadata ) -> () -> templateMetadata -> renderedTemplate @@ -20,12 +18,12 @@ simplest : -> templateMetadata -> List (Head.Tag pathKey) } - -> Template pathKey templateMetadata renderedTemplate () () templateView templateMsg globalMetadata msg + -> Template pathKey templateMetadata renderedTemplate () () templateView templateMsg globalMetadata simplest config = template { view = - \toMsg toGlobalMsg allMetadata () model blogPost rendered -> - config.view toMsg toGlobalMsg allMetadata model blogPost rendered + \allMetadata () model blogPost rendered -> + config.view allMetadata model blogPost rendered , head = \() -> config.head , staticData = \_ -> StaticHttp.succeed () , init = \_ -> ( (), Cmd.none ) @@ -37,9 +35,7 @@ simplest config = simpler : { view : - (templateMsg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath pathKey, globalMetadata ) + List ( PagePath pathKey, globalMetadata ) -> templateModel -> templateMetadata -> renderedTemplate @@ -51,12 +47,12 @@ simpler : , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) } - -> Template pathKey templateMetadata renderedTemplate () templateModel templateView templateMsg globalMetadata msg + -> Template pathKey templateMetadata renderedTemplate () templateModel templateView templateMsg globalMetadata simpler config = template { view = - \toMsg toGlobalMsg allMetadata () model blogPost rendered -> - config.view toMsg toGlobalMsg allMetadata model blogPost rendered + \allMetadata () model blogPost rendered -> + config.view allMetadata model blogPost rendered , head = \() -> config.head , staticData = \_ -> StaticHttp.succeed () , init = config.init @@ -71,9 +67,7 @@ stateless : List ( PagePath pathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - (templateMsg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath pathKey, globalMetadata ) + List ( PagePath pathKey, globalMetadata ) -> templateStaticData -> templateMetadata -> renderedTemplate @@ -84,12 +78,12 @@ stateless : -> templateMetadata -> List (Head.Tag pathKey) } - -> Template pathKey templateMetadata renderedTemplate templateStaticData () templateView templateMsg globalMetadata msg + -> Template pathKey templateMetadata renderedTemplate templateStaticData () templateView templateMsg globalMetadata stateless config = template { view = - \toMsg toGlobalMsg allMetadata staticData () blogPost rendered -> - config.view toMsg toGlobalMsg allMetadata staticData blogPost rendered + \allMetadata staticData () blogPost rendered -> + config.view allMetadata staticData blogPost rendered , head = config.head , staticData = config.staticData , init = \_ -> ( (), Cmd.none ) @@ -104,9 +98,7 @@ template : List ( PagePath pathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - (templateMsg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath pathKey, globalMetadata ) + List ( PagePath pathKey, globalMetadata ) -> templateStaticData -> templateModel -> templateMetadata @@ -122,19 +114,17 @@ template : , save : templateModel -> Global.Model -> Global.Model , load : Global.Model -> templateModel -> ( templateModel, Cmd templateMsg ) } - -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata msg + -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata template config = config -type alias Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata msg = +type alias Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata = { staticData : List ( PagePath pathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - (templateMsg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath pathKey, globalMetadata ) + List ( PagePath pathKey, globalMetadata ) -> templateStaticData -> templateModel -> templateMetadata diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 50fed074..ca59a0c8 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -21,7 +21,7 @@ type Msg = Msg -template : TemplateDocument BlogIndex StaticData Model Msg msg +template : TemplateDocument BlogIndex StaticData Model Msg template = Template.template { view = view @@ -77,15 +77,13 @@ type alias View msg = view : - (Msg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> BlogIndex - -> Global.RenderedBody Never - -> { title : String, body : Element Never } -view toMsg toGlobalMsg allMetadata static model metadata rendered = + -> Global.RenderedBody + -> { title : String, body : Element Msg } +view allMetadata static model metadata rendered = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 93364b9d..0de077ee 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -30,7 +30,7 @@ type Msg = Msg -template : TemplateDocument BlogPost () Model Msg msg +template : TemplateDocument BlogPost () Model Msg template = Template.simpler { view = view @@ -98,14 +98,12 @@ update metadata msg model = view : - (Msg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> Model -> BlogPost - -> Global.RenderedBody Never - -> { title : String, body : Element Never } -view toMsg toGlobalMsg allMetadata model blogPost rendered = + -> Global.RenderedBody + -> { title : String, body : Element Msg } +view allMetadata model blogPost rendered = { title = blogPost.title , body = Element.column [ Element.width Element.fill ] @@ -132,6 +130,7 @@ view toMsg toGlobalMsg allMetadata model blogPost rendered = :: Palette.blogHeading blogPost.title :: articleImageView blogPost.image :: Tuple.second rendered + |> List.map (Element.map never) ) ] } diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 26d0f08d..46ce10e5 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -32,7 +32,7 @@ type Msg = Msg -template : TemplateDocument Documentation StaticData Model Msg msg +template : TemplateDocument Documentation StaticData Model Msg template = Template.template { view = view @@ -95,19 +95,18 @@ head static currentPath meta = view : - (Msg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> Documentation - -> Global.RenderedBody Never - -> { title : String, body : Element Never } -view toMsg toGlobalMsg allMetadata static model metadata rendered = + -> Global.RenderedBody + -> { title : String, body : Element Msg } +view allMetadata static model metadata rendered = { title = metadata.title , body = [ Element.row [] - [ DocSidebar.view + [ counterView model + , DocSidebar.view Pages.pages.index allMetadata |> Element.el [ Element.width (Element.fillPortion 2), Element.alignTop, Element.height Element.fill ] @@ -120,7 +119,7 @@ view toMsg toGlobalMsg allMetadata static model metadata rendered = , Element.spacing 30 , Element.Region.mainContent ] - (Tuple.second rendered) + (Tuple.second rendered |> List.map (Element.map never)) ] ] ] @@ -132,6 +131,11 @@ view toMsg toGlobalMsg allMetadata static model metadata rendered = } +counterView : Model -> Element Msg +counterView model = + Element.text "" + + tocView : MarkdownRenderer.TableOfContents -> Element msg tocView toc = Element.column [ Element.alignTop, Element.spacing 20 ] diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index d2d09cbe..60e2dbe6 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -28,7 +28,7 @@ type Msg = Msg -template : TemplateDocument Page StaticData Model Msg msg +template : TemplateDocument Page StaticData Model Msg template = Template.simplest { view = view @@ -76,14 +76,12 @@ head currentPath meta = view : - (Msg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> Model -> Page - -> Global.RenderedBody Never - -> { title : String, body : Element Never } -view toMsg toGlobalMsg allMetadata model metadata rendered = + -> Global.RenderedBody + -> { title : String, body : Element Msg } +view allMetadata model metadata rendered = { title = metadata.title , body = [ Element.column @@ -91,7 +89,7 @@ view toMsg toGlobalMsg allMetadata model metadata rendered = , Element.spacing 60 , Element.Region.mainContent ] - (Tuple.second rendered) + (Tuple.second rendered |> List.map (Element.map never)) ] |> Element.textColumn [ Element.width Element.fill diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index bcc491a4..c2f2455d 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -23,7 +23,7 @@ type Msg = Msg -template : TemplateDocument Showcase StaticData Model Msg msg +template : TemplateDocument Showcase StaticData Model Msg template = Template.stateless { view = view @@ -47,14 +47,12 @@ type alias StaticData = view : - (Msg -> msg) - -> (Global.Msg -> msg) - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Showcase - -> Global.RenderedBody Never - -> { title : String, body : Element Never } -view toMsg toGlobalMsg allMetadata static metadata rendered = + -> Global.RenderedBody + -> { title : String, body : Element Msg } +view allMetadata static metadata rendered = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] diff --git a/examples/docs/src/TemplateDocument.elm b/examples/docs/src/TemplateDocument.elm index b8486aa5..3278b8d3 100644 --- a/examples/docs/src/TemplateDocument.elm +++ b/examples/docs/src/TemplateDocument.elm @@ -18,5 +18,5 @@ type alias RenderedBody msg = ( MarkdownRenderer.TableOfContents, List (Element msg) ) -type alias TemplateDocument templateMetadata templateStaticData templateModel templateMsg internalMsg = - Template Pages.PathKey templateMetadata (RenderedBody Never) templateStaticData templateModel (View Never) templateMsg GlobalMetadata.Metadata internalMsg +type alias TemplateDocument templateMetadata templateStaticData templateModel templateMsg = + Template Pages.PathKey templateMetadata Global.RenderedBody templateStaticData templateModel (View templateMsg) templateMsg GlobalMetadata.Metadata diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 7195dcad..98075332 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -60,7 +60,7 @@ view : } -> StaticHttp.Request - { view : Model -> Global.View -> { title : String, body : Html Msg } + { view : Model -> Global.RenderedBody -> { title : String, body : Html Msg } , head : List (Head.Tag Pages.PathKey) } view siteMetadata page = @@ -74,8 +74,6 @@ view siteMetadata page = case model.page of Model${name} subModel -> Template.${name}.template.view - Msg${name} - MsgGlobal siteMetadata data subModel @@ -87,7 +85,9 @@ view siteMetadata page = page model.global MsgGlobal - { title = title, body = body } + ({ title = title, body = body } + |> Global.map Msg${name} + ) ) _ -> From 6bebe4f32c82cb75dbc9fd70962171f220ef8f62 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Tue, 1 Sep 2020 23:03:50 -0700 Subject: [PATCH 051/106] Persist global state. --- examples/docs/src/Global.elm | 2 +- examples/docs/src/Template/Documentation.elm | 18 ++++++++------ .../src/generate-template-module-connector.js | 24 ++++++++++--------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index b1cf2bb6..68281355 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -134,7 +134,7 @@ view stars page model toMsg pageView = incrementView : Model -> Element Msg incrementView model = - Element.el [ Element.Events.onClick Increment ] (Element.text <| String.fromInt model.counter) + Element.el [ Element.Events.onClick Increment ] (Element.text <| "Global count: " ++ String.fromInt model.counter) logoLinkMobile = diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 46ce10e5..6986feae 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -2,6 +2,7 @@ module Template.Documentation exposing (Model, Msg, decoder, template) import DocSidebar import Element exposing (Element) +import Element.Events import Element.Font as Font import Element.Region import Global @@ -24,12 +25,13 @@ type alias StaticData = () -type Model - = Model +type alias Model = + { counter : Int + } type Msg - = Msg + = Increment template : TemplateDocument Documentation StaticData Model Msg @@ -47,7 +49,7 @@ template = load : Global.Model -> Model -> ( Model, Cmd Msg ) load globalModel model = - ( model, Cmd.none ) + ( { model | counter = globalModel.counter }, Cmd.none ) save : Model -> Global.Model -> Global.Model @@ -57,12 +59,14 @@ save model globalModel = init : Documentation -> ( Model, Cmd Msg ) init metadata = - ( Model, Cmd.none ) + ( { counter = 0 }, Cmd.none ) update : Documentation -> Msg -> Model -> ( Model, Cmd Msg ) update metadata msg model = - ( Model, Cmd.none ) + case msg of + Increment -> + ( { counter = model.counter + 1 }, Cmd.none ) staticData : a -> StaticHttp.Request StaticData @@ -133,7 +137,7 @@ view allMetadata static model metadata rendered = counterView : Model -> Element Msg counterView model = - Element.text "" + Element.el [ Element.Events.onClick Increment ] (Element.text <| "Docs count: " ++ String.fromInt model.counter) tocView : MarkdownRenderer.TableOfContents -> Element msg diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 98075332..385d540b 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -102,17 +102,19 @@ view siteMetadata page = init : - Maybe - { path : - { path : PagePath Pages.PathKey - , query : Maybe String - , fragment : Maybe String + Maybe Global.Model + -> + Maybe + { path : + { path : PagePath Pages.PathKey + , query : Maybe String + , fragment : Maybe String + } + , metadata : Metadata } - , metadata : Metadata - } -> ( Model, Cmd Msg ) -init maybePagePath = - ( { global = Global.init maybePagePath +init currentGlobalModel maybePagePath = + ( { global = currentGlobalModel |> Maybe.withDefault (Global.init maybePagePath) , page = case maybePagePath |> Maybe.map .metadata of Nothing -> @@ -143,7 +145,7 @@ update msg model = ( { model | global = globalModel }, globalCmd |> Cmd.map MsgGlobal ) OnPageChange record -> - init <| + init (Just model.global) <| Just { path = { path = record.path @@ -189,7 +191,7 @@ save model globalModel= mainTemplate { documents, manifest, canonicalSiteUrl, subscriptions } = Pages.Platform.init - { init = init + { init = init Nothing , view = view , update = update , subscriptions = subscriptions From dc9e34207a2eea6992edf3ca9c30875ab47169c4 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Tue, 1 Sep 2020 23:49:23 -0700 Subject: [PATCH 052/106] Init local model with load from global model. --- examples/docs/src/Global.elm | 10 +++--- examples/docs/src/Template/Documentation.elm | 2 +- .../src/generate-template-module-connector.js | 34 +++++++++++++++++-- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index 68281355..a08d4be6 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -62,11 +62,13 @@ type Msg | Increment -init : a -> Model +init : a -> ( Model, Cmd Msg ) init maybePagePath = - { showMobileMenu = False - , counter = 0 - } + ( { showMobileMenu = False + , counter = 0 + } + , Cmd.none + ) update : Msg -> Model -> ( Model, Cmd Msg ) diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 6986feae..db402561 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -54,7 +54,7 @@ load globalModel model = save : Model -> Global.Model -> Global.Model save model globalModel = - globalModel + { globalModel | counter = model.counter } init : Documentation -> ( Model, Cmd Msg ) diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 385d540b..ac961a83 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -114,8 +114,11 @@ init : } -> ( Model, Cmd Msg ) init currentGlobalModel maybePagePath = - ( { global = currentGlobalModel |> Maybe.withDefault (Global.init maybePagePath) - , page = + let + ( globalModel, globalCmd ) = + currentGlobalModel |> Maybe.map (\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Global.init maybePagePath) + + page = case maybePagePath |> Maybe.map .metadata of Nothing -> NotFound @@ -128,12 +131,22 @@ init currentGlobalModel maybePagePath = |> Model${name} `).join("\n ")} + + ( templateModel, templateCmd ) = + load globalModel page + in + ( { global = globalModel + , page = templateModel , current = maybePagePath } - , Cmd.none + , Cmd.batch + [ templateCmd + , globalCmd |> Cmd.map MsgGlobal + ] ) + update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of @@ -176,6 +189,21 @@ update msg model = +load : Global.Model -> TemplateModel -> ( TemplateModel, Cmd Msg ) +load globalModel model = + case model of + ${templates.map(name => `Model${name} m -> + Template.${name}.template.load globalModel m + |> Tuple.mapFirst (Model${name}) + |> Tuple.mapSecond (Cmd.map Msg${name}) +` + ).join("\n ")} + + NotFound -> + ( model, Cmd.none ) + + + save : TemplateModel -> Global.Model -> Global.Model save model globalModel= case model of From e4a703b8d44ce41e18adc883dc08ccc94b95732e Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 2 Sep 2020 07:57:33 -0700 Subject: [PATCH 053/106] Wire in load function on global msgs. --- .../src/generate-template-module-connector.js | 13 +- .../generated-files.test.js.snap | 120 +++++++++++++----- 2 files changed, 102 insertions(+), 31 deletions(-) diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index ac961a83..083ba793 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -154,8 +154,19 @@ update msg model = let ( globalModel, globalCmd ) = Global.update msg_ model.global + + ( templateModel, templateCmd ) = + load globalModel model.page in - ( { model | global = globalModel }, globalCmd |> Cmd.map MsgGlobal ) + ( { model + | global = globalModel + , page = templateModel + } + , Cmd.batch + [ templateCmd + , globalCmd |> Cmd.map MsgGlobal + ] + ) OnPageChange record -> init (Just model.global) <| diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index e851b40d..571784cc 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -184,7 +184,7 @@ view : } -> StaticHttp.Request - { view : Model -> Global.View -> { title : String, body : Html Msg } + { view : Model -> Global.RenderedBody -> { title : String, body : Html Msg } , head : List (Head.Tag Pages.PathKey) } view siteMetadata page = @@ -197,8 +197,6 @@ view siteMetadata page = case model.page of ModelBlogIndex subModel -> Template.BlogIndex.template.view - MsgBlogIndex - MsgGlobal siteMetadata data subModel @@ -210,7 +208,9 @@ view siteMetadata page = page model.global MsgGlobal - { title = title, body = body } + ({ title = title, body = body } + |> Global.map MsgBlogIndex + ) ) _ -> @@ -230,8 +230,6 @@ view siteMetadata page = case model.page of ModelBlogPost subModel -> Template.BlogPost.template.view - MsgBlogPost - MsgGlobal siteMetadata data subModel @@ -243,7 +241,9 @@ view siteMetadata page = page model.global MsgGlobal - { title = title, body = body } + ({ title = title, body = body } + |> Global.map MsgBlogPost + ) ) _ -> @@ -263,8 +263,6 @@ view siteMetadata page = case model.page of ModelDocumentation subModel -> Template.Documentation.template.view - MsgDocumentation - MsgGlobal siteMetadata data subModel @@ -276,7 +274,9 @@ view siteMetadata page = page model.global MsgGlobal - { title = title, body = body } + ({ title = title, body = body } + |> Global.map MsgDocumentation + ) ) _ -> @@ -296,8 +296,6 @@ view siteMetadata page = case model.page of ModelPage subModel -> Template.Page.template.view - MsgPage - MsgGlobal siteMetadata data subModel @@ -309,7 +307,9 @@ view siteMetadata page = page model.global MsgGlobal - { title = title, body = body } + ({ title = title, body = body } + |> Global.map MsgPage + ) ) _ -> @@ -329,8 +329,6 @@ view siteMetadata page = case model.page of ModelShowcase subModel -> Template.Showcase.template.view - MsgShowcase - MsgGlobal siteMetadata data subModel @@ -342,7 +340,9 @@ view siteMetadata page = page model.global MsgGlobal - { title = title, body = body } + ({ title = title, body = body } + |> Global.map MsgShowcase + ) ) _ -> @@ -356,18 +356,23 @@ view siteMetadata page = init : - Maybe - { path : - { path : PagePath Pages.PathKey - , query : Maybe String - , fragment : Maybe String + Maybe Global.Model + -> + Maybe + { path : + { path : PagePath Pages.PathKey + , query : Maybe String + , fragment : Maybe String + } + , metadata : Metadata } - , metadata : Metadata - } -> ( Model, Cmd Msg ) -init maybePagePath = - ( { global = Global.init maybePagePath - , page = +init currentGlobalModel maybePagePath = + let + ( globalModel, globalCmd ) = + currentGlobalModel |> Maybe.map (\\\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Global.init maybePagePath) + + page = case maybePagePath |> Maybe.map .metadata of Nothing -> NotFound @@ -404,12 +409,22 @@ init maybePagePath = |> ModelShowcase + + ( templateModel, templateCmd ) = + load globalModel page + in + ( { global = globalModel + , page = templateModel , current = maybePagePath } - , Cmd.none + , Cmd.batch + [ templateCmd + , globalCmd |> Cmd.map MsgGlobal + ] ) + update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of @@ -417,11 +432,22 @@ update msg model = let ( globalModel, globalCmd ) = Global.update msg_ model.global + + ( templateModel, templateCmd ) = + load globalModel model.page in - ( { model | global = globalModel }, globalCmd |> Cmd.map MsgGlobal ) + ( { model + | global = globalModel + , page = templateModel + } + , Cmd.batch + [ templateCmd + , globalCmd |> Cmd.map MsgGlobal + ] + ) OnPageChange record -> - init <| + init (Just model.global) <| Just { path = { path = record.path @@ -519,6 +545,40 @@ update msg model = +load : Global.Model -> TemplateModel -> ( TemplateModel, Cmd Msg ) +load globalModel model = + case model of + ModelBlogIndex m -> + Template.BlogIndex.template.load globalModel m + |> Tuple.mapFirst (ModelBlogIndex) + |> Tuple.mapSecond (Cmd.map MsgBlogIndex) + + ModelBlogPost m -> + Template.BlogPost.template.load globalModel m + |> Tuple.mapFirst (ModelBlogPost) + |> Tuple.mapSecond (Cmd.map MsgBlogPost) + + ModelDocumentation m -> + Template.Documentation.template.load globalModel m + |> Tuple.mapFirst (ModelDocumentation) + |> Tuple.mapSecond (Cmd.map MsgDocumentation) + + ModelPage m -> + Template.Page.template.load globalModel m + |> Tuple.mapFirst (ModelPage) + |> Tuple.mapSecond (Cmd.map MsgPage) + + ModelShowcase m -> + Template.Showcase.template.load globalModel m + |> Tuple.mapFirst (ModelShowcase) + |> Tuple.mapSecond (Cmd.map MsgShowcase) + + + NotFound -> + ( model, Cmd.none ) + + + save : TemplateModel -> Global.Model -> Global.Model save model globalModel= case model of @@ -545,7 +605,7 @@ save model globalModel= mainTemplate { documents, manifest, canonicalSiteUrl, subscriptions } = Pages.Platform.init - { init = init + { init = init Nothing , view = view , update = update , subscriptions = subscriptions From b66b0ba45c73e357047740e9eda46048b816af3f Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 5 Sep 2020 21:02:05 -0700 Subject: [PATCH 054/106] Wire up new shared update msg. --- examples/docs/src/Global.elm | 10 ++++++++++ examples/docs/src/Template.elm | 16 ++++++++++++++-- .../src/generate-template-module-connector.js | 17 +++++++++++++---- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index a08d4be6..f8feb5cd 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -21,6 +21,10 @@ import Palette import Secrets +type GlobalMsg + = NoOp + + type alias Model = { showMobileMenu : Bool , counter : Int @@ -60,6 +64,7 @@ type Msg } | ToggleMobileMenu | Increment + | SharedMsg GlobalMsg init : a -> ( Model, Cmd Msg ) @@ -83,6 +88,11 @@ update msg model = Increment -> ( { model | counter = model.counter + 1 }, Cmd.none ) + SharedMsg globalMsg -> + case globalMsg of + NoOp -> + ( model, Cmd.none ) + type alias StaticData = Int diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 51391a62..bc5533c4 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -116,7 +116,19 @@ template : } -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata template config = - config + { view = config.view + , head = config.head + , staticData = config.staticData + , init = config.init + , update = + \a b c -> + config.update a b c + |> (\tuple -> + ( tuple |> Tuple.first, tuple |> Tuple.second, Global.NoOp ) + ) + , save = \_ globalModel -> globalModel + , load = \_ model -> ( model, Cmd.none ) + } type alias Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata = @@ -136,7 +148,7 @@ type alias Template pathKey templateMetadata renderedTemplate templateStaticData -> templateMetadata -> List (Head.Tag pathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Global.GlobalMsg ) , save : templateModel -> Global.Model -> Global.Model , load : Global.Model -> templateModel -> ( templateModel, Cmd templateMsg ) } diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 083ba793..1ad77e7a 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -182,19 +182,24 @@ update msg model = ${templates.map(name => ` Msg${name} msg_ -> let - ( updatedPageModel, pageCmd ) = + ( updatedPageModel, pageCmd, ( newGlobalModel, newGlobalCmd ) ) = case ( model.page, model.current |> Maybe.map .metadata ) of ( Model${name} pageModel, Just (M.Metadata${name} metadata) ) -> Template.${name}.template.update metadata msg_ pageModel - |> Tuple.mapBoth Model${name} (Cmd.map Msg${name}) + |> mapBoth Model${name} (Cmd.map Msg${name}) + |> (\\( a, b, c ) -> + ( a, b, Global.update (Global.SharedMsg c) model.global ) + ) _ -> - ( model.page, Cmd.none ) + ( model.page, Cmd.none, ( model.global, Cmd.none ) ) in - ( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd ) + ( { model | page = updatedPageModel, global = newGlobalModel } + , Cmd.batch [ pageCmd, newGlobalCmd |> Cmd.map MsgGlobal ] + ) ` ).join("\n ")} @@ -247,6 +252,10 @@ mapDocument document = { title = document.title , body = document.body |> List.map (Html.map never) } + + +mapBoth fnA fnB ( a, b, c ) = + ( fnA a, fnB b, c ) ` } From 87eb2408cc277d1cc4605cb717866292029df58d Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 5 Sep 2020 21:12:54 -0700 Subject: [PATCH 055/106] Stop generating save function. --- examples/docs/src/Template.elm | 6 ------ examples/docs/src/Template/BlogIndex.elm | 6 ------ examples/docs/src/Template/Documentation.elm | 6 ------ generator/src/generate-template-module-connector.js | 13 ------------- 4 files changed, 31 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index bc5533c4..ef2e99b0 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -28,7 +28,6 @@ simplest config = , staticData = \_ -> StaticHttp.succeed () , init = \_ -> ( (), Cmd.none ) , update = \_ _ _ -> ( (), Cmd.none ) - , save = \_ globalModel -> globalModel , load = \_ model -> ( model, Cmd.none ) } @@ -57,7 +56,6 @@ simpler config = , staticData = \_ -> StaticHttp.succeed () , init = config.init , update = config.update - , save = \_ globalModel -> globalModel , load = \_ model -> ( model, Cmd.none ) } @@ -88,7 +86,6 @@ stateless config = , staticData = config.staticData , init = \_ -> ( (), Cmd.none ) , update = \_ _ _ -> ( (), Cmd.none ) - , save = \_ globalModel -> globalModel , load = \_ model -> ( model, Cmd.none ) } @@ -111,7 +108,6 @@ template : -> List (Head.Tag pathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) - , save : templateModel -> Global.Model -> Global.Model , load : Global.Model -> templateModel -> ( templateModel, Cmd templateMsg ) } -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata @@ -126,7 +122,6 @@ template config = |> (\tuple -> ( tuple |> Tuple.first, tuple |> Tuple.second, Global.NoOp ) ) - , save = \_ globalModel -> globalModel , load = \_ model -> ( model, Cmd.none ) } @@ -149,7 +144,6 @@ type alias Template pathKey templateMetadata renderedTemplate templateStaticData -> List (Head.Tag pathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Global.GlobalMsg ) - , save : templateModel -> Global.Model -> Global.Model , load : Global.Model -> templateModel -> ( templateModel, Cmd templateMsg ) } diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index ca59a0c8..6f9ee4b2 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -30,7 +30,6 @@ template = , init = init , update = update , load = load - , save = save } @@ -39,11 +38,6 @@ load globalModel model = ( model, Cmd.none ) -save : Model -> Global.Model -> Global.Model -save model globalModel = - globalModel - - staticData : a -> StaticHttp.Request StaticData staticData siteMetadata = Showcase.staticRequest diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index db402561..8cadbda5 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -43,7 +43,6 @@ template = , init = init , update = update , load = load - , save = save } @@ -52,11 +51,6 @@ load globalModel model = ( { model | counter = globalModel.counter }, Cmd.none ) -save : Model -> Global.Model -> Global.Model -save model globalModel = - { globalModel | counter = model.counter } - - init : Documentation -> ( Model, Cmd Msg ) init metadata = ( { counter = 0 }, Cmd.none ) diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 1ad77e7a..cd1a7fd3 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -220,19 +220,6 @@ load globalModel model = -save : TemplateModel -> Global.Model -> Global.Model -save model globalModel= - case model of - ${templates.map(name => `Model${name} m -> - Template.${name}.template.save m globalModel -` - ).join("\n ")} - - NotFound -> - globalModel - - - mainTemplate { documents, manifest, canonicalSiteUrl, subscriptions } = Pages.Platform.init { init = init Nothing From 57310bacd84d54c4cc7a6322bc5343892f246bcf Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 5 Sep 2020 21:31:14 -0700 Subject: [PATCH 056/106] Wire in global model to view. --- examples/docs/src/Global.elm | 4 +++ examples/docs/src/Template.elm | 33 ++++++++++--------- examples/docs/src/Template/BlogIndex.elm | 9 ++--- examples/docs/src/Template/Documentation.elm | 24 +++++++------- .../src/generate-template-module-connector.js | 1 + 5 files changed, 40 insertions(+), 31 deletions(-) diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index f8feb5cd..3dc184ca 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -23,6 +23,7 @@ import Secrets type GlobalMsg = NoOp + | IncrementFromChild type alias Model = @@ -93,6 +94,9 @@ update msg model = NoOp -> ( model, Cmd.none ) + IncrementFromChild -> + ( { model | counter = model.counter + 1 }, Cmd.none ) + type alias StaticData = Int diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index ef2e99b0..e3a5b292 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -22,12 +22,12 @@ simplest : simplest config = template { view = - \allMetadata () model blogPost rendered -> + \global allMetadata () model blogPost rendered -> config.view allMetadata model blogPost rendered , head = \() -> config.head , staticData = \_ -> StaticHttp.succeed () , init = \_ -> ( (), Cmd.none ) - , update = \_ _ _ -> ( (), Cmd.none ) + , update = \_ _ _ -> ( (), Cmd.none, Global.NoOp ) , load = \_ model -> ( model, Cmd.none ) } @@ -50,12 +50,12 @@ simpler : simpler config = template { view = - \allMetadata () model blogPost rendered -> + \global allMetadata () model blogPost rendered -> config.view allMetadata model blogPost rendered , head = \() -> config.head , staticData = \_ -> StaticHttp.succeed () , init = config.init - , update = config.update + , update = \a1 b1 c1 -> config.update a1 b1 c1 |> (\( a, b ) -> ( a, b, Global.NoOp )) , load = \_ model -> ( model, Cmd.none ) } @@ -80,12 +80,12 @@ stateless : stateless config = template { view = - \allMetadata staticData () blogPost rendered -> + \global allMetadata staticData () blogPost rendered -> config.view allMetadata staticData blogPost rendered , head = config.head , staticData = config.staticData , init = \_ -> ( (), Cmd.none ) - , update = \_ _ _ -> ( (), Cmd.none ) + , update = \_ _ _ -> ( (), Cmd.none, Global.NoOp ) , load = \_ model -> ( model, Cmd.none ) } @@ -95,7 +95,8 @@ template : List ( PagePath pathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - List ( PagePath pathKey, globalMetadata ) + Global.Model + -> List ( PagePath pathKey, globalMetadata ) -> templateStaticData -> templateModel -> templateMetadata @@ -107,7 +108,7 @@ template : -> templateMetadata -> List (Head.Tag pathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Global.GlobalMsg ) , load : Global.Model -> templateModel -> ( templateModel, Cmd templateMsg ) } -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata @@ -116,12 +117,13 @@ template config = , head = config.head , staticData = config.staticData , init = config.init - , update = - \a b c -> - config.update a b c - |> (\tuple -> - ( tuple |> Tuple.first, tuple |> Tuple.second, Global.NoOp ) - ) + , update = config.update + + --\a b c -> + -- config.update a b c + -- |> (\tuple -> + -- ( tuple |> Tuple.first, tuple |> Tuple.second, Global.NoOp ) + -- ) , load = \_ model -> ( model, Cmd.none ) } @@ -131,7 +133,8 @@ type alias Template pathKey templateMetadata renderedTemplate templateStaticData List ( PagePath pathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - List ( PagePath pathKey, globalMetadata ) + Global.Model + -> List ( PagePath pathKey, globalMetadata ) -> templateStaticData -> templateModel -> templateMetadata diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 6f9ee4b2..c77c3686 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -52,9 +52,9 @@ init metadata = ( Model, Cmd.none ) -update : BlogIndex -> Msg -> Model -> ( Model, Cmd Msg ) +update : BlogIndex -> Msg -> Model -> ( Model, Cmd Msg, Global.GlobalMsg ) update metadata msg model = - ( Model, Cmd.none ) + ( Model, Cmd.none, Global.NoOp ) type alias Model = @@ -71,13 +71,14 @@ type alias View msg = view : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + Global.Model + -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> BlogIndex -> Global.RenderedBody -> { title : String, body : Element Msg } -view allMetadata static model metadata rendered = +view globalModel allMetadata static model metadata rendered = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 8cadbda5..5c7b01bb 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -26,8 +26,7 @@ type alias StaticData = type alias Model = - { counter : Int - } + {} type Msg @@ -48,19 +47,19 @@ template = load : Global.Model -> Model -> ( Model, Cmd Msg ) load globalModel model = - ( { model | counter = globalModel.counter }, Cmd.none ) + ( model, Cmd.none ) init : Documentation -> ( Model, Cmd Msg ) init metadata = - ( { counter = 0 }, Cmd.none ) + ( {}, Cmd.none ) -update : Documentation -> Msg -> Model -> ( Model, Cmd Msg ) +update : Documentation -> Msg -> Model -> ( Model, Cmd Msg, Global.GlobalMsg ) update metadata msg model = case msg of Increment -> - ( { counter = model.counter + 1 }, Cmd.none ) + ( model, Cmd.none, Global.IncrementFromChild ) staticData : a -> StaticHttp.Request StaticData @@ -93,17 +92,18 @@ head static currentPath meta = view : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + Global.Model + -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> Documentation -> Global.RenderedBody -> { title : String, body : Element Msg } -view allMetadata static model metadata rendered = +view globalModel allMetadata static model metadata rendered = { title = metadata.title , body = [ Element.row [] - [ counterView model + [ counterView globalModel , DocSidebar.view Pages.pages.index allMetadata @@ -129,9 +129,9 @@ view allMetadata static model metadata rendered = } -counterView : Model -> Element Msg -counterView model = - Element.el [ Element.Events.onClick Increment ] (Element.text <| "Docs count: " ++ String.fromInt model.counter) +counterView : Global.Model -> Element Msg +counterView globalModel = + Element.el [ Element.Events.onClick Increment ] (Element.text <| "Docs count: " ++ String.fromInt globalModel.counter) tocView : MarkdownRenderer.TableOfContents -> Element msg diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index cd1a7fd3..d27b23e9 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -74,6 +74,7 @@ view siteMetadata page = case model.page of Model${name} subModel -> Template.${name}.template.view + model.global siteMetadata data subModel From eb8c0ffabcb249841361342dc3de971bb180ee0c Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 5 Sep 2020 22:17:28 -0700 Subject: [PATCH 057/106] Remove save hook. --- examples/docs/src/Template.elm | 6 --- examples/docs/src/Template/BlogIndex.elm | 6 --- examples/docs/src/Template/Documentation.elm | 6 --- .../src/generate-template-module-connector.js | 39 +++---------------- 4 files changed, 5 insertions(+), 52 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index e3a5b292..efdb60f7 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -28,7 +28,6 @@ simplest config = , staticData = \_ -> StaticHttp.succeed () , init = \_ -> ( (), Cmd.none ) , update = \_ _ _ -> ( (), Cmd.none, Global.NoOp ) - , load = \_ model -> ( model, Cmd.none ) } @@ -56,7 +55,6 @@ simpler config = , staticData = \_ -> StaticHttp.succeed () , init = config.init , update = \a1 b1 c1 -> config.update a1 b1 c1 |> (\( a, b ) -> ( a, b, Global.NoOp )) - , load = \_ model -> ( model, Cmd.none ) } @@ -86,7 +84,6 @@ stateless config = , staticData = config.staticData , init = \_ -> ( (), Cmd.none ) , update = \_ _ _ -> ( (), Cmd.none, Global.NoOp ) - , load = \_ model -> ( model, Cmd.none ) } @@ -109,7 +106,6 @@ template : -> List (Head.Tag pathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Global.GlobalMsg ) - , load : Global.Model -> templateModel -> ( templateModel, Cmd templateMsg ) } -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata template config = @@ -124,7 +120,6 @@ template config = -- |> (\tuple -> -- ( tuple |> Tuple.first, tuple |> Tuple.second, Global.NoOp ) -- ) - , load = \_ model -> ( model, Cmd.none ) } @@ -147,7 +142,6 @@ type alias Template pathKey templateMetadata renderedTemplate templateStaticData -> List (Head.Tag pathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Global.GlobalMsg ) - , load : Global.Model -> templateModel -> ( templateModel, Cmd templateMsg ) } diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index c77c3686..483cfd81 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -29,15 +29,9 @@ template = , staticData = staticData , init = init , update = update - , load = load } -load : Global.Model -> Model -> ( Model, Cmd Msg ) -load globalModel model = - ( model, Cmd.none ) - - staticData : a -> StaticHttp.Request StaticData staticData siteMetadata = Showcase.staticRequest diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 5c7b01bb..19243044 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -41,15 +41,9 @@ template = , staticData = staticData , init = init , update = update - , load = load } -load : Global.Model -> Model -> ( Model, Cmd Msg ) -load globalModel model = - ( model, Cmd.none ) - - init : Documentation -> ( Model, Cmd Msg ) init metadata = ( {}, Cmd.none ) diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index d27b23e9..d67f940a 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -119,22 +119,18 @@ init currentGlobalModel maybePagePath = ( globalModel, globalCmd ) = currentGlobalModel |> Maybe.map (\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Global.init maybePagePath) - page = + ( templateModel, templateCmd ) = case maybePagePath |> Maybe.map .metadata of Nothing -> - NotFound + ( NotFound, Cmd.none ) Just meta -> case meta of ${templates.map(name => `M.Metadata${name} metadata -> Template.${name}.template.init metadata - |> Tuple.first - |> Model${name} + |> Tuple.mapBoth Model${name} (Cmd.map Msg${name}) `).join("\n ")} - - ( templateModel, templateCmd ) = - load globalModel page in ( { global = globalModel , page = templateModel @@ -155,18 +151,9 @@ update msg model = let ( globalModel, globalCmd ) = Global.update msg_ model.global - - ( templateModel, templateCmd ) = - load globalModel model.page in - ( { model - | global = globalModel - , page = templateModel - } - , Cmd.batch - [ templateCmd - , globalCmd |> Cmd.map MsgGlobal - ] + ( { model | global = globalModel } + , globalCmd |> Cmd.map MsgGlobal ) OnPageChange record -> @@ -205,22 +192,6 @@ update msg model = ).join("\n ")} - -load : Global.Model -> TemplateModel -> ( TemplateModel, Cmd Msg ) -load globalModel model = - case model of - ${templates.map(name => `Model${name} m -> - Template.${name}.template.load globalModel m - |> Tuple.mapFirst (Model${name}) - |> Tuple.mapSecond (Cmd.map Msg${name}) -` - ).join("\n ")} - - NotFound -> - ( model, Cmd.none ) - - - mainTemplate { documents, manifest, canonicalSiteUrl, subscriptions } = Pages.Platform.init { init = init Nothing From 651de611462d30c886f92ee6684b73f0ec7cdf61 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 6 Sep 2020 08:37:59 -0700 Subject: [PATCH 058/106] Change Template signatures and use Template alias instead of TemplateDocument module. --- examples/docs/src/Template.elm | 131 ++++++++---------- examples/docs/src/Template/BlogIndex.elm | 27 +--- examples/docs/src/Template/BlogPost.elm | 25 ++-- examples/docs/src/Template/Documentation.elm | 21 ++- examples/docs/src/Template/Page.elm | 12 +- examples/docs/src/Template/Showcase.elm | 14 +- examples/docs/src/TemplateDocument.elm | 22 --- .../src/generate-template-module-connector.js | 11 +- 8 files changed, 105 insertions(+), 158 deletions(-) delete mode 100644 examples/docs/src/TemplateDocument.elm diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index efdb60f7..0db69456 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -2,28 +2,28 @@ module Template exposing (..) import Global import Head +import Pages import Pages.PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp simplest : { view : - List ( PagePath pathKey, globalMetadata ) - -> () - -> templateMetadata - -> renderedTemplate - -> templateView + List ( PagePath Pages.PathKey, globalMetadata ) + -> StaticPayload templateMetadata () + -> Global.RenderedBody + -> Global.PageView templateMsg , head : - PagePath pathKey + PagePath Pages.PathKey -> templateMetadata - -> List (Head.Tag pathKey) + -> List (Head.Tag Pages.PathKey) } - -> Template pathKey templateMetadata renderedTemplate () () templateView templateMsg globalMetadata + -> Template templateMetadata () () templateMsg globalMetadata simplest config = template { view = - \global allMetadata () model blogPost rendered -> - config.view allMetadata model blogPost rendered + \dynamicPayload allMetadata staticPayload rendered -> + config.view allMetadata staticPayload rendered , head = \() -> config.head , staticData = \_ -> StaticHttp.succeed () , init = \_ -> ( (), Cmd.none ) @@ -33,24 +33,24 @@ simplest config = simpler : { view : - List ( PagePath pathKey, globalMetadata ) + List ( PagePath Pages.PathKey, globalMetadata ) + -> StaticPayload templateMetadata () -> templateModel - -> templateMetadata - -> renderedTemplate - -> templateView + -> Global.RenderedBody + -> Global.PageView templateMsg , head : - PagePath pathKey + PagePath Pages.PathKey -> templateMetadata - -> List (Head.Tag pathKey) + -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) } - -> Template pathKey templateMetadata renderedTemplate () templateModel templateView templateMsg globalMetadata + -> Template templateMetadata () templateModel templateMsg globalMetadata simpler config = template { view = - \global allMetadata () model blogPost rendered -> - config.view allMetadata model blogPost rendered + \dynamicPayload allMetadata staticPayload rendered -> + config.view allMetadata staticPayload dynamicPayload.model rendered , head = \() -> config.head , staticData = \_ -> StaticHttp.succeed () , init = config.init @@ -60,26 +60,25 @@ simpler config = stateless : { staticData : - List ( PagePath pathKey, globalMetadata ) + List ( PagePath Pages.PathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - List ( PagePath pathKey, globalMetadata ) - -> templateStaticData - -> templateMetadata - -> renderedTemplate - -> templateView + List ( PagePath Pages.PathKey, globalMetadata ) + -> StaticPayload templateMetadata templateStaticData + -> Global.RenderedBody + -> Global.PageView templateMsg , head : templateStaticData - -> PagePath pathKey + -> PagePath Pages.PathKey -> templateMetadata - -> List (Head.Tag pathKey) + -> List (Head.Tag Pages.PathKey) } - -> Template pathKey templateMetadata renderedTemplate templateStaticData () templateView templateMsg globalMetadata + -> Template templateMetadata templateStaticData () templateMsg globalMetadata stateless config = template { view = - \global allMetadata staticData () blogPost rendered -> - config.view allMetadata staticData blogPost rendered + \dynamicPayload allMetadata staticPayload rendered -> + config.view allMetadata staticPayload rendered , head = config.head , staticData = config.staticData , init = \_ -> ( (), Cmd.none ) @@ -89,74 +88,62 @@ stateless config = template : { staticData : - List ( PagePath pathKey, globalMetadata ) + List ( PagePath Pages.PathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - Global.Model - -> List ( PagePath pathKey, globalMetadata ) - -> templateStaticData - -> templateModel - -> templateMetadata - -> renderedTemplate - -> templateView + DynamicPayload templateModel + -> List ( PagePath Pages.PathKey, globalMetadata ) + -> StaticPayload templateMetadata templateStaticData + -> Global.RenderedBody + -> Global.PageView templateMsg , head : templateStaticData - -> PagePath pathKey + -> PagePath Pages.PathKey -> templateMetadata - -> List (Head.Tag pathKey) + -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Global.GlobalMsg ) } - -> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata + -> Template templateMetadata templateStaticData templateModel templateMsg globalMetadata template config = { view = config.view , head = config.head , staticData = config.staticData , init = config.init , update = config.update - - --\a b c -> - -- config.update a b c - -- |> (\tuple -> - -- ( tuple |> Tuple.first, tuple |> Tuple.second, Global.NoOp ) - -- ) } -type alias Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata = +type alias Template templateMetadata templateStaticData templateModel templateMsg globalMetadata = { staticData : - List ( PagePath pathKey, globalMetadata ) + List ( PagePath Pages.PathKey, globalMetadata ) -> StaticHttp.Request templateStaticData , view : - Global.Model - -> List ( PagePath pathKey, globalMetadata ) - -> templateStaticData - -> templateModel - -> templateMetadata - -> renderedTemplate - -> templateView + DynamicPayload templateModel + -> List ( PagePath Pages.PathKey, globalMetadata ) + -> StaticPayload templateMetadata templateStaticData + -> Global.RenderedBody + -> Global.PageView templateMsg , head : templateStaticData - -> PagePath pathKey + -> PagePath Pages.PathKey -> templateMetadata - -> List (Head.Tag pathKey) + -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Global.GlobalMsg ) } +type alias StaticPayload metadata staticData = + { static : staticData ---template : --- { view : StaticData -> Model -> BlogPost -> ( a, List (Element msg) ) -> { title : String, body : Element msg } --- , head : StaticData -> PagePath Pages.PathKey -> BlogPost -> List (Head.Tag Pages.PathKey) --- , staticData : b -> StaticHttp.Request StaticData --- , init : BlogPost -> ( Model, Cmd Msg ) --- , update : BlogPost -> Model -> ( Model, Cmd Msg ) --- } ---template = --- { view = view --- , head = head --- , staticData = staticData --- , init = init --- , update = update --- } + --, globalStatic : Global.StaticData + , metadata : metadata + , path : PagePath Pages.PathKey + } + + +type alias DynamicPayload model = + { model : model + , globalModel : Global.Model + } diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 483cfd81..5ccd7f87 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -6,14 +6,12 @@ import GlobalMetadata import Head import Head.Seo as Seo import Index -import MarkdownRenderer import Pages exposing (images) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Showcase import SiteConfig -import Template -import TemplateDocument exposing (TemplateDocument) +import Template exposing (DynamicPayload, StaticPayload, Template) import TemplateMetadata exposing (BlogIndex) @@ -21,7 +19,7 @@ type Msg = Msg -template : TemplateDocument BlogIndex StaticData Model Msg +template : Template BlogIndex StaticData Model Msg GlobalMetadata.Metadata template = Template.template { view = view @@ -41,7 +39,7 @@ type alias StaticData = List Showcase.Entry -init : BlogIndex -> ( Model, Cmd msg ) +init : BlogIndex -> ( Model, Cmd Msg ) init metadata = ( Model, Cmd.none ) @@ -55,24 +53,13 @@ type alias Model = {} -type alias View msg = - ( MarkdownRenderer.TableOfContents, List (Element msg) ) - - - ---view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> BlogIndex -> ( a, List (Element msg) ) -> { title : String, body : Element msg } ---view siteMetadata data model metadata viewForPage = - - view : - Global.Model + DynamicPayload Model -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) - -> StaticData - -> Model - -> BlogIndex + -> StaticPayload BlogIndex StaticData -> Global.RenderedBody - -> { title : String, body : Element Msg } -view globalModel allMetadata static model metadata rendered = + -> Global.PageView Msg +view dynamicPayload allMetadata staticPayload rendered = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 0de077ee..85aebd6a 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -17,8 +17,7 @@ import Pages.PagePath as PagePath exposing (PagePath) import Palette import SiteConfig import StructuredData -import Template -import TemplateDocument exposing (TemplateDocument) +import Template exposing (DynamicPayload, StaticPayload, Template) import TemplateMetadata exposing (BlogPost) @@ -30,7 +29,7 @@ type Msg = Msg -template : TemplateDocument BlogPost () Model Msg +template : Template BlogPost () Model Msg GlobalMetadata.Metadata template = Template.simpler { view = view @@ -99,12 +98,12 @@ update metadata msg model = view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> StaticPayload BlogPost () -> Model - -> BlogPost -> Global.RenderedBody - -> { title : String, body : Element Msg } -view allMetadata model blogPost rendered = - { title = blogPost.title + -> Global.PageView Msg +view allMetadata staticPayload model rendered = + { title = staticPayload.metadata.title , body = Element.column [ Element.width Element.fill ] [ Element.column @@ -116,19 +115,19 @@ view allMetadata model blogPost rendered = ] (Element.column [ Element.spacing 10 ] [ Element.row [ Element.spacing 10 ] - [ Author.view [] blogPost.author + [ Author.view [] staticPayload.metadata.author , Element.column [ Element.spacing 10, Element.width Element.fill ] [ Element.paragraph [ Font.bold, Font.size 24 ] - [ Element.text blogPost.author.name + [ Element.text staticPayload.metadata.author.name ] , Element.paragraph [ Font.size 16 ] - [ Element.text blogPost.author.bio ] + [ Element.text staticPayload.metadata.author.bio ] ] ] ] - :: (publishedDateView blogPost |> Element.el [ Font.size 16, Font.color (Element.rgba255 0 0 0 0.6) ]) - :: Palette.blogHeading blogPost.title - :: articleImageView blogPost.image + :: (publishedDateView staticPayload.metadata |> Element.el [ Font.size 16, Font.color (Element.rgba255 0 0 0 0.6) ]) + :: Palette.blogHeading staticPayload.metadata.title + :: articleImageView staticPayload.metadata.image :: Tuple.second rendered |> List.map (Element.map never) ) diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 19243044..de41bc0c 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -16,8 +16,7 @@ import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Palette import SiteConfig -import Template -import TemplateDocument exposing (TemplateDocument) +import Template exposing (DynamicPayload, StaticPayload, Template) import TemplateMetadata exposing (Documentation) @@ -33,7 +32,7 @@ type Msg = Increment -template : TemplateDocument Documentation StaticData Model Msg +template : Template Documentation StaticData Model Msg GlobalMetadata.Metadata template = Template.template { view = view @@ -86,24 +85,22 @@ head static currentPath meta = view : - Global.Model + DynamicPayload Model -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) - -> StaticData - -> Model - -> Documentation + -> StaticPayload Documentation StaticData -> Global.RenderedBody - -> { title : String, body : Element Msg } -view globalModel allMetadata static model metadata rendered = - { title = metadata.title + -> Global.PageView Msg +view dynamicPayload allMetadata staticPayload rendered = + { title = staticPayload.metadata.title , body = [ Element.row [] - [ counterView globalModel + [ counterView dynamicPayload.globalModel , DocSidebar.view Pages.pages.index allMetadata |> Element.el [ Element.width (Element.fillPortion 2), Element.alignTop, Element.height Element.fill ] , Element.column [ Element.width (Element.fillPortion 8), Element.padding 35, Element.spacing 15 ] - [ Palette.heading 1 [ Element.text metadata.title ] + [ Palette.heading 1 [ Element.text staticPayload.metadata.title ] , Element.column [ Element.spacing 20 ] [ tocView (Tuple.first rendered) , Element.column diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index 60e2dbe6..03cf9171 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -11,8 +11,7 @@ import Pages exposing (images) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import SiteConfig -import Template -import TemplateDocument exposing (TemplateDocument) +import Template exposing (StaticPayload, Template) import TemplateMetadata exposing (Page) @@ -28,7 +27,7 @@ type Msg = Msg -template : TemplateDocument Page StaticData Model Msg +template : Template Page () () Msg GlobalMetadata.Metadata template = Template.simplest { view = view @@ -77,12 +76,11 @@ head currentPath meta = view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) - -> Model - -> Page + -> StaticPayload Page () -> Global.RenderedBody -> { title : String, body : Element Msg } -view allMetadata model metadata rendered = - { title = metadata.title +view allMetadata staticPayload rendered = + { title = staticPayload.metadata.title , body = [ Element.column [ Element.padding 50 diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index c2f2455d..468871c4 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -10,8 +10,7 @@ import Pages exposing (images) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Showcase -import Template -import TemplateDocument exposing (TemplateDocument) +import Template exposing (StaticPayload, Template) import TemplateMetadata exposing (Showcase) @@ -23,7 +22,7 @@ type Msg = Msg -template : TemplateDocument Showcase StaticData Model Msg +template : Template Showcase StaticData () Msg GlobalMetadata.Metadata template = Template.stateless { view = view @@ -48,15 +47,14 @@ type alias StaticData = view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) - -> StaticData - -> Showcase + -> StaticPayload Showcase StaticData -> Global.RenderedBody - -> { title : String, body : Element Msg } -view allMetadata static metadata rendered = + -> Global.PageView msg +view allMetadata static rendered = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] - [ Element.column [ Element.padding 20, Element.centerX ] [ Showcase.view static ] + [ Element.column [ Element.padding 20, Element.centerX ] [ Showcase.view static.static ] ] } diff --git a/examples/docs/src/TemplateDocument.elm b/examples/docs/src/TemplateDocument.elm deleted file mode 100644 index 3278b8d3..00000000 --- a/examples/docs/src/TemplateDocument.elm +++ /dev/null @@ -1,22 +0,0 @@ -module TemplateDocument exposing (..) - -import Browser -import Element exposing (Element) -import Global -import GlobalMetadata -import Html exposing (Html) -import MarkdownRenderer -import Pages -import Template exposing (Template) - - -type alias View msg = - { title : String, body : Element msg } - - -type alias RenderedBody msg = - ( MarkdownRenderer.TableOfContents, List (Element msg) ) - - -type alias TemplateDocument templateMetadata templateStaticData templateModel templateMsg = - Template Pages.PathKey templateMetadata Global.RenderedBody templateStaticData templateModel (View templateMsg) templateMsg GlobalMetadata.Metadata diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index d67f940a..f3f62828 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -74,11 +74,14 @@ view siteMetadata page = case model.page of Model${name} subModel -> Template.${name}.template.view - model.global + { model = subModel + , globalModel = model.global + } siteMetadata - data - subModel - metadata + { static = data + , metadata = metadata + , path = page.path + } rendered |> (\\{ title, body } -> Global.view From 40614be38f3644b62c9a0c42f4ac29d20fd24636 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 6 Sep 2020 12:29:46 -0700 Subject: [PATCH 059/106] Pass in global static in static bundle. --- examples/docs/src/Template.elm | 3 +-- generator/src/generate-template-module-connector.js | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 0db69456..38dca75e 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -136,8 +136,7 @@ type alias Template templateMetadata templateStaticData templateModel templateMs type alias StaticPayload metadata staticData = { static : staticData - - --, globalStatic : Global.StaticData + , globalStatic : Global.StaticData , metadata : metadata , path : PagePath Pages.PathKey } diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index f3f62828..f7d6bf1a 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -79,6 +79,7 @@ view siteMetadata page = } siteMetadata { static = data + , globalStatic = globalData , metadata = metadata , path = page.path } From d6790c479c349692ffa8c7f825e359e6169f5b9e Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 6 Sep 2020 12:42:05 -0700 Subject: [PATCH 060/106] Use static payload for head function. --- examples/docs/src/Template.elm | 22 +++++----------- examples/docs/src/Template/BlogIndex.elm | 4 +-- examples/docs/src/Template/BlogPost.elm | 26 +++++++++---------- examples/docs/src/Template/Documentation.elm | 6 ++--- examples/docs/src/Template/Page.elm | 6 ++--- examples/docs/src/Template/Showcase.elm | 4 +-- .../src/generate-template-module-connector.js | 7 ++++- 7 files changed, 36 insertions(+), 39 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 38dca75e..94f403e4 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -14,8 +14,7 @@ simplest : -> Global.RenderedBody -> Global.PageView templateMsg , head : - PagePath Pages.PathKey - -> templateMetadata + StaticPayload templateMetadata () -> List (Head.Tag Pages.PathKey) } -> Template templateMetadata () () templateMsg globalMetadata @@ -24,7 +23,7 @@ simplest config = { view = \dynamicPayload allMetadata staticPayload rendered -> config.view allMetadata staticPayload rendered - , head = \() -> config.head + , head = config.head , staticData = \_ -> StaticHttp.succeed () , init = \_ -> ( (), Cmd.none ) , update = \_ _ _ -> ( (), Cmd.none, Global.NoOp ) @@ -39,8 +38,7 @@ simpler : -> Global.RenderedBody -> Global.PageView templateMsg , head : - PagePath Pages.PathKey - -> templateMetadata + StaticPayload templateMetadata () -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) @@ -51,7 +49,7 @@ simpler config = { view = \dynamicPayload allMetadata staticPayload rendered -> config.view allMetadata staticPayload dynamicPayload.model rendered - , head = \() -> config.head + , head = config.head , staticData = \_ -> StaticHttp.succeed () , init = config.init , update = \a1 b1 c1 -> config.update a1 b1 c1 |> (\( a, b ) -> ( a, b, Global.NoOp )) @@ -68,9 +66,7 @@ stateless : -> Global.RenderedBody -> Global.PageView templateMsg , head : - templateStaticData - -> PagePath Pages.PathKey - -> templateMetadata + StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) } -> Template templateMetadata templateStaticData () templateMsg globalMetadata @@ -97,9 +93,7 @@ template : -> Global.RenderedBody -> Global.PageView templateMsg , head : - templateStaticData - -> PagePath Pages.PathKey - -> templateMetadata + StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Global.GlobalMsg ) @@ -125,9 +119,7 @@ type alias Template templateMetadata templateStaticData templateModel templateMs -> Global.RenderedBody -> Global.PageView templateMsg , head : - templateStaticData - -> PagePath Pages.PathKey - -> templateMetadata + StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Global.GlobalMsg ) diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 5ccd7f87..87a4e369 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -70,8 +70,8 @@ view dynamicPayload allMetadata staticPayload rendered = } -head : StaticData -> PagePath.PagePath Pages.PathKey -> BlogIndex -> List (Head.Tag Pages.PathKey) -head static currentPath metadata = +head : StaticPayload BlogIndex StaticData -> List (Head.Tag Pages.PathKey) +head staticPayload = Seo.summary { canonicalUrlOverride = Nothing , siteName = "elm-pages" diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 85aebd6a..dad1c212 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -135,17 +135,17 @@ view allMetadata staticPayload model rendered = } -head : PagePath.PagePath Pages.PathKey -> BlogPost -> List (Head.Tag Pages.PathKey) -head currentPath meta = +head : StaticPayload BlogPost () -> List (Head.Tag Pages.PathKey) +head staticPayload = Head.structuredData (StructuredData.article - { title = meta.title - , description = meta.description - , author = StructuredData.person { name = meta.author.name } + { title = staticPayload.metadata.title + , description = staticPayload.metadata.description + , author = StructuredData.person { name = staticPayload.metadata.author.name } , publisher = StructuredData.person { name = "Dillon Kearns" } - , url = SiteConfig.canonicalUrl ++ "/" ++ PagePath.toString currentPath - , imageUrl = SiteConfig.canonicalUrl ++ "/" ++ ImagePath.toString meta.image - , datePublished = Date.toIsoString meta.published + , url = SiteConfig.canonicalUrl ++ "/" ++ PagePath.toString staticPayload.path + , imageUrl = SiteConfig.canonicalUrl ++ "/" ++ ImagePath.toString staticPayload.metadata.image + , datePublished = Date.toIsoString staticPayload.metadata.published , mainEntityOfPage = StructuredData.softwareSourceCode { codeRepositoryUrl = "https://github.com/dillonkearns/elm-pages" @@ -159,19 +159,19 @@ head currentPath meta = { canonicalUrlOverride = Nothing , siteName = "elm-pages" , image = - { url = meta.image - , alt = meta.description + { url = staticPayload.metadata.image + , alt = staticPayload.metadata.description , dimensions = Nothing , mimeType = Nothing } - , description = meta.description + , description = staticPayload.metadata.description , locale = Nothing - , title = meta.title + , title = staticPayload.metadata.title } |> Seo.article { tags = [] , section = Nothing - , publishedTime = Just (Date.toIsoString meta.published) + , publishedTime = Just (Date.toIsoString staticPayload.metadata.published) , modifiedTime = Nothing , expirationTime = Nothing } diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index de41bc0c..b7f54135 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -66,8 +66,8 @@ decoder = (Decode.field "title" Decode.string) -head : StaticData -> PagePath.PagePath Pages.PathKey -> Documentation -> List (Head.Tag Pages.PathKey) -head static currentPath meta = +head : StaticPayload Documentation StaticData -> List (Head.Tag Pages.PathKey) +head staticPayload = Seo.summary { canonicalUrlOverride = Nothing , siteName = "elm-pages" @@ -79,7 +79,7 @@ head static currentPath meta = } , description = SiteConfig.tagline , locale = Nothing - , title = meta.title + , title = staticPayload.metadata.title } |> Seo.website diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index 03cf9171..56ac0307 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -56,8 +56,8 @@ decoder = (Decode.field "title" Decode.string) -head : PagePath.PagePath Pages.PathKey -> Page -> List (Head.Tag Pages.PathKey) -head currentPath meta = +head : StaticPayload Page () -> List (Head.Tag Pages.PathKey) +head staticPayload = Seo.summary { canonicalUrlOverride = Nothing , siteName = "elm-pages" @@ -69,7 +69,7 @@ head currentPath meta = } , description = SiteConfig.tagline , locale = Nothing - , title = meta.title + , title = staticPayload.metadata.title } |> Seo.website diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index 468871c4..3588fe7a 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -59,8 +59,8 @@ view allMetadata static rendered = } -head : StaticData -> PagePath.PagePath Pages.PathKey -> Showcase -> List (Head.Tag Pages.PathKey) -head static currentPath metadata = +head : StaticPayload Showcase StaticData -> List (Head.Tag Pages.PathKey) +head staticPayload = Seo.summary { canonicalUrlOverride = Nothing , siteName = "elm-pages" diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index f7d6bf1a..d8f11491 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -97,7 +97,12 @@ view siteMetadata page = _ -> { title = "", body = Html.text "" } - , head = Template.${name}.template.head data page.path metadata + , head = Template.${name}.template.head + { static = data + , globalStatic = globalData + , metadata = metadata + , path = page.path + } } ) (Template.${name}.template.staticData siteMetadata) From e4c8c0a578cb1282f8133172ead004a31e167149 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 6 Sep 2020 13:00:35 -0700 Subject: [PATCH 061/106] Remove a type variable. --- examples/docs/src/Template.elm | 27 ++++++++++---------- examples/docs/src/Template/BlogIndex.elm | 2 +- examples/docs/src/Template/BlogPost.elm | 2 +- examples/docs/src/Template/Documentation.elm | 2 +- examples/docs/src/Template/Page.elm | 2 +- examples/docs/src/Template/Showcase.elm | 2 +- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 94f403e4..5eedcc53 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -1,6 +1,7 @@ module Template exposing (..) import Global +import GlobalMetadata import Head import Pages import Pages.PagePath exposing (PagePath) @@ -9,7 +10,7 @@ import Pages.StaticHttp as StaticHttp simplest : { view : - List ( PagePath Pages.PathKey, globalMetadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload templateMetadata () -> Global.RenderedBody -> Global.PageView templateMsg @@ -17,7 +18,7 @@ simplest : StaticPayload templateMetadata () -> List (Head.Tag Pages.PathKey) } - -> Template templateMetadata () () templateMsg globalMetadata + -> Template templateMetadata () () templateMsg simplest config = template { view = @@ -32,7 +33,7 @@ simplest config = simpler : { view : - List ( PagePath Pages.PathKey, globalMetadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload templateMetadata () -> templateModel -> Global.RenderedBody @@ -43,7 +44,7 @@ simpler : , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) } - -> Template templateMetadata () templateModel templateMsg globalMetadata + -> Template templateMetadata () templateModel templateMsg simpler config = template { view = @@ -58,10 +59,10 @@ simpler config = stateless : { staticData : - List ( PagePath Pages.PathKey, globalMetadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticHttp.Request templateStaticData , view : - List ( PagePath Pages.PathKey, globalMetadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload templateMetadata templateStaticData -> Global.RenderedBody -> Global.PageView templateMsg @@ -69,7 +70,7 @@ stateless : StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) } - -> Template templateMetadata templateStaticData () templateMsg globalMetadata + -> Template templateMetadata templateStaticData () templateMsg stateless config = template { view = @@ -84,11 +85,11 @@ stateless config = template : { staticData : - List ( PagePath Pages.PathKey, globalMetadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticHttp.Request templateStaticData , view : DynamicPayload templateModel - -> List ( PagePath Pages.PathKey, globalMetadata ) + -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload templateMetadata templateStaticData -> Global.RenderedBody -> Global.PageView templateMsg @@ -98,7 +99,7 @@ template : , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Global.GlobalMsg ) } - -> Template templateMetadata templateStaticData templateModel templateMsg globalMetadata + -> Template templateMetadata templateStaticData templateModel templateMsg template config = { view = config.view , head = config.head @@ -108,13 +109,13 @@ template config = } -type alias Template templateMetadata templateStaticData templateModel templateMsg globalMetadata = +type alias Template templateMetadata templateStaticData templateModel templateMsg = { staticData : - List ( PagePath Pages.PathKey, globalMetadata ) + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticHttp.Request templateStaticData , view : DynamicPayload templateModel - -> List ( PagePath Pages.PathKey, globalMetadata ) + -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload templateMetadata templateStaticData -> Global.RenderedBody -> Global.PageView templateMsg diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 87a4e369..a68a7cfb 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -19,7 +19,7 @@ type Msg = Msg -template : Template BlogIndex StaticData Model Msg GlobalMetadata.Metadata +template : Template BlogIndex StaticData Model Msg template = Template.template { view = view diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index dad1c212..6a7649ff 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -29,7 +29,7 @@ type Msg = Msg -template : Template BlogPost () Model Msg GlobalMetadata.Metadata +template : Template BlogPost () Model Msg template = Template.simpler { view = view diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index b7f54135..ac2a557e 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -32,7 +32,7 @@ type Msg = Increment -template : Template Documentation StaticData Model Msg GlobalMetadata.Metadata +template : Template Documentation StaticData Model Msg template = Template.template { view = view diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index 56ac0307..d13e753e 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -27,7 +27,7 @@ type Msg = Msg -template : Template Page () () Msg GlobalMetadata.Metadata +template : Template Page () () Msg template = Template.simplest { view = view diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index 3588fe7a..a7e4b292 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -22,7 +22,7 @@ type Msg = Msg -template : Template Showcase StaticData () Msg GlobalMetadata.Metadata +template : Template Showcase StaticData () Msg template = Template.stateless { view = view From d5b2a9df09b700b5d6dd9da53670cbe96d52c3ef Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 6 Sep 2020 13:03:46 -0700 Subject: [PATCH 062/106] Clean up some type annotations. --- examples/docs/src/Template/BlogIndex.elm | 4 +++- examples/docs/src/Template/Documentation.elm | 4 +++- examples/docs/src/Template/Page.elm | 6 ++++-- examples/docs/src/Template/Showcase.elm | 4 +++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index a68a7cfb..e3d25df9 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -30,7 +30,9 @@ template = } -staticData : a -> StaticHttp.Request StaticData +staticData : + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> StaticHttp.Request StaticData staticData siteMetadata = Showcase.staticRequest diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index ac2a557e..eb3be223 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -55,7 +55,9 @@ update metadata msg model = ( model, Cmd.none, Global.IncrementFromChild ) -staticData : a -> StaticHttp.Request StaticData +staticData : + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> StaticHttp.Request StaticData staticData siteMetadata = StaticHttp.succeed () diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index d13e753e..1593a51f 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -45,7 +45,9 @@ update metadata msg model = ( (), Cmd.none ) -staticData : a -> StaticHttp.Request StaticData +staticData : + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> StaticHttp.Request StaticData staticData siteMetadata = StaticHttp.succeed () @@ -78,7 +80,7 @@ view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload Page () -> Global.RenderedBody - -> { title : String, body : Element Msg } + -> Global.PageView Msg view allMetadata staticPayload rendered = { title = staticPayload.metadata.title , body = diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index a7e4b292..fab5fba4 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -36,7 +36,9 @@ decoder = Decode.succeed Showcase -staticData : a -> StaticHttp.Request StaticData +staticData : + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> StaticHttp.Request StaticData staticData siteMetadata = Showcase.staticRequest From 384d80798a42b993735f4af9da6e2ac4c1afbf76 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 6 Sep 2020 13:12:30 -0700 Subject: [PATCH 063/106] Remove unused. --- examples/docs/src/Global.elm | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Global.elm index 3dc184ca..b22e3501 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Global.elm @@ -39,16 +39,6 @@ map fn doc = } - ---mapRendered : (msg1 -> msg2) -> RenderedBody msg1 -> RenderedBody msg2 ---mapRendered fn ( first, second ) = --- ( first, second |> List.map (Element.map fn) ) - - -type alias View msg = - ( MarkdownRenderer.TableOfContents, List (Element msg) ) - - type alias RenderedBody = ( MarkdownRenderer.TableOfContents, List (Element Never) ) From 9a4fd9a3f30df8022b1746c7822fb0667e7bb1cd Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 6 Sep 2020 13:12:55 -0700 Subject: [PATCH 064/106] Remove unused import. --- generator/src/generate-template-module-connector.js | 1 - 1 file changed, 1 deletion(-) diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index d8f11491..31494bc1 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -16,7 +16,6 @@ import Pages import Pages.PagePath exposing (PagePath) import Pages.Platform import Pages.StaticHttp as StaticHttp -import SiteConfig ${templates.map(name => `import Template.${name}`).join("\n")} From 8c2fc23112cbd095473b03ee4e41b951509e2a58 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 6 Sep 2020 13:29:19 -0700 Subject: [PATCH 065/106] Remove unused, restore some file generators. --- examples/docs/src/Main.elm | 76 +++++++++++--------------------------- 1 file changed, 21 insertions(+), 55 deletions(-) diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 6d8b3d78..96074e0b 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -2,33 +2,21 @@ module Main exposing (main) import Color import Data.Author -import Date -import DocSidebar -import DocumentSvg import Element exposing (Element) -import Element.Events import Element.Font as Font -import Element.Region -import FontAwesome import Global import GlobalMetadata -import Head -import Head.Seo as Seo -import Html.Attributes as Attr import MarkdownRenderer -import Metadata exposing (Metadata) import MetadataNew +import MySitemap import Pages exposing (images, pages) -import Pages.Directory as Directory exposing (Directory) -import Pages.ImagePath as ImagePath exposing (ImagePath) import Pages.Manifest as Manifest import Pages.Manifest.Category import Pages.PagePath as PagePath exposing (PagePath) import Pages.Platform exposing (Page) -import Palette import Rss +import RssPlugin import SiteConfig -import StructuredData import TemplateDemultiplexer @@ -61,60 +49,38 @@ main = , canonicalSiteUrl = SiteConfig.canonicalUrl , subscriptions = \_ -> Sub.none } + |> RssPlugin.generate + { siteTagline = siteTagline + , siteUrl = canonicalSiteUrl + , title = "elm-pages Blog" + , builtAt = Pages.builtAt + , indexPage = Pages.pages.blog.index + } + metadataToRssItem + |> MySitemap.install { siteUrl = canonicalSiteUrl } metadataToSitemapEntry |> Pages.Platform.toProgram - ---main : Pages.Platform.Program Model Msg Metadata View ---main = --- Pages.Platform.init --- { init = init --- , view = view --- , update = update --- , subscriptions = subscriptions --- , documents = --- [ { extension = "md" --- , metadata = Metadata.decoder --- , body = MarkdownRenderer.view --- } --- ] --- , onPageChange = Just OnPageChange --- , manifest = manifest --- , canonicalSiteUrl = canonicalSiteUrl --- , internals = Pages.internals --- } --- |> RssPlugin.generate --- { siteTagline = siteTagline --- , siteUrl = canonicalSiteUrl --- , title = "elm-pages Blog" --- , builtAt = Pages.builtAt --- , indexPage = Pages.pages.blog.index --- } --- metadataToRssItem --- |> MySitemap.install { siteUrl = canonicalSiteUrl } metadataToSitemapEntry --- |> Pages.Platform.toProgram - - metadataToRssItem : { path : PagePath Pages.PathKey - , frontmatter : Metadata + , frontmatter : GlobalMetadata.Metadata , body : String } -> Maybe Rss.Item metadataToRssItem page = case page.frontmatter of - Metadata.Article article -> - if article.draft then + GlobalMetadata.MetadataBlogPost blogPost -> + if blogPost.draft then Nothing else Just - { title = article.title - , description = article.description + { title = blogPost.title + , description = blogPost.description , url = PagePath.toString page.path , categories = [] - , author = article.author.name - , pubDate = Rss.Date article.published + , author = blogPost.author.name + , pubDate = Rss.Date blogPost.published , content = Nothing } @@ -125,7 +91,7 @@ metadataToRssItem page = metadataToSitemapEntry : List { path : PagePath Pages.PathKey - , frontmatter : Metadata + , frontmatter : GlobalMetadata.Metadata , body : String } -> List { path : String, lastMod : Maybe String } @@ -134,8 +100,8 @@ metadataToSitemapEntry siteMetadata = |> List.filter (\page -> case page.frontmatter of - Metadata.Article articleData -> - not articleData.draft + GlobalMetadata.MetadataBlogPost blogPost -> + not blogPost.draft _ -> True From 417849bb098843d90648b105e98208b844e8085e Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 6 Sep 2020 13:32:29 -0700 Subject: [PATCH 066/106] Remove unused. --- examples/docs/src/Main.elm | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 96074e0b..76a0c893 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -1,6 +1,5 @@ module Main exposing (main) -import Color import Data.Author import Element exposing (Element) import Element.Font as Font @@ -9,9 +8,7 @@ import GlobalMetadata import MarkdownRenderer import MetadataNew import MySitemap -import Pages exposing (images, pages) -import Pages.Manifest as Manifest -import Pages.Manifest.Category +import Pages import Pages.PagePath as PagePath exposing (PagePath) import Pages.Platform exposing (Page) import Rss @@ -20,22 +17,6 @@ import SiteConfig import TemplateDemultiplexer -manifest : Manifest.Config Pages.PathKey -manifest = - { backgroundColor = Just Color.white - , categories = [ Pages.Manifest.Category.education ] - , displayMode = Manifest.Standalone - , orientation = Manifest.Portrait - , description = "elm-pages - A statically typed site generator." - , iarcRatingId = Nothing - , name = "elm-pages docs" - , themeColor = Just Color.white - , startUrl = pages.blog.staticHttp - , shortName = Just "elm-pages" - , sourceIcon = images.iconPng - } - - main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg GlobalMetadata.Metadata Global.RenderedBody main = TemplateDemultiplexer.mainTemplate @@ -50,14 +31,14 @@ main = , subscriptions = \_ -> Sub.none } |> RssPlugin.generate - { siteTagline = siteTagline - , siteUrl = canonicalSiteUrl + { siteTagline = SiteConfig.tagline + , siteUrl = SiteConfig.canonicalUrl , title = "elm-pages Blog" , builtAt = Pages.builtAt , indexPage = Pages.pages.blog.index } metadataToRssItem - |> MySitemap.install { siteUrl = canonicalSiteUrl } metadataToSitemapEntry + |> MySitemap.install { siteUrl = SiteConfig.canonicalUrl } metadataToSitemapEntry |> Pages.Platform.toProgram @@ -136,16 +117,6 @@ update msg model = ( { model | showMobileMenu = not model.showMobileMenu }, Cmd.none ) -canonicalSiteUrl : String -canonicalSiteUrl = - "https://elm-pages.com" - - -siteTagline : String -siteTagline = - "A statically typed site generator - elm-pages" - - tocView : MarkdownRenderer.TableOfContents -> Element msg tocView toc = Element.column [ Element.alignTop, Element.spacing 20 ] From b762c655a436be96f28d72aadc26312781ac9809 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 6 Sep 2020 13:34:41 -0700 Subject: [PATCH 067/106] Rename module. --- examples/docs/src/Main.elm | 12 ++++++------ examples/docs/src/{SiteConfig.elm => Site.elm} | 2 +- examples/docs/src/Template/BlogIndex.elm | 4 ++-- examples/docs/src/Template/BlogPost.elm | 6 +++--- examples/docs/src/Template/Documentation.elm | 4 ++-- examples/docs/src/Template/Page.elm | 4 ++-- generator/src/generate-template-module-connector.js | 4 ++-- tests/__snapshots__/generated-files.test.js.snap | 6 +++--- tests/src/Template/BlogPost.elm | 6 +++--- 9 files changed, 24 insertions(+), 24 deletions(-) rename examples/docs/src/{SiteConfig.elm => Site.elm} (95%) diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 76a0c893..b135bbb8 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -13,7 +13,7 @@ import Pages.PagePath as PagePath exposing (PagePath) import Pages.Platform exposing (Page) import Rss import RssPlugin -import SiteConfig +import Site import TemplateDemultiplexer @@ -26,19 +26,19 @@ main = , body = MarkdownRenderer.view } ] - , manifest = SiteConfig.manifest - , canonicalSiteUrl = SiteConfig.canonicalUrl + , manifest = Site.manifest + , canonicalSiteUrl = Site.canonicalUrl , subscriptions = \_ -> Sub.none } |> RssPlugin.generate - { siteTagline = SiteConfig.tagline - , siteUrl = SiteConfig.canonicalUrl + { siteTagline = Site.tagline + , siteUrl = Site.canonicalUrl , title = "elm-pages Blog" , builtAt = Pages.builtAt , indexPage = Pages.pages.blog.index } metadataToRssItem - |> MySitemap.install { siteUrl = SiteConfig.canonicalUrl } metadataToSitemapEntry + |> MySitemap.install { siteUrl = Site.canonicalUrl } metadataToSitemapEntry |> Pages.Platform.toProgram diff --git a/examples/docs/src/SiteConfig.elm b/examples/docs/src/Site.elm similarity index 95% rename from examples/docs/src/SiteConfig.elm rename to examples/docs/src/Site.elm index 8b6d9dab..260ee833 100644 --- a/examples/docs/src/SiteConfig.elm +++ b/examples/docs/src/Site.elm @@ -1,4 +1,4 @@ -module SiteConfig exposing (..) +module Site exposing (..) import Color import Pages exposing (images, pages) diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index e3d25df9..c9542e0a 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -10,7 +10,7 @@ import Pages exposing (images) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Showcase -import SiteConfig +import Site import Template exposing (DynamicPayload, StaticPayload, Template) import TemplateMetadata exposing (BlogIndex) @@ -83,7 +83,7 @@ head staticPayload = , dimensions = Nothing , mimeType = Nothing } - , description = SiteConfig.tagline + , description = Site.tagline , locale = Nothing , title = "elm-pages blog" } diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 6a7649ff..4a11ab32 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -15,7 +15,7 @@ import Pages import Pages.ImagePath as ImagePath exposing (ImagePath) import Pages.PagePath as PagePath exposing (PagePath) import Palette -import SiteConfig +import Site import StructuredData import Template exposing (DynamicPayload, StaticPayload, Template) import TemplateMetadata exposing (BlogPost) @@ -143,8 +143,8 @@ head staticPayload = , description = staticPayload.metadata.description , author = StructuredData.person { name = staticPayload.metadata.author.name } , publisher = StructuredData.person { name = "Dillon Kearns" } - , url = SiteConfig.canonicalUrl ++ "/" ++ PagePath.toString staticPayload.path - , imageUrl = SiteConfig.canonicalUrl ++ "/" ++ ImagePath.toString staticPayload.metadata.image + , url = Site.canonicalUrl ++ "/" ++ PagePath.toString staticPayload.path + , imageUrl = Site.canonicalUrl ++ "/" ++ ImagePath.toString staticPayload.metadata.image , datePublished = Date.toIsoString staticPayload.metadata.published , mainEntityOfPage = StructuredData.softwareSourceCode diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index eb3be223..4be1eeab 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -15,7 +15,7 @@ import Pages exposing (images) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Palette -import SiteConfig +import Site import Template exposing (DynamicPayload, StaticPayload, Template) import TemplateMetadata exposing (Documentation) @@ -79,7 +79,7 @@ head staticPayload = , dimensions = Nothing , mimeType = Nothing } - , description = SiteConfig.tagline + , description = Site.tagline , locale = Nothing , title = staticPayload.metadata.title } diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index 1593a51f..acd35885 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -10,7 +10,7 @@ import Json.Decode as Decode import Pages exposing (images) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp -import SiteConfig +import Site import Template exposing (StaticPayload, Template) import TemplateMetadata exposing (Page) @@ -69,7 +69,7 @@ head staticPayload = , dimensions = Nothing , mimeType = Nothing } - , description = SiteConfig.tagline + , description = Site.tagline , locale = Nothing , title = staticPayload.metadata.title } diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 31494bc1..f89573c0 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -208,8 +208,8 @@ mainTemplate { documents, manifest, canonicalSiteUrl, subscriptions } = , subscriptions = subscriptions , documents = documents , onPageChange = Just OnPageChange - , manifest = manifest -- SiteConfig.manifest - , canonicalSiteUrl = canonicalSiteUrl -- SiteConfig.canonicalUrl + , manifest = manifest -- Site.manifest + , canonicalSiteUrl = canonicalSiteUrl -- Site.canonicalUrl , internals = Pages.internals } diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index 571784cc..c3e1d0f9 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -126,7 +126,7 @@ import Pages import Pages.PagePath exposing (PagePath) import Pages.Platform import Pages.StaticHttp as StaticHttp -import SiteConfig +import Site import Template.BlogIndex import Template.BlogPost import Template.Documentation @@ -611,8 +611,8 @@ mainTemplate { documents, manifest, canonicalSiteUrl, subscriptions } = , subscriptions = subscriptions , documents = documents , onPageChange = Just OnPageChange - , manifest = manifest -- SiteConfig.manifest - , canonicalSiteUrl = canonicalSiteUrl -- SiteConfig.canonicalUrl + , manifest = manifest -- Site.manifest + , canonicalSiteUrl = canonicalSiteUrl -- Site.canonicalUrl , internals = Pages.internals } diff --git a/tests/src/Template/BlogPost.elm b/tests/src/Template/BlogPost.elm index e13d9c08..d2c01fae 100644 --- a/tests/src/Template/BlogPost.elm +++ b/tests/src/Template/BlogPost.elm @@ -17,7 +17,7 @@ import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Palette import Secrets -import SiteConfig +import Site import StructuredData import Template import Template.Metadata exposing (BlogPost) @@ -151,8 +151,8 @@ head static currentPath meta = , description = meta.description , author = StructuredData.person { name = meta.author.name } , publisher = StructuredData.person { name = "Dillon Kearns" } - , url = SiteConfig.canonicalUrl ++ "/" ++ PagePath.toString currentPath - , imageUrl = SiteConfig.canonicalUrl ++ "/" ++ ImagePath.toString meta.image + , url = Site.canonicalUrl ++ "/" ++ PagePath.toString currentPath + , imageUrl = Site.canonicalUrl ++ "/" ++ ImagePath.toString meta.image , datePublished = Date.toIsoString meta.published , mainEntityOfPage = StructuredData.softwareSourceCode From e033c3796e02773f7e3124306baadc05e20281a4 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 6 Sep 2020 13:41:24 -0700 Subject: [PATCH 068/106] Remove unused code. --- examples/docs/src/Main.elm | 43 -------------------------------------- 1 file changed, 43 deletions(-) diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index b135bbb8..812cee0b 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -1,8 +1,6 @@ module Main exposing (main) import Data.Author -import Element exposing (Element) -import Element.Font as Font import Global import GlobalMetadata import MarkdownRenderer @@ -91,44 +89,3 @@ metadataToSitemapEntry siteMetadata = (\page -> { path = PagePath.toString page.path, lastMod = Nothing } ) - - -type alias Model = - { showMobileMenu : Bool - } - - -type Msg - = OnPageChange - { path : PagePath Pages.PathKey - , query : Maybe String - , fragment : Maybe String - } - | ToggleMobileMenu - - -update : Msg -> Model -> ( Model, Cmd Msg ) -update msg model = - case msg of - OnPageChange page -> - ( { model | showMobileMenu = False }, Cmd.none ) - - ToggleMobileMenu -> - ( { model | showMobileMenu = not model.showMobileMenu }, Cmd.none ) - - -tocView : MarkdownRenderer.TableOfContents -> Element msg -tocView toc = - Element.column [ Element.alignTop, Element.spacing 20 ] - [ Element.el [ Font.bold, Font.size 22 ] (Element.text "Table of Contents") - , Element.column [ Element.spacing 10 ] - (toc - |> List.map - (\heading -> - Element.link [ Font.color (Element.rgb255 100 100 100) ] - { url = "#" ++ heading.anchorId - , label = Element.text heading.name - } - ) - ) - ] From 6214964257fa379066cbae26ee2abbccef653a70 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 12 Sep 2020 09:15:24 -0700 Subject: [PATCH 069/106] Rename global to shared. --- .../docs/content/docs/directory-structure.md | 4 +- examples/docs/src/Main.elm | 4 +- examples/docs/src/{Global.elm => Shared.elm} | 4 +- examples/docs/src/Template.elm | 36 +++++++------- examples/docs/src/Template/BlogIndex.elm | 10 ++-- examples/docs/src/Template/BlogPost.elm | 6 +-- examples/docs/src/Template/Documentation.elm | 12 ++--- examples/docs/src/Template/Page.elm | 6 +-- examples/docs/src/Template/Showcase.elm | 6 +-- .../src/generate-template-module-connector.js | 22 ++++----- .../generated-files.test.js.snap | 48 +++++++++---------- 11 files changed, 79 insertions(+), 79 deletions(-) rename examples/docs/src/{Global.elm => Shared.elm} (98%) diff --git a/examples/docs/content/docs/directory-structure.md b/examples/docs/content/docs/directory-structure.md index 915097c4..1f0f01d1 100644 --- a/examples/docs/content/docs/directory-structure.md +++ b/examples/docs/content/docs/directory-structure.md @@ -131,8 +131,8 @@ Now say you navigate to `/catalog/sibelius`. Let's look at the `elm-pages archit * `update` - if you click the Carousel, the page's state gets updated. -### Global -`src/Global.elm` +### Shared +`src/Shared.elm` * `staticData` (loaded per-app, not per-page) * `View` - the data type that pages render to in your app * `view` - the top-level view function for your app diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 812cee0b..b5c01a27 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -1,7 +1,6 @@ module Main exposing (main) import Data.Author -import Global import GlobalMetadata import MarkdownRenderer import MetadataNew @@ -11,11 +10,12 @@ import Pages.PagePath as PagePath exposing (PagePath) import Pages.Platform exposing (Page) import Rss import RssPlugin +import Shared import Site import TemplateDemultiplexer -main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg GlobalMetadata.Metadata Global.RenderedBody +main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg GlobalMetadata.Metadata Shared.RenderedBody main = TemplateDemultiplexer.mainTemplate { documents = diff --git a/examples/docs/src/Global.elm b/examples/docs/src/Shared.elm similarity index 98% rename from examples/docs/src/Global.elm rename to examples/docs/src/Shared.elm index b22e3501..87f65abf 100644 --- a/examples/docs/src/Global.elm +++ b/examples/docs/src/Shared.elm @@ -1,4 +1,4 @@ -module Global exposing (..) +module Shared exposing (..) import DocumentSvg import Element exposing (Element) @@ -140,7 +140,7 @@ view stars page model toMsg pageView = incrementView : Model -> Element Msg incrementView model = - Element.el [ Element.Events.onClick Increment ] (Element.text <| "Global count: " ++ String.fromInt model.counter) + Element.el [ Element.Events.onClick Increment ] (Element.text <| "Shared count: " ++ String.fromInt model.counter) logoLinkMobile = diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 5eedcc53..66b41be5 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -1,19 +1,19 @@ module Template exposing (..) -import Global import GlobalMetadata import Head import Pages import Pages.PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp +import Shared simplest : { view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload templateMetadata () - -> Global.RenderedBody - -> Global.PageView templateMsg + -> Shared.RenderedBody + -> Shared.PageView templateMsg , head : StaticPayload templateMetadata () -> List (Head.Tag Pages.PathKey) @@ -27,7 +27,7 @@ simplest config = , head = config.head , staticData = \_ -> StaticHttp.succeed () , init = \_ -> ( (), Cmd.none ) - , update = \_ _ _ -> ( (), Cmd.none, Global.NoOp ) + , update = \_ _ _ -> ( (), Cmd.none, Shared.NoOp ) } @@ -36,8 +36,8 @@ simpler : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload templateMetadata () -> templateModel - -> Global.RenderedBody - -> Global.PageView templateMsg + -> Shared.RenderedBody + -> Shared.PageView templateMsg , head : StaticPayload templateMetadata () -> List (Head.Tag Pages.PathKey) @@ -53,7 +53,7 @@ simpler config = , head = config.head , staticData = \_ -> StaticHttp.succeed () , init = config.init - , update = \a1 b1 c1 -> config.update a1 b1 c1 |> (\( a, b ) -> ( a, b, Global.NoOp )) + , update = \a1 b1 c1 -> config.update a1 b1 c1 |> (\( a, b ) -> ( a, b, Shared.NoOp )) } @@ -64,8 +64,8 @@ stateless : , view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload templateMetadata templateStaticData - -> Global.RenderedBody - -> Global.PageView templateMsg + -> Shared.RenderedBody + -> Shared.PageView templateMsg , head : StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) @@ -79,7 +79,7 @@ stateless config = , head = config.head , staticData = config.staticData , init = \_ -> ( (), Cmd.none ) - , update = \_ _ _ -> ( (), Cmd.none, Global.NoOp ) + , update = \_ _ _ -> ( (), Cmd.none, Shared.NoOp ) } @@ -91,13 +91,13 @@ template : DynamicPayload templateModel -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload templateMetadata templateStaticData - -> Global.RenderedBody - -> Global.PageView templateMsg + -> Shared.RenderedBody + -> Shared.PageView templateMsg , head : StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Global.GlobalMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Shared.GlobalMsg ) } -> Template templateMetadata templateStaticData templateModel templateMsg template config = @@ -117,19 +117,19 @@ type alias Template templateMetadata templateStaticData templateModel templateMs DynamicPayload templateModel -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload templateMetadata templateStaticData - -> Global.RenderedBody - -> Global.PageView templateMsg + -> Shared.RenderedBody + -> Shared.PageView templateMsg , head : StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Global.GlobalMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Shared.GlobalMsg ) } type alias StaticPayload metadata staticData = { static : staticData - , globalStatic : Global.StaticData + , globalStatic : Shared.StaticData , metadata : metadata , path : PagePath Pages.PathKey } @@ -137,5 +137,5 @@ type alias StaticPayload metadata staticData = type alias DynamicPayload model = { model : model - , globalModel : Global.Model + , globalModel : Shared.Model } diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index c9542e0a..fa27f3d9 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -1,7 +1,6 @@ module Template.BlogIndex exposing (Model, Msg, template) import Element exposing (Element) -import Global import GlobalMetadata import Head import Head.Seo as Seo @@ -9,6 +8,7 @@ import Index import Pages exposing (images) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp +import Shared import Showcase import Site import Template exposing (DynamicPayload, StaticPayload, Template) @@ -46,9 +46,9 @@ init metadata = ( Model, Cmd.none ) -update : BlogIndex -> Msg -> Model -> ( Model, Cmd Msg, Global.GlobalMsg ) +update : BlogIndex -> Msg -> Model -> ( Model, Cmd Msg, Shared.GlobalMsg ) update metadata msg model = - ( Model, Cmd.none, Global.NoOp ) + ( Model, Cmd.none, Shared.NoOp ) type alias Model = @@ -59,8 +59,8 @@ view : DynamicPayload Model -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload BlogIndex StaticData - -> Global.RenderedBody - -> Global.PageView Msg + -> Shared.RenderedBody + -> Shared.PageView Msg view dynamicPayload allMetadata staticPayload rendered = { title = "elm-pages blog" , body = diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 4a11ab32..a1ff512d 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -5,7 +5,6 @@ import Date exposing (Date) import Element exposing (Element) import Element.Font as Font import Element.Region -import Global import GlobalMetadata import Head import Head.Seo as Seo @@ -15,6 +14,7 @@ import Pages import Pages.ImagePath as ImagePath exposing (ImagePath) import Pages.PagePath as PagePath exposing (PagePath) import Palette +import Shared import Site import StructuredData import Template exposing (DynamicPayload, StaticPayload, Template) @@ -100,8 +100,8 @@ view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload BlogPost () -> Model - -> Global.RenderedBody - -> Global.PageView Msg + -> Shared.RenderedBody + -> Shared.PageView Msg view allMetadata staticPayload model rendered = { title = staticPayload.metadata.title , body = diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 4be1eeab..6bc2b7b8 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -5,7 +5,6 @@ import Element exposing (Element) import Element.Events import Element.Font as Font import Element.Region -import Global import GlobalMetadata import Head import Head.Seo as Seo @@ -15,6 +14,7 @@ import Pages exposing (images) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Palette +import Shared import Site import Template exposing (DynamicPayload, StaticPayload, Template) import TemplateMetadata exposing (Documentation) @@ -48,11 +48,11 @@ init metadata = ( {}, Cmd.none ) -update : Documentation -> Msg -> Model -> ( Model, Cmd Msg, Global.GlobalMsg ) +update : Documentation -> Msg -> Model -> ( Model, Cmd Msg, Shared.GlobalMsg ) update metadata msg model = case msg of Increment -> - ( model, Cmd.none, Global.IncrementFromChild ) + ( model, Cmd.none, Shared.IncrementFromChild ) staticData : @@ -90,8 +90,8 @@ view : DynamicPayload Model -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload Documentation StaticData - -> Global.RenderedBody - -> Global.PageView Msg + -> Shared.RenderedBody + -> Shared.PageView Msg view dynamicPayload allMetadata staticPayload rendered = { title = staticPayload.metadata.title , body = @@ -122,7 +122,7 @@ view dynamicPayload allMetadata staticPayload rendered = } -counterView : Global.Model -> Element Msg +counterView : Shared.Model -> Element Msg counterView globalModel = Element.el [ Element.Events.onClick Increment ] (Element.text <| "Docs count: " ++ String.fromInt globalModel.counter) diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index acd35885..baa0d677 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -2,7 +2,6 @@ module Template.Page exposing (Model, Msg, decoder, template) import Element exposing (Element) import Element.Region -import Global import GlobalMetadata import Head import Head.Seo as Seo @@ -10,6 +9,7 @@ import Json.Decode as Decode import Pages exposing (images) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp +import Shared import Site import Template exposing (StaticPayload, Template) import TemplateMetadata exposing (Page) @@ -79,8 +79,8 @@ head staticPayload = view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload Page () - -> Global.RenderedBody - -> Global.PageView Msg + -> Shared.RenderedBody + -> Shared.PageView Msg view allMetadata staticPayload rendered = { title = staticPayload.metadata.title , body = diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index fab5fba4..5ad49c98 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -1,7 +1,6 @@ module Template.Showcase exposing (Model, Msg, decoder, template) import Element exposing (Element) -import Global import GlobalMetadata import Head import Head.Seo as Seo @@ -9,6 +8,7 @@ import Json.Decode as Decode exposing (Decoder) import Pages exposing (images) import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp +import Shared import Showcase import Template exposing (StaticPayload, Template) import TemplateMetadata exposing (Showcase) @@ -50,8 +50,8 @@ type alias StaticData = view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticPayload Showcase StaticData - -> Global.RenderedBody - -> Global.PageView msg + -> Shared.RenderedBody + -> Shared.PageView msg view allMetadata static rendered = { title = "elm-pages blog" , body = diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index f89573c0..3ea5c58f 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -8,7 +8,7 @@ function generateTemplateModuleConnector() { return `module TemplateDemultiplexer exposing (..) import Browser -import Global +import Shared import GlobalMetadata as M exposing (Metadata) import Head import Html exposing (Html) @@ -20,7 +20,7 @@ ${templates.map(name => `import Template.${name}`).join("\n")} type alias Model = - { global : Global.Model + { global : Shared.Model , page : TemplateModel , current : Maybe @@ -41,7 +41,7 @@ type TemplateModel type Msg - = MsgGlobal Global.Msg + = MsgGlobal Shared.Msg | OnPageChange { path : PagePath Pages.PathKey , query : Maybe String @@ -59,7 +59,7 @@ view : } -> StaticHttp.Request - { view : Model -> Global.RenderedBody -> { title : String, body : Html Msg } + { view : Model -> Shared.RenderedBody -> { title : String, body : Html Msg } , head : List (Head.Tag Pages.PathKey) } view siteMetadata page = @@ -84,13 +84,13 @@ view siteMetadata page = } rendered |> (\\{ title, body } -> - Global.view + Shared.view globalData page model.global MsgGlobal ({ title = title, body = body } - |> Global.map Msg${name} + |> Shared.map Msg${name} ) ) @@ -105,13 +105,13 @@ view siteMetadata page = } ) (Template.${name}.template.staticData siteMetadata) - (Global.staticData siteMetadata) + (Shared.staticData siteMetadata) `).join("\n\n ") } init : - Maybe Global.Model + Maybe Shared.Model -> Maybe { path : @@ -125,7 +125,7 @@ init : init currentGlobalModel maybePagePath = let ( globalModel, globalCmd ) = - currentGlobalModel |> Maybe.map (\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Global.init maybePagePath) + currentGlobalModel |> Maybe.map (\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Shared.init maybePagePath) ( templateModel, templateCmd ) = case maybePagePath |> Maybe.map .metadata of @@ -158,7 +158,7 @@ update msg model = MsgGlobal msg_ -> let ( globalModel, globalCmd ) = - Global.update msg_ model.global + Shared.update msg_ model.global in ( { model | global = globalModel } , globalCmd |> Cmd.map MsgGlobal @@ -187,7 +187,7 @@ update msg model = pageModel |> mapBoth Model${name} (Cmd.map Msg${name}) |> (\\( a, b, c ) -> - ( a, b, Global.update (Global.SharedMsg c) model.global ) + ( a, b, Shared.update (Shared.SharedMsg c) model.global ) ) _ -> diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index c3e1d0f9..fc97297d 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -118,7 +118,7 @@ exports[`generate template module connector 1`] = ` "module TemplateDemultiplexer exposing (..) import Browser -import Global +import Shared import GlobalMetadata as M exposing (Metadata) import Head import Html exposing (Html) @@ -135,7 +135,7 @@ import Template.Showcase type alias Model = - { global : Global.Model + { global : Shared.Model , page : TemplateModel , current : Maybe @@ -161,7 +161,7 @@ type TemplateModel type Msg - = MsgGlobal Global.Msg + = MsgGlobal Shared.Msg | OnPageChange { path : PagePath Pages.PathKey , query : Maybe String @@ -184,7 +184,7 @@ view : } -> StaticHttp.Request - { view : Model -> Global.RenderedBody -> { title : String, body : Html Msg } + { view : Model -> Shared.RenderedBody -> { title : String, body : Html Msg } , head : List (Head.Tag Pages.PathKey) } view siteMetadata page = @@ -203,13 +203,13 @@ view siteMetadata page = metadata rendered |> (\\\\{ title, body } -> - Global.view + Shared.view globalData page model.global MsgGlobal ({ title = title, body = body } - |> Global.map MsgBlogIndex + |> Shared.map MsgBlogIndex ) ) @@ -219,7 +219,7 @@ view siteMetadata page = } ) (Template.BlogIndex.template.staticData siteMetadata) - (Global.staticData siteMetadata) + (Shared.staticData siteMetadata) M.MetadataBlogPost metadata -> @@ -236,13 +236,13 @@ view siteMetadata page = metadata rendered |> (\\\\{ title, body } -> - Global.view + Shared.view globalData page model.global MsgGlobal ({ title = title, body = body } - |> Global.map MsgBlogPost + |> Shared.map MsgBlogPost ) ) @@ -252,7 +252,7 @@ view siteMetadata page = } ) (Template.BlogPost.template.staticData siteMetadata) - (Global.staticData siteMetadata) + (Shared.staticData siteMetadata) M.MetadataDocumentation metadata -> @@ -269,13 +269,13 @@ view siteMetadata page = metadata rendered |> (\\\\{ title, body } -> - Global.view + Shared.view globalData page model.global MsgGlobal ({ title = title, body = body } - |> Global.map MsgDocumentation + |> Shared.map MsgDocumentation ) ) @@ -285,7 +285,7 @@ view siteMetadata page = } ) (Template.Documentation.template.staticData siteMetadata) - (Global.staticData siteMetadata) + (Shared.staticData siteMetadata) M.MetadataPage metadata -> @@ -302,13 +302,13 @@ view siteMetadata page = metadata rendered |> (\\\\{ title, body } -> - Global.view + Shared.view globalData page model.global MsgGlobal ({ title = title, body = body } - |> Global.map MsgPage + |> Shared.map MsgPage ) ) @@ -318,7 +318,7 @@ view siteMetadata page = } ) (Template.Page.template.staticData siteMetadata) - (Global.staticData siteMetadata) + (Shared.staticData siteMetadata) M.MetadataShowcase metadata -> @@ -335,13 +335,13 @@ view siteMetadata page = metadata rendered |> (\\\\{ title, body } -> - Global.view + Shared.view globalData page model.global MsgGlobal ({ title = title, body = body } - |> Global.map MsgShowcase + |> Shared.map MsgShowcase ) ) @@ -351,12 +351,12 @@ view siteMetadata page = } ) (Template.Showcase.template.staticData siteMetadata) - (Global.staticData siteMetadata) + (Shared.staticData siteMetadata) init : - Maybe Global.Model + Maybe Shared.Model -> Maybe { path : @@ -370,7 +370,7 @@ init : init currentGlobalModel maybePagePath = let ( globalModel, globalCmd ) = - currentGlobalModel |> Maybe.map (\\\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Global.init maybePagePath) + currentGlobalModel |> Maybe.map (\\\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Shared.init maybePagePath) page = case maybePagePath |> Maybe.map .metadata of @@ -431,7 +431,7 @@ update msg model = MsgGlobal msg_ -> let ( globalModel, globalCmd ) = - Global.update msg_ model.global + Shared.update msg_ model.global ( templateModel, templateCmd ) = load globalModel model.page @@ -545,7 +545,7 @@ update msg model = -load : Global.Model -> TemplateModel -> ( TemplateModel, Cmd Msg ) +load : Shared.Model -> TemplateModel -> ( TemplateModel, Cmd Msg ) load globalModel model = case model of ModelBlogIndex m -> @@ -579,7 +579,7 @@ load globalModel model = -save : TemplateModel -> Global.Model -> Global.Model +save : TemplateModel -> Shared.Model -> Shared.Model save model globalModel= case model of ModelBlogIndex m -> From a9db326fa4def447c89cc446a56117fa2790a931 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 12 Sep 2020 09:16:56 -0700 Subject: [PATCH 070/106] Rename some global things to shared. --- examples/docs/src/Shared.elm | 4 +- examples/docs/src/Template.elm | 8 ++-- examples/docs/src/Template/BlogIndex.elm | 2 +- examples/docs/src/Template/Documentation.elm | 8 ++-- .../src/generate-template-module-connector.js | 14 +++---- .../generated-files.test.js.snap | 38 +++++++++---------- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/examples/docs/src/Shared.elm b/examples/docs/src/Shared.elm index 87f65abf..9c45e6b0 100644 --- a/examples/docs/src/Shared.elm +++ b/examples/docs/src/Shared.elm @@ -21,7 +21,7 @@ import Palette import Secrets -type GlobalMsg +type SharedMsg = NoOp | IncrementFromChild @@ -55,7 +55,7 @@ type Msg } | ToggleMobileMenu | Increment - | SharedMsg GlobalMsg + | SharedMsg SharedMsg init : a -> ( Model, Cmd Msg ) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 66b41be5..81f01c76 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -97,7 +97,7 @@ template : StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Shared.GlobalMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) } -> Template templateMetadata templateStaticData templateModel templateMsg template config = @@ -123,13 +123,13 @@ type alias Template templateMetadata templateStaticData templateModel templateMs StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Shared.GlobalMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) } type alias StaticPayload metadata staticData = { static : staticData - , globalStatic : Shared.StaticData + , sharedStatic : Shared.StaticData , metadata : metadata , path : PagePath Pages.PathKey } @@ -137,5 +137,5 @@ type alias StaticPayload metadata staticData = type alias DynamicPayload model = { model : model - , globalModel : Shared.Model + , sharedModel : Shared.Model } diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index fa27f3d9..bae7afbb 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -46,7 +46,7 @@ init metadata = ( Model, Cmd.none ) -update : BlogIndex -> Msg -> Model -> ( Model, Cmd Msg, Shared.GlobalMsg ) +update : BlogIndex -> Msg -> Model -> ( Model, Cmd Msg, Shared.SharedMsg ) update metadata msg model = ( Model, Cmd.none, Shared.NoOp ) diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 6bc2b7b8..d4e010aa 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -48,7 +48,7 @@ init metadata = ( {}, Cmd.none ) -update : Documentation -> Msg -> Model -> ( Model, Cmd Msg, Shared.GlobalMsg ) +update : Documentation -> Msg -> Model -> ( Model, Cmd Msg, Shared.SharedMsg ) update metadata msg model = case msg of Increment -> @@ -96,7 +96,7 @@ view dynamicPayload allMetadata staticPayload rendered = { title = staticPayload.metadata.title , body = [ Element.row [] - [ counterView dynamicPayload.globalModel + [ counterView dynamicPayload.sharedModel , DocSidebar.view Pages.pages.index allMetadata @@ -123,8 +123,8 @@ view dynamicPayload allMetadata staticPayload rendered = counterView : Shared.Model -> Element Msg -counterView globalModel = - Element.el [ Element.Events.onClick Increment ] (Element.text <| "Docs count: " ++ String.fromInt globalModel.counter) +counterView sharedModel = + Element.el [ Element.Events.onClick Increment ] (Element.text <| "Docs count: " ++ String.fromInt sharedModel.counter) tocView : MarkdownRenderer.TableOfContents -> Element msg diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 3ea5c58f..196c61eb 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -74,11 +74,11 @@ view siteMetadata page = Model${name} subModel -> Template.${name}.template.view { model = subModel - , globalModel = model.global + , sharedModel = model.global } siteMetadata { static = data - , globalStatic = globalData + , sharedStatic = globalData , metadata = metadata , path = page.path } @@ -98,7 +98,7 @@ view siteMetadata page = { title = "", body = Html.text "" } , head = Template.${name}.template.head { static = data - , globalStatic = globalData + , sharedStatic = globalData , metadata = metadata , path = page.path } @@ -124,7 +124,7 @@ init : -> ( Model, Cmd Msg ) init currentGlobalModel maybePagePath = let - ( globalModel, globalCmd ) = + ( sharedModel, globalCmd ) = currentGlobalModel |> Maybe.map (\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Shared.init maybePagePath) ( templateModel, templateCmd ) = @@ -140,7 +140,7 @@ init currentGlobalModel maybePagePath = `).join("\n ")} in - ( { global = globalModel + ( { global = sharedModel , page = templateModel , current = maybePagePath } @@ -157,10 +157,10 @@ update msg model = case msg of MsgGlobal msg_ -> let - ( globalModel, globalCmd ) = + ( sharedModel, globalCmd ) = Shared.update msg_ model.global in - ( { model | global = globalModel } + ( { model | global = sharedModel } , globalCmd |> Cmd.map MsgGlobal ) diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index fc97297d..c7a5469f 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -369,7 +369,7 @@ init : -> ( Model, Cmd Msg ) init currentGlobalModel maybePagePath = let - ( globalModel, globalCmd ) = + ( sharedModel, globalCmd ) = currentGlobalModel |> Maybe.map (\\\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Shared.init maybePagePath) page = @@ -411,9 +411,9 @@ init currentGlobalModel maybePagePath = ( templateModel, templateCmd ) = - load globalModel page + load sharedModel page in - ( { global = globalModel + ( { global = sharedModel , page = templateModel , current = maybePagePath } @@ -430,14 +430,14 @@ update msg model = case msg of MsgGlobal msg_ -> let - ( globalModel, globalCmd ) = + ( sharedModel, globalCmd ) = Shared.update msg_ model.global ( templateModel, templateCmd ) = - load globalModel model.page + load sharedModel model.page in ( { model - | global = globalModel + | global = sharedModel , page = templateModel } , Cmd.batch @@ -546,30 +546,30 @@ update msg model = load : Shared.Model -> TemplateModel -> ( TemplateModel, Cmd Msg ) -load globalModel model = +load sharedModel model = case model of ModelBlogIndex m -> - Template.BlogIndex.template.load globalModel m + Template.BlogIndex.template.load sharedModel m |> Tuple.mapFirst (ModelBlogIndex) |> Tuple.mapSecond (Cmd.map MsgBlogIndex) ModelBlogPost m -> - Template.BlogPost.template.load globalModel m + Template.BlogPost.template.load sharedModel m |> Tuple.mapFirst (ModelBlogPost) |> Tuple.mapSecond (Cmd.map MsgBlogPost) ModelDocumentation m -> - Template.Documentation.template.load globalModel m + Template.Documentation.template.load sharedModel m |> Tuple.mapFirst (ModelDocumentation) |> Tuple.mapSecond (Cmd.map MsgDocumentation) ModelPage m -> - Template.Page.template.load globalModel m + Template.Page.template.load sharedModel m |> Tuple.mapFirst (ModelPage) |> Tuple.mapSecond (Cmd.map MsgPage) ModelShowcase m -> - Template.Showcase.template.load globalModel m + Template.Showcase.template.load sharedModel m |> Tuple.mapFirst (ModelShowcase) |> Tuple.mapSecond (Cmd.map MsgShowcase) @@ -580,26 +580,26 @@ load globalModel model = save : TemplateModel -> Shared.Model -> Shared.Model -save model globalModel= +save model sharedModel= case model of ModelBlogIndex m -> - Template.BlogIndex.template.save m globalModel + Template.BlogIndex.template.save m sharedModel ModelBlogPost m -> - Template.BlogPost.template.save m globalModel + Template.BlogPost.template.save m sharedModel ModelDocumentation m -> - Template.Documentation.template.save m globalModel + Template.Documentation.template.save m sharedModel ModelPage m -> - Template.Page.template.save m globalModel + Template.Page.template.save m sharedModel ModelShowcase m -> - Template.Showcase.template.save m globalModel + Template.Showcase.template.save m sharedModel NotFound -> - globalModel + sharedModel From 785d6ae85aa4ee1fa4b67fa868f1710d8a4b8f59 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 13 Sep 2020 07:19:09 -0700 Subject: [PATCH 071/106] Use site config module. --- examples/docs/src/Main.elm | 3 +-- examples/docs/src/Site.elm | 17 +++++++++++++++-- .../src/generate-template-module-connector.js | 14 +++++++++++--- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index b5c01a27..0a24683b 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -24,8 +24,7 @@ main = , body = MarkdownRenderer.view } ] - , manifest = Site.manifest - , canonicalSiteUrl = Site.canonicalUrl + , site = Site.config , subscriptions = \_ -> Sub.none } |> RssPlugin.generate diff --git a/examples/docs/src/Site.elm b/examples/docs/src/Site.elm index 260ee833..52f39fe1 100644 --- a/examples/docs/src/Site.elm +++ b/examples/docs/src/Site.elm @@ -1,4 +1,4 @@ -module Site exposing (..) +module Site exposing (canonicalUrl, config, tagline) import Color import Pages exposing (images, pages) @@ -6,6 +6,19 @@ import Pages.Manifest as Manifest import Pages.Manifest.Category +type alias SiteConfig = + { canonicalUrl : String + , manifest : Manifest.Config Pages.PathKey + } + + +config : SiteConfig +config = + { canonicalUrl = canonicalUrl + , manifest = manifest + } + + canonicalUrl : String canonicalUrl = "https://elm-pages.com" @@ -17,7 +30,7 @@ manifest = , categories = [ Pages.Manifest.Category.education ] , displayMode = Manifest.Standalone , orientation = Manifest.Portrait - , description = "elm-pages - A statically typed site generator." + , description = tagline , iarcRatingId = Nothing , name = "elm-pages docs" , themeColor = Just Color.white diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 196c61eb..d0609a40 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -8,6 +8,7 @@ function generateTemplateModuleConnector() { return `module TemplateDemultiplexer exposing (..) import Browser +import Pages.Manifest as Manifest import Shared import GlobalMetadata as M exposing (Metadata) import Head @@ -200,7 +201,13 @@ update msg model = ).join("\n ")} -mainTemplate { documents, manifest, canonicalSiteUrl, subscriptions } = +type alias SiteConfig = + { canonicalUrl : String + , manifest : Manifest.Config Pages.PathKey + } + + +mainTemplate { documents, subscriptions, site } = Pages.Platform.init { init = init Nothing , view = view @@ -208,12 +215,13 @@ mainTemplate { documents, manifest, canonicalSiteUrl, subscriptions } = , subscriptions = subscriptions , documents = documents , onPageChange = Just OnPageChange - , manifest = manifest -- Site.manifest - , canonicalSiteUrl = canonicalSiteUrl -- Site.canonicalUrl + , manifest = site.manifest + , canonicalSiteUrl = site.canonicalUrl , internals = Pages.internals } + mapDocument : Browser.Document Never -> Browser.Document mapped mapDocument document = { title = document.title From 819993f74b03c2a0edca8e13700721d882f43fd9 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 13 Sep 2020 08:02:35 -0700 Subject: [PATCH 072/106] Add placeholder for static data in Site module. --- examples/docs/src/Site.elm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/examples/docs/src/Site.elm b/examples/docs/src/Site.elm index 52f39fe1..73a746f1 100644 --- a/examples/docs/src/Site.elm +++ b/examples/docs/src/Site.elm @@ -1,9 +1,12 @@ module Site exposing (canonicalUrl, config, tagline) import Color +import GlobalMetadata import Pages exposing (images, pages) import Pages.Manifest as Manifest import Pages.Manifest.Category +import Pages.PagePath exposing (PagePath) +import Pages.StaticHttp as StaticHttp type alias SiteConfig = @@ -19,6 +22,17 @@ config = } +type alias StaticData = + () + + +staticData : + List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> StaticHttp.Request StaticData +staticData siteMetadata = + StaticHttp.succeed () + + canonicalUrl : String canonicalUrl = "https://elm-pages.com" From 55f2a4bcd42870d33b2b46174c49d24f6f4b08a2 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 13 Sep 2020 16:38:57 -0700 Subject: [PATCH 073/106] Wire in DynamicPayload for Template modules' update. --- examples/docs/src/Template.elm | 6 +++--- examples/docs/src/Template/BlogIndex.elm | 4 ++-- examples/docs/src/Template/BlogPost.elm | 4 ++-- examples/docs/src/Template/Documentation.elm | 4 ++-- generator/src/generate-template-module-connector.js | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 81f01c76..b5cc6441 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -42,7 +42,7 @@ simpler : StaticPayload templateMetadata () -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateMsg -> DynamicPayload templateModel -> ( templateModel, Cmd templateMsg ) } -> Template templateMetadata () templateModel templateMsg simpler config = @@ -97,7 +97,7 @@ template : StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) + , update : templateMetadata -> templateMsg -> DynamicPayload templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) } -> Template templateMetadata templateStaticData templateModel templateMsg template config = @@ -123,7 +123,7 @@ type alias Template templateMetadata templateStaticData templateModel templateMs StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) + , update : templateMetadata -> templateMsg -> DynamicPayload templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) } diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index bae7afbb..fe97e123 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -46,9 +46,9 @@ init metadata = ( Model, Cmd.none ) -update : BlogIndex -> Msg -> Model -> ( Model, Cmd Msg, Shared.SharedMsg ) +update : BlogIndex -> Msg -> DynamicPayload Model -> ( Model, Cmd Msg, Shared.SharedMsg ) update metadata msg model = - ( Model, Cmd.none, Shared.NoOp ) + ( model.model, Cmd.none, Shared.NoOp ) type alias Model = diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index a1ff512d..4ff6279d 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -91,9 +91,9 @@ init metadata = ( Model, Cmd.none ) -update : BlogPost -> Msg -> Model -> ( Model, Cmd Msg ) +update : BlogPost -> Msg -> DynamicPayload Model -> ( Model, Cmd Msg ) update metadata msg model = - ( Model, Cmd.none ) + ( model.model, Cmd.none ) view : diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index d4e010aa..be307a40 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -48,11 +48,11 @@ init metadata = ( {}, Cmd.none ) -update : Documentation -> Msg -> Model -> ( Model, Cmd Msg, Shared.SharedMsg ) +update : Documentation -> Msg -> DynamicPayload Model -> ( Model, Cmd Msg, Shared.SharedMsg ) update metadata msg model = case msg of Increment -> - ( model, Cmd.none, Shared.IncrementFromChild ) + ( model.model, Cmd.none, Shared.IncrementFromChild ) staticData : diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index d0609a40..eddfda08 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -185,7 +185,7 @@ update msg model = Template.${name}.template.update metadata msg_ - pageModel + { sharedModel = model.global, model = pageModel } |> mapBoth Model${name} (Cmd.map Msg${name}) |> (\\( a, b, c ) -> ( a, b, Shared.update (Shared.SharedMsg c) model.global ) From 59a740280905cdc241a800a45fd4e229b5ef4afc Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 13 Sep 2020 21:05:32 -0700 Subject: [PATCH 074/106] Add sandbox template constructor. --- examples/docs/src/Template.elm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index b5cc6441..5e6b6f60 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -8,6 +8,30 @@ import Pages.StaticHttp as StaticHttp import Shared +sandbox : + { view : + templateMetadata + -> PagePath Pages.PathKey + -> Shared.RenderedBody + -> Shared.PageView Never + , head : + templateMetadata + -> PagePath Pages.PathKey + -> List (Head.Tag Pages.PathKey) + } + -> TemplateSandbox templateMetadata +sandbox config = + template + { view = + \dynamicPayload allMetadata staticPayload rendered -> + config.view staticPayload.metadata staticPayload.path rendered + , head = \staticPayload -> config.head staticPayload.metadata staticPayload.path + , staticData = \_ -> StaticHttp.succeed () + , init = \_ -> ( (), Cmd.none ) + , update = \_ _ _ -> ( (), Cmd.none, Shared.NoOp ) + } + + simplest : { view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) @@ -127,6 +151,10 @@ type alias Template templateMetadata templateStaticData templateModel templateMs } +type alias TemplateSandbox templateMetadata = + Template templateMetadata () () Never + + type alias StaticPayload metadata staticData = { static : staticData , sharedStatic : Shared.StaticData From 9497438f8cb92cc9e0c6e44447ff6a950ef19aa6 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 13 Sep 2020 21:06:47 -0700 Subject: [PATCH 075/106] Rename Template.template to application. --- examples/docs/src/Template.elm | 12 ++++++------ examples/docs/src/Template/BlogIndex.elm | 2 +- examples/docs/src/Template/Documentation.elm | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 5e6b6f60..0bf31af9 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -21,7 +21,7 @@ sandbox : } -> TemplateSandbox templateMetadata sandbox config = - template + application { view = \dynamicPayload allMetadata staticPayload rendered -> config.view staticPayload.metadata staticPayload.path rendered @@ -44,7 +44,7 @@ simplest : } -> Template templateMetadata () () templateMsg simplest config = - template + application { view = \dynamicPayload allMetadata staticPayload rendered -> config.view allMetadata staticPayload rendered @@ -70,7 +70,7 @@ simpler : } -> Template templateMetadata () templateModel templateMsg simpler config = - template + application { view = \dynamicPayload allMetadata staticPayload rendered -> config.view allMetadata staticPayload dynamicPayload.model rendered @@ -96,7 +96,7 @@ stateless : } -> Template templateMetadata templateStaticData () templateMsg stateless config = - template + application { view = \dynamicPayload allMetadata staticPayload rendered -> config.view allMetadata staticPayload rendered @@ -107,7 +107,7 @@ stateless config = } -template : +application : { staticData : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticHttp.Request templateStaticData @@ -124,7 +124,7 @@ template : , update : templateMetadata -> templateMsg -> DynamicPayload templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) } -> Template templateMetadata templateStaticData templateModel templateMsg -template config = +application config = { view = config.view , head = config.head , staticData = config.staticData diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index fe97e123..753f8787 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -21,7 +21,7 @@ type Msg template : Template BlogIndex StaticData Model Msg template = - Template.template + Template.application { view = view , head = head , staticData = staticData diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index be307a40..4f50ffa1 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -34,7 +34,7 @@ type Msg template : Template Documentation StaticData Model Msg template = - Template.template + Template.application { view = view , head = head , staticData = staticData From 2996470c1747b9c4e1ae1f3cc1e0c6be9edb2a24 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 13 Sep 2020 21:16:21 -0700 Subject: [PATCH 076/106] Use sandbox for Template.Page. --- examples/docs/src/Template/Page.elm | 52 +++++++++-------------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index baa0d677..6e713027 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -2,64 +2,44 @@ module Template.Page exposing (Model, Msg, decoder, template) import Element exposing (Element) import Element.Region -import GlobalMetadata import Head import Head.Seo as Seo import Json.Decode as Decode import Pages exposing (images) -import Pages.PagePath as PagePath exposing (PagePath) -import Pages.StaticHttp as StaticHttp +import Pages.PagePath exposing (PagePath) import Shared import Site import Template exposing (StaticPayload, Template) import TemplateMetadata exposing (Page) -type alias StaticData = - () - - type alias Model = () -type Msg - = Msg +type alias Msg = + Never -template : Template Page () () Msg +template : Template.TemplateSandbox Page template = - Template.simplest + Template.sandbox { view = view , head = head } -init : Page -> ( Model, Cmd Msg ) -init metadata = - ( (), Cmd.none ) - - -update : Page -> Msg -> Model -> ( Model, Cmd Msg ) -update metadata msg model = - ( (), Cmd.none ) - - -staticData : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) - -> StaticHttp.Request StaticData -staticData siteMetadata = - StaticHttp.succeed () - - decoder : Decode.Decoder Page decoder = Decode.map Page (Decode.field "title" Decode.string) -head : StaticPayload Page () -> List (Head.Tag Pages.PathKey) -head staticPayload = +head : + Page + -> PagePath Pages.PathKey + -> List (Head.Tag Pages.PathKey) +head metadata path = Seo.summary { canonicalUrlOverride = Nothing , siteName = "elm-pages" @@ -71,18 +51,18 @@ head staticPayload = } , description = Site.tagline , locale = Nothing - , title = staticPayload.metadata.title + , title = metadata.title } |> Seo.website view : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) - -> StaticPayload Page () + Page + -> PagePath Pages.PathKey -> Shared.RenderedBody - -> Shared.PageView Msg -view allMetadata staticPayload rendered = - { title = staticPayload.metadata.title + -> Shared.PageView msg +view metadata path rendered = + { title = metadata.title , body = [ Element.column [ Element.padding 50 From a8ab4645071cf19d6d4f916f7dc562ac4e48a71a Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 13 Sep 2020 21:31:32 -0700 Subject: [PATCH 077/106] Remove unused template helper. --- examples/docs/src/Template.elm | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 0bf31af9..aa5b3a31 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -32,29 +32,6 @@ sandbox config = } -simplest : - { view : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) - -> StaticPayload templateMetadata () - -> Shared.RenderedBody - -> Shared.PageView templateMsg - , head : - StaticPayload templateMetadata () - -> List (Head.Tag Pages.PathKey) - } - -> Template templateMetadata () () templateMsg -simplest config = - application - { view = - \dynamicPayload allMetadata staticPayload rendered -> - config.view allMetadata staticPayload rendered - , head = config.head - , staticData = \_ -> StaticHttp.succeed () - , init = \_ -> ( (), Cmd.none ) - , update = \_ _ _ -> ( (), Cmd.none, Shared.NoOp ) - } - - simpler : { view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) From 86da9973bd74bbe3b07c43abf7818ce9fbcc6678 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 13 Sep 2020 21:31:49 -0700 Subject: [PATCH 078/106] Use Template.sandbox for blog post template. --- examples/docs/src/Template/BlogPost.elm | 79 +++++++++++-------------- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 4ff6279d..48f1e739 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -5,7 +5,6 @@ import Date exposing (Date) import Element exposing (Element) import Element.Font as Font import Element.Region -import GlobalMetadata import Head import Head.Seo as Seo import Json.Decode as Decode @@ -17,25 +16,23 @@ import Palette import Shared import Site import StructuredData -import Template exposing (DynamicPayload, StaticPayload, Template) +import Template exposing (DynamicPayload, StaticPayload, Template, TemplateSandbox) import TemplateMetadata exposing (BlogPost) -type Model - = Model +type alias Model = + () -type Msg - = Msg +type alias Msg = + Never -template : Template BlogPost () Model Msg +template : TemplateSandbox BlogPost template = - Template.simpler + Template.sandbox { view = view , head = head - , init = init - , update = update } @@ -86,24 +83,13 @@ findMatchingImage imageAssetPath = Pages.allImages -init : BlogPost -> ( Model, Cmd Msg ) -init metadata = - ( Model, Cmd.none ) - - -update : BlogPost -> Msg -> DynamicPayload Model -> ( Model, Cmd Msg ) -update metadata msg model = - ( model.model, Cmd.none ) - - view : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) - -> StaticPayload BlogPost () - -> Model + BlogPost + -> PagePath Pages.PathKey -> Shared.RenderedBody - -> Shared.PageView Msg -view allMetadata staticPayload model rendered = - { title = staticPayload.metadata.title + -> Shared.PageView msg +view metadata path rendered = + { title = metadata.title , body = Element.column [ Element.width Element.fill ] [ Element.column @@ -115,19 +101,19 @@ view allMetadata staticPayload model rendered = ] (Element.column [ Element.spacing 10 ] [ Element.row [ Element.spacing 10 ] - [ Author.view [] staticPayload.metadata.author + [ Author.view [] metadata.author , Element.column [ Element.spacing 10, Element.width Element.fill ] [ Element.paragraph [ Font.bold, Font.size 24 ] - [ Element.text staticPayload.metadata.author.name + [ Element.text metadata.author.name ] , Element.paragraph [ Font.size 16 ] - [ Element.text staticPayload.metadata.author.bio ] + [ Element.text metadata.author.bio ] ] ] ] - :: (publishedDateView staticPayload.metadata |> Element.el [ Font.size 16, Font.color (Element.rgba255 0 0 0 0.6) ]) - :: Palette.blogHeading staticPayload.metadata.title - :: articleImageView staticPayload.metadata.image + :: (publishedDateView metadata |> Element.el [ Font.size 16, Font.color (Element.rgba255 0 0 0 0.6) ]) + :: Palette.blogHeading metadata.title + :: articleImageView metadata.image :: Tuple.second rendered |> List.map (Element.map never) ) @@ -135,17 +121,20 @@ view allMetadata staticPayload model rendered = } -head : StaticPayload BlogPost () -> List (Head.Tag Pages.PathKey) -head staticPayload = +head : + BlogPost + -> PagePath Pages.PathKey + -> List (Head.Tag Pages.PathKey) +head metadata path = Head.structuredData (StructuredData.article - { title = staticPayload.metadata.title - , description = staticPayload.metadata.description - , author = StructuredData.person { name = staticPayload.metadata.author.name } + { title = metadata.title + , description = metadata.description + , author = StructuredData.person { name = metadata.author.name } , publisher = StructuredData.person { name = "Dillon Kearns" } - , url = Site.canonicalUrl ++ "/" ++ PagePath.toString staticPayload.path - , imageUrl = Site.canonicalUrl ++ "/" ++ ImagePath.toString staticPayload.metadata.image - , datePublished = Date.toIsoString staticPayload.metadata.published + , url = Site.canonicalUrl ++ "/" ++ PagePath.toString path + , imageUrl = Site.canonicalUrl ++ "/" ++ ImagePath.toString metadata.image + , datePublished = Date.toIsoString metadata.published , mainEntityOfPage = StructuredData.softwareSourceCode { codeRepositoryUrl = "https://github.com/dillonkearns/elm-pages" @@ -159,19 +148,19 @@ head staticPayload = { canonicalUrlOverride = Nothing , siteName = "elm-pages" , image = - { url = staticPayload.metadata.image - , alt = staticPayload.metadata.description + { url = metadata.image + , alt = metadata.description , dimensions = Nothing , mimeType = Nothing } - , description = staticPayload.metadata.description + , description = metadata.description , locale = Nothing - , title = staticPayload.metadata.title + , title = metadata.title } |> Seo.article { tags = [] , section = Nothing - , publishedTime = Just (Date.toIsoString staticPayload.metadata.published) + , publishedTime = Just (Date.toIsoString metadata.published) , modifiedTime = Nothing , expirationTime = Nothing } From e71e90172a60031d725ced0b1b210cb2bfcd500f Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 14 Sep 2020 22:05:36 -0700 Subject: [PATCH 079/106] Wire in subscriptions for templates. --- examples/docs/src/Main.elm | 2 +- examples/docs/src/Template.elm | 10 ++++++ examples/docs/src/Template/BlogIndex.elm | 1 + examples/docs/src/Template/BlogPost.elm | 4 +-- examples/docs/src/Template/Documentation.elm | 1 + .../src/generate-template-module-connector.js | 31 ++++++++++++++++- src/Pages/Internal/Platform.elm | 33 ++++++++++++++++--- src/Pages/Internal/Platform/Cli.elm | 2 +- src/Pages/Platform.elm | 6 ++-- 9 files changed, 76 insertions(+), 14 deletions(-) diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 0a24683b..e81d283c 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -25,7 +25,7 @@ main = } ] , site = Site.config - , subscriptions = \_ -> Sub.none + , subscriptions = Sub.none } |> RssPlugin.generate { siteTagline = Site.tagline diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index aa5b3a31..94ba0788 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -29,6 +29,7 @@ sandbox config = , staticData = \_ -> StaticHttp.succeed () , init = \_ -> ( (), Cmd.none ) , update = \_ _ _ -> ( (), Cmd.none, Shared.NoOp ) + , subscriptions = \_ _ _ -> Sub.none } @@ -55,9 +56,12 @@ simpler config = , staticData = \_ -> StaticHttp.succeed () , init = config.init , update = \a1 b1 c1 -> config.update a1 b1 c1 |> (\( a, b ) -> ( a, b, Shared.NoOp )) + , subscriptions = \_ _ _ -> Sub.none } +{-| Basic `staticData` (including access to Shared static data) +-} stateless : { staticData : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) @@ -81,9 +85,12 @@ stateless config = , staticData = config.staticData , init = \_ -> ( (), Cmd.none ) , update = \_ _ _ -> ( (), Cmd.none, Shared.NoOp ) + , subscriptions = \_ _ _ -> Sub.none } +{-| Full application (including local `Model`, `Msg`, `update`) +-} application : { staticData : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) @@ -99,6 +106,7 @@ application : -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> DynamicPayload templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) + , subscriptions : templateMetadata -> PagePath Pages.PathKey -> DynamicPayload templateModel -> Sub templateMsg } -> Template templateMetadata templateStaticData templateModel templateMsg application config = @@ -107,6 +115,7 @@ application config = , staticData = config.staticData , init = config.init , update = config.update + , subscriptions = config.subscriptions } @@ -125,6 +134,7 @@ type alias Template templateMetadata templateStaticData templateModel templateMs -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) , update : templateMetadata -> templateMsg -> DynamicPayload templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) + , subscriptions : templateMetadata -> PagePath Pages.PathKey -> DynamicPayload templateModel -> Sub templateMsg } diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 753f8787..1b2af0d9 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -27,6 +27,7 @@ template = , staticData = staticData , init = init , update = update + , subscriptions = \_ _ _ -> Sub.none } diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 48f1e739..87d24096 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -78,9 +78,7 @@ imageDecoder = findMatchingImage : String -> Maybe (ImagePath Pages.PathKey) findMatchingImage imageAssetPath = - List.Extra.find - (\image -> ImagePath.toString image == imageAssetPath) - Pages.allImages + List.Extra.find (\image -> ImagePath.toString image == imageAssetPath) Pages.allImages view : diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 4f50ffa1..e53357cc 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -40,6 +40,7 @@ template = , staticData = staticData , init = init , update = update + , subscriptions = \_ _ _ -> Sub.none } diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index eddfda08..ade3b2b2 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -206,13 +206,42 @@ type alias SiteConfig = , manifest : Manifest.Config Pages.PathKey } +templateSubscriptions : Metadata -> PagePath Pages.PathKey -> Model -> Sub Msg +templateSubscriptions metadata path model = + case model.page of + ${templates.map(name => ` + Model${name} templateModel -> + case metadata of + M.Metadata${name} templateMetadata -> + Template.${name}.template.subscriptions + templateMetadata + path + { model = templateModel + , sharedModel = model.global + } + |> Sub.map Msg${name} + + _ -> + Sub.none +` + ).join("\n ")} + + + NotFound -> + Sub.none + mainTemplate { documents, subscriptions, site } = Pages.Platform.init { init = init Nothing , view = view , update = update - , subscriptions = subscriptions + , subscriptions = + \\metadata path model -> + Sub.batch + [ subscriptions + , templateSubscriptions metadata path model + ] , documents = documents , onPageChange = Just OnPageChange , manifest = site.manifest diff --git a/src/Pages/Internal/Platform.elm b/src/Pages/Internal/Platform.elm index add9c88e..aa46b91c 100644 --- a/src/Pages/Internal/Platform.elm +++ b/src/Pages/Internal/Platform.elm @@ -727,7 +727,7 @@ application : } -> ( userModel, Cmd userMsg ) , update : userMsg -> userModel -> ( userModel, Cmd userMsg ) - , subscriptions : userModel -> Sub userMsg + , subscriptions : metadata -> PagePath pathKey -> userModel -> Sub userMsg , view : List ( PagePath pathKey, metadata ) -> @@ -822,10 +822,33 @@ application config = \outerModel -> case outerModel of Model model -> + let + urls = + { currentUrl = model.url + , baseUrl = model.baseUrl + } + + ( maybePagePath, maybeMetadata ) = + case ContentCache.lookupMetadata config.pathKey model.contentCache urls of + Just ( pagePath, metadata ) -> + ( Just pagePath, Just metadata ) + + Nothing -> + ( Nothing, Nothing ) + + userSub = + Maybe.map2 + (\metadata path -> + config.subscriptions metadata path model.userModel + |> Sub.map UserMsg + |> Sub.map AppMsg + ) + maybeMetadata + maybePagePath + |> Maybe.withDefault Sub.none + in Sub.batch - [ config.subscriptions model.userModel - |> Sub.map UserMsg - |> Sub.map AppMsg + [ userSub , config.fromJsPort |> Sub.map (\decodeValue -> @@ -863,7 +886,7 @@ cliApplication : } -> ( userModel, Cmd userMsg ) , update : userMsg -> userModel -> ( userModel, Cmd userMsg ) - , subscriptions : userModel -> Sub userMsg + , subscriptions : metadata -> PagePath pathKey -> userModel -> Sub userMsg , view : List ( PagePath pathKey, metadata ) -> diff --git a/src/Pages/Internal/Platform/Cli.elm b/src/Pages/Internal/Platform/Cli.elm index 49be51fc..809ae43a 100644 --- a/src/Pages/Internal/Platform/Cli.elm +++ b/src/Pages/Internal/Platform/Cli.elm @@ -79,7 +79,7 @@ type alias Config pathKey userMsg userModel metadata view = } -> ( userModel, Cmd userMsg ) , update : userMsg -> userModel -> ( userModel, Cmd userMsg ) - , subscriptions : userModel -> Sub userMsg + , subscriptions : metadata -> PagePath pathKey -> userModel -> Sub userMsg , view : List ( PagePath pathKey, metadata ) -> diff --git a/src/Pages/Platform.elm b/src/Pages/Platform.elm index 42f11ac2..4cf2313f 100644 --- a/src/Pages/Platform.elm +++ b/src/Pages/Platform.elm @@ -92,7 +92,7 @@ type Builder pathKey model msg metadata view } -> ( model, Cmd msg ) , update : msg -> model -> ( model, Cmd msg ) - , subscriptions : model -> Sub msg + , subscriptions : metadata -> PagePath pathKey -> model -> Sub msg , view : List ( PagePath pathKey, metadata ) -> @@ -185,7 +185,7 @@ init : { view : model -> view -> { title : String, body : Html msg } , head : List (Head.Tag pathKey) } - , subscriptions : model -> Sub msg + , subscriptions : metadata -> PagePath pathKey -> model -> Sub msg , documents : List { extension : String @@ -330,7 +330,7 @@ application : } -> ( model, Cmd msg ) , update : msg -> model -> ( model, Cmd msg ) - , subscriptions : model -> Sub msg + , subscriptions : metadata -> PagePath pathKey -> model -> Sub msg , view : List ( PagePath pathKey, metadata ) -> From fce79cdaf61928f8977e3dad645d59d35ed110d5 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 16 Sep 2020 19:18:25 -0700 Subject: [PATCH 080/106] Rename GlobalMetadata to TemplateType. --- .../docs/content/docs/directory-structure.md | 4 +-- examples/docs/src/DocSidebar.elm | 6 ++-- examples/docs/src/GlobalMetadata.elm | 12 +++---- examples/docs/src/Index.elm | 6 ++-- examples/docs/src/Main.elm | 16 +++++----- examples/docs/src/MetadataNew.elm | 12 +++---- examples/docs/src/Site.elm | 4 +-- examples/docs/src/Template.elm | 16 +++++----- examples/docs/src/Template/BlogIndex.elm | 6 ++-- examples/docs/src/Template/Documentation.elm | 10 +++--- examples/docs/src/Template/Showcase.elm | 7 ++-- examples/docs/src/TemplateHardcoded.elm | 10 +++--- .../src/generate-template-module-connector.js | 2 +- .../generated-files.test.js.snap | 32 +++++++++---------- tests/src/Template/BlogPost.elm | 4 +-- 15 files changed, 74 insertions(+), 73 deletions(-) diff --git a/examples/docs/content/docs/directory-structure.md b/examples/docs/content/docs/directory-structure.md index 1f0f01d1..daef8124 100644 --- a/examples/docs/content/docs/directory-structure.md +++ b/examples/docs/content/docs/directory-structure.md @@ -82,7 +82,7 @@ markdownDocument = ### Templates `src/Template/*.elm` -A template represents a type of page. For example, a BlogPost template could live in `src/Template/BlogPost.elm`. Any files in your `content/` folder with frontmatter that you decode into type `GlobalMetadata.BlogPost` will be rendered using your `BlogPost` template. +A template represents a type of page. For example, a BlogPost template could live in `src/Template/BlogPost.elm`. Any files in your `content/` folder with frontmatter that you decode into type `TemplateType.BlogPost` will be rendered using your `BlogPost` template. Think of each template as having its own mini `elm-pages architecture` lifecycle. @@ -145,6 +145,6 @@ Now say you navigate to `/catalog/sibelius`. Let's look at the `elm-pages archit ### Global Metadata -`src/GlobalMetadata.elm` +`src/TemplateType.elm` This module must define a variant for each template module. \ No newline at end of file diff --git a/examples/docs/src/DocSidebar.elm b/examples/docs/src/DocSidebar.elm index e6f3b9be..dbc113db 100644 --- a/examples/docs/src/DocSidebar.elm +++ b/examples/docs/src/DocSidebar.elm @@ -3,16 +3,16 @@ module DocSidebar exposing (view) import Element exposing (Element) import Element.Border as Border import Element.Font -import GlobalMetadata import Metadata exposing (Metadata) import Pages import Pages.PagePath as PagePath exposing (PagePath) import Palette +import TemplateType view : PagePath Pages.PathKey - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> Element msg view currentPage posts = Element.column @@ -26,7 +26,7 @@ view currentPage posts = |> List.filterMap (\( path, metadata ) -> case metadata of - GlobalMetadata.MetadataDocumentation meta -> + TemplateType.Documentation meta -> Just ( currentPage == path, path, meta ) _ -> diff --git a/examples/docs/src/GlobalMetadata.elm b/examples/docs/src/GlobalMetadata.elm index 312c984a..3bd43bda 100644 --- a/examples/docs/src/GlobalMetadata.elm +++ b/examples/docs/src/GlobalMetadata.elm @@ -1,11 +1,11 @@ -module GlobalMetadata exposing (..) +module TemplateType exposing (..) import TemplateMetadata type Metadata - = MetadataBlogPost TemplateMetadata.BlogPost - | MetadataShowcase TemplateMetadata.Showcase - | MetadataPage TemplateMetadata.Page - | MetadataBlogIndex TemplateMetadata.BlogIndex - | MetadataDocumentation TemplateMetadata.Documentation + = BlogPost TemplateMetadata.BlogPost + | Showcase TemplateMetadata.Showcase + | Page TemplateMetadata.Page + | BlogIndex TemplateMetadata.BlogIndex + | Documentation TemplateMetadata.Documentation diff --git a/examples/docs/src/Index.elm b/examples/docs/src/Index.elm index 09ae4c7e..b448ff7c 100644 --- a/examples/docs/src/Index.elm +++ b/examples/docs/src/Index.elm @@ -7,15 +7,15 @@ import Date import Element exposing (Element) import Element.Border import Element.Font -import GlobalMetadata import Pages import Pages.ImagePath as ImagePath exposing (ImagePath) import Pages.PagePath as PagePath exposing (PagePath) import TemplateMetadata exposing (BlogPost) +import TemplateType view : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> Element msg view posts = Element.column [ Element.spacing 20 ] @@ -23,7 +23,7 @@ view posts = |> List.filterMap (\( path, metadata ) -> case metadata of - GlobalMetadata.MetadataBlogPost meta -> + TemplateType.BlogPost meta -> if meta.draft then Nothing diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index e81d283c..0eef8de1 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -1,7 +1,6 @@ module Main exposing (main) import Data.Author -import GlobalMetadata import MarkdownRenderer import MetadataNew import MySitemap @@ -13,15 +12,16 @@ import RssPlugin import Shared import Site import TemplateDemultiplexer +import TemplateType -main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg GlobalMetadata.Metadata Shared.RenderedBody +main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg TemplateType.Metadata Shared.RenderedBody main = TemplateDemultiplexer.mainTemplate { documents = [ { extension = "md" - , metadata = MetadataNew.decoder - , body = MarkdownRenderer.view + , metadata = MetadataNew.decoder -- metadata parser/decoder? + , body = MarkdownRenderer.view -- body parser? } ] , site = Site.config @@ -41,13 +41,13 @@ main = metadataToRssItem : { path : PagePath Pages.PathKey - , frontmatter : GlobalMetadata.Metadata + , frontmatter : TemplateType.Metadata , body : String } -> Maybe Rss.Item metadataToRssItem page = case page.frontmatter of - GlobalMetadata.MetadataBlogPost blogPost -> + TemplateType.BlogPost blogPost -> if blogPost.draft then Nothing @@ -69,7 +69,7 @@ metadataToRssItem page = metadataToSitemapEntry : List { path : PagePath Pages.PathKey - , frontmatter : GlobalMetadata.Metadata + , frontmatter : TemplateType.Metadata , body : String } -> List { path : String, lastMod : Maybe String } @@ -78,7 +78,7 @@ metadataToSitemapEntry siteMetadata = |> List.filter (\page -> case page.frontmatter of - GlobalMetadata.MetadataBlogPost blogPost -> + TemplateType.BlogPost blogPost -> not blogPost.draft _ -> diff --git a/examples/docs/src/MetadataNew.elm b/examples/docs/src/MetadataNew.elm index 343bfeda..7f83a7f1 100644 --- a/examples/docs/src/MetadataNew.elm +++ b/examples/docs/src/MetadataNew.elm @@ -1,10 +1,10 @@ module MetadataNew exposing (DocMetadata, PageMetadata, decoder) -import GlobalMetadata as Metadata exposing (Metadata) import Json.Decode as Decode exposing (Decoder) import Template.BlogPost import Template.Page import Template.Showcase +import TemplateType as Metadata exposing (Metadata) type alias DocMetadata = @@ -24,23 +24,23 @@ decoder = case pageType of "doc" -> Decode.field "title" Decode.string - |> Decode.map (\title -> Metadata.MetadataDocumentation { title = title }) + |> Decode.map (\title -> Metadata.Documentation { title = title }) "page" -> Template.Page.decoder - |> Decode.map Metadata.MetadataPage + |> Decode.map Metadata.Page "blog-index" -> Decode.succeed {} - |> Decode.map Metadata.MetadataBlogIndex + |> Decode.map Metadata.BlogIndex "showcase" -> Template.Showcase.decoder - |> Decode.map Metadata.MetadataShowcase + |> Decode.map Metadata.Showcase "blog" -> Template.BlogPost.decoder - |> Decode.map Metadata.MetadataBlogPost + |> Decode.map Metadata.BlogPost _ -> Decode.fail <| "Unexpected page \"type\" " ++ pageType diff --git a/examples/docs/src/Site.elm b/examples/docs/src/Site.elm index 73a746f1..cad9f8a6 100644 --- a/examples/docs/src/Site.elm +++ b/examples/docs/src/Site.elm @@ -1,12 +1,12 @@ module Site exposing (canonicalUrl, config, tagline) import Color -import GlobalMetadata import Pages exposing (images, pages) import Pages.Manifest as Manifest import Pages.Manifest.Category import Pages.PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp +import TemplateType type alias SiteConfig = @@ -27,7 +27,7 @@ type alias StaticData = staticData : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticHttp.Request StaticData staticData siteMetadata = StaticHttp.succeed () diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 94ba0788..eed20131 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -1,11 +1,11 @@ module Template exposing (..) -import GlobalMetadata import Head import Pages import Pages.PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Shared +import TemplateType sandbox : @@ -35,7 +35,7 @@ sandbox config = simpler : { view : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticPayload templateMetadata () -> templateModel -> Shared.RenderedBody @@ -64,10 +64,10 @@ simpler config = -} stateless : { staticData : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticHttp.Request templateStaticData , view : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticPayload templateMetadata templateStaticData -> Shared.RenderedBody -> Shared.PageView templateMsg @@ -93,11 +93,11 @@ stateless config = -} application : { staticData : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticHttp.Request templateStaticData , view : DynamicPayload templateModel - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticPayload templateMetadata templateStaticData -> Shared.RenderedBody -> Shared.PageView templateMsg @@ -121,11 +121,11 @@ application config = type alias Template templateMetadata templateStaticData templateModel templateMsg = { staticData : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticHttp.Request templateStaticData , view : DynamicPayload templateModel - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticPayload templateMetadata templateStaticData -> Shared.RenderedBody -> Shared.PageView templateMsg diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 1b2af0d9..7b182197 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -1,7 +1,6 @@ module Template.BlogIndex exposing (Model, Msg, template) import Element exposing (Element) -import GlobalMetadata import Head import Head.Seo as Seo import Index @@ -13,6 +12,7 @@ import Showcase import Site import Template exposing (DynamicPayload, StaticPayload, Template) import TemplateMetadata exposing (BlogIndex) +import TemplateType type Msg @@ -32,7 +32,7 @@ template = staticData : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticHttp.Request StaticData staticData siteMetadata = Showcase.staticRequest @@ -58,7 +58,7 @@ type alias Model = view : DynamicPayload Model - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticPayload BlogIndex StaticData -> Shared.RenderedBody -> Shared.PageView Msg diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index e53357cc..772b3b41 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -5,7 +5,6 @@ import Element exposing (Element) import Element.Events import Element.Font as Font import Element.Region -import GlobalMetadata import Head import Head.Seo as Seo import Json.Decode as Decode @@ -18,6 +17,7 @@ import Shared import Site import Template exposing (DynamicPayload, StaticPayload, Template) import TemplateMetadata exposing (Documentation) +import TemplateType type alias StaticData = @@ -50,14 +50,14 @@ init metadata = update : Documentation -> Msg -> DynamicPayload Model -> ( Model, Cmd Msg, Shared.SharedMsg ) -update metadata msg model = +update metadata msg dynamic = case msg of Increment -> - ( model.model, Cmd.none, Shared.IncrementFromChild ) + ( dynamic.model, Cmd.none, Shared.IncrementFromChild ) staticData : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticHttp.Request StaticData staticData siteMetadata = StaticHttp.succeed () @@ -89,7 +89,7 @@ head staticPayload = view : DynamicPayload Model - -> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + -> List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticPayload Documentation StaticData -> Shared.RenderedBody -> Shared.PageView Msg diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index 5ad49c98..3dae43de 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -1,7 +1,6 @@ module Template.Showcase exposing (Model, Msg, decoder, template) import Element exposing (Element) -import GlobalMetadata import Head import Head.Seo as Seo import Json.Decode as Decode exposing (Decoder) @@ -12,6 +11,7 @@ import Shared import Showcase import Template exposing (StaticPayload, Template) import TemplateMetadata exposing (Showcase) +import TemplateType type alias Model = @@ -25,6 +25,7 @@ type Msg template : Template Showcase StaticData () Msg template = Template.stateless + -- static { view = view , head = head , staticData = staticData @@ -37,7 +38,7 @@ decoder = staticData : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticHttp.Request StaticData staticData siteMetadata = Showcase.staticRequest @@ -48,7 +49,7 @@ type alias StaticData = view : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticPayload Showcase StaticData -> Shared.RenderedBody -> Shared.PageView msg diff --git a/examples/docs/src/TemplateHardcoded.elm b/examples/docs/src/TemplateHardcoded.elm index d7dbd347..80774ed5 100644 --- a/examples/docs/src/TemplateHardcoded.elm +++ b/examples/docs/src/TemplateHardcoded.elm @@ -1,18 +1,18 @@ module TemplateHardcoded exposing (..) -import GlobalMetadata import Head import Pages import Pages.PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp +import TemplateType template : { staticData : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticHttp.Request staticData , view : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> staticData -> model -> metadata @@ -33,10 +33,10 @@ template config = type alias Template metadata renderedTemplate staticData model view templateMsg = { staticData : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticHttp.Request staticData , view : - List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) + List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> staticData -> model -> metadata diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index ade3b2b2..8b64d25a 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -10,7 +10,7 @@ function generateTemplateModuleConnector() { import Browser import Pages.Manifest as Manifest import Shared -import GlobalMetadata as M exposing (Metadata) +import TemplateType as M exposing (Metadata) import Head import Html exposing (Html) import Pages diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index c7a5469f..f187b79c 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -119,7 +119,7 @@ exports[`generate template module connector 1`] = ` import Browser import Shared -import GlobalMetadata as M exposing (Metadata) +import TemplateType as M exposing (Metadata) import Head import Html exposing (Html) import Pages @@ -189,7 +189,7 @@ view : } view siteMetadata page = case page.frontmatter of - M.MetadataBlogIndex metadata -> + M.BlogIndex metadata -> StaticHttp.map2 (\\\\data globalData -> { view = @@ -222,7 +222,7 @@ view siteMetadata page = (Shared.staticData siteMetadata) - M.MetadataBlogPost metadata -> + M.BlogPost metadata -> StaticHttp.map2 (\\\\data globalData -> { view = @@ -255,7 +255,7 @@ view siteMetadata page = (Shared.staticData siteMetadata) - M.MetadataDocumentation metadata -> + M.Documentation metadata -> StaticHttp.map2 (\\\\data globalData -> { view = @@ -288,7 +288,7 @@ view siteMetadata page = (Shared.staticData siteMetadata) - M.MetadataPage metadata -> + M.Page metadata -> StaticHttp.map2 (\\\\data globalData -> { view = @@ -321,7 +321,7 @@ view siteMetadata page = (Shared.staticData siteMetadata) - M.MetadataShowcase metadata -> + M.Showcase metadata -> StaticHttp.map2 (\\\\data globalData -> { view = @@ -379,31 +379,31 @@ init currentGlobalModel maybePagePath = Just meta -> case meta of - M.MetadataBlogIndex metadata -> + M.BlogIndex metadata -> Template.BlogIndex.template.init metadata |> Tuple.first |> ModelBlogIndex - M.MetadataBlogPost metadata -> + M.BlogPost metadata -> Template.BlogPost.template.init metadata |> Tuple.first |> ModelBlogPost - M.MetadataDocumentation metadata -> + M.Documentation metadata -> Template.Documentation.template.init metadata |> Tuple.first |> ModelDocumentation - M.MetadataPage metadata -> + M.Page metadata -> Template.Page.template.init metadata |> Tuple.first |> ModelPage - M.MetadataShowcase metadata -> + M.Showcase metadata -> Template.Showcase.template.init metadata |> Tuple.first |> ModelShowcase @@ -462,7 +462,7 @@ update msg model = let ( updatedPageModel, pageCmd ) = case ( model.page, model.current |> Maybe.map .metadata ) of - ( ModelBlogIndex pageModel, Just (M.MetadataBlogIndex metadata) ) -> + ( ModelBlogIndex pageModel, Just (M.BlogIndex metadata) ) -> Template.BlogIndex.template.update metadata msg_ @@ -479,7 +479,7 @@ update msg model = let ( updatedPageModel, pageCmd ) = case ( model.page, model.current |> Maybe.map .metadata ) of - ( ModelBlogPost pageModel, Just (M.MetadataBlogPost metadata) ) -> + ( ModelBlogPost pageModel, Just (M.BlogPost metadata) ) -> Template.BlogPost.template.update metadata msg_ @@ -496,7 +496,7 @@ update msg model = let ( updatedPageModel, pageCmd ) = case ( model.page, model.current |> Maybe.map .metadata ) of - ( ModelDocumentation pageModel, Just (M.MetadataDocumentation metadata) ) -> + ( ModelDocumentation pageModel, Just (M.Documentation metadata) ) -> Template.Documentation.template.update metadata msg_ @@ -513,7 +513,7 @@ update msg model = let ( updatedPageModel, pageCmd ) = case ( model.page, model.current |> Maybe.map .metadata ) of - ( ModelPage pageModel, Just (M.MetadataPage metadata) ) -> + ( ModelPage pageModel, Just (M.Page metadata) ) -> Template.Page.template.update metadata msg_ @@ -530,7 +530,7 @@ update msg model = let ( updatedPageModel, pageCmd ) = case ( model.page, model.current |> Maybe.map .metadata ) of - ( ModelShowcase pageModel, Just (M.MetadataShowcase metadata) ) -> + ( ModelShowcase pageModel, Just (M.Showcase metadata) ) -> Template.Showcase.template.update metadata msg_ diff --git a/tests/src/Template/BlogPost.elm b/tests/src/Template/BlogPost.elm index d2c01fae..be5e522c 100644 --- a/tests/src/Template/BlogPost.elm +++ b/tests/src/Template/BlogPost.elm @@ -5,7 +5,6 @@ import Date exposing (Date) import Element exposing (Element) import Element.Font as Font import Element.Region -import GlobalMetadata import Head import Head.Seo as Seo import Json.Decode as Decode @@ -22,6 +21,7 @@ import StructuredData import Template import Template.Metadata exposing (BlogPost) import TemplateDocument exposing (TemplateDocument) +import TemplateType type Model @@ -110,7 +110,7 @@ type alias StaticData = Int -view : List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) -> StaticData -> Model -> BlogPost -> ( a, List (Element msg) ) -> { title : String, body : Element msg } +view : List ( PagePath Pages.PathKey, TemplateType.Metadata ) -> StaticData -> Model -> BlogPost -> ( a, List (Element msg) ) -> { title : String, body : Element msg } view allMetadata static model blogPost rendered = { title = blogPost.title , body = From dd3f824e4e4aab38cb5633909061418338ee0392 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 16 Sep 2020 21:08:12 -0700 Subject: [PATCH 081/106] Remove DynamicPayload type and update TemplateType wiring. --- examples/docs/src/DocSidebar.elm | 4 +- examples/docs/src/Index.elm | 4 +- examples/docs/src/Main.elm | 8 +-- examples/docs/src/MetadataNew.elm | 14 ++--- examples/docs/src/Site.elm | 4 +- examples/docs/src/Template.elm | 62 +++++++++---------- examples/docs/src/Template/BlogIndex.elm | 21 ++++--- examples/docs/src/Template/BlogPost.elm | 2 +- examples/docs/src/Template/Documentation.elm | 23 +++---- examples/docs/src/Template/Showcase.elm | 7 +-- .../{GlobalMetadata.elm => TemplateType.elm} | 4 +- .../src/generate-template-module-connector.js | 35 +++++------ 12 files changed, 92 insertions(+), 96 deletions(-) rename examples/docs/src/{GlobalMetadata.elm => TemplateType.elm} (78%) diff --git a/examples/docs/src/DocSidebar.elm b/examples/docs/src/DocSidebar.elm index dbc113db..71b0f87c 100644 --- a/examples/docs/src/DocSidebar.elm +++ b/examples/docs/src/DocSidebar.elm @@ -7,12 +7,12 @@ import Metadata exposing (Metadata) import Pages import Pages.PagePath as PagePath exposing (PagePath) import Palette -import TemplateType +import TemplateType exposing (TemplateType) view : PagePath Pages.PathKey - -> List ( PagePath Pages.PathKey, TemplateType.Metadata ) + -> List ( PagePath Pages.PathKey, TemplateType ) -> Element msg view currentPage posts = Element.column diff --git a/examples/docs/src/Index.elm b/examples/docs/src/Index.elm index b448ff7c..37e07970 100644 --- a/examples/docs/src/Index.elm +++ b/examples/docs/src/Index.elm @@ -11,11 +11,11 @@ import Pages import Pages.ImagePath as ImagePath exposing (ImagePath) import Pages.PagePath as PagePath exposing (PagePath) import TemplateMetadata exposing (BlogPost) -import TemplateType +import TemplateType exposing (TemplateType) view : - List ( PagePath Pages.PathKey, TemplateType.Metadata ) + List ( PagePath Pages.PathKey, TemplateType ) -> Element msg view posts = Element.column [ Element.spacing 20 ] diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 0eef8de1..2c64b923 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -12,10 +12,10 @@ import RssPlugin import Shared import Site import TemplateDemultiplexer -import TemplateType +import TemplateType exposing (TemplateType) -main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg TemplateType.Metadata Shared.RenderedBody +main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg TemplateType Shared.RenderedBody main = TemplateDemultiplexer.mainTemplate { documents = @@ -41,7 +41,7 @@ main = metadataToRssItem : { path : PagePath Pages.PathKey - , frontmatter : TemplateType.Metadata + , frontmatter : TemplateType , body : String } -> Maybe Rss.Item @@ -69,7 +69,7 @@ metadataToRssItem page = metadataToSitemapEntry : List { path : PagePath Pages.PathKey - , frontmatter : TemplateType.Metadata + , frontmatter : TemplateType , body : String } -> List { path : String, lastMod : Maybe String } diff --git a/examples/docs/src/MetadataNew.elm b/examples/docs/src/MetadataNew.elm index 7f83a7f1..49f3e8af 100644 --- a/examples/docs/src/MetadataNew.elm +++ b/examples/docs/src/MetadataNew.elm @@ -4,7 +4,7 @@ import Json.Decode as Decode exposing (Decoder) import Template.BlogPost import Template.Page import Template.Showcase -import TemplateType as Metadata exposing (Metadata) +import TemplateType exposing (TemplateType) type alias DocMetadata = @@ -16,7 +16,7 @@ type alias PageMetadata = { title : String } -decoder : Decoder Metadata +decoder : Decoder TemplateType decoder = Decode.field "type" Decode.string |> Decode.andThen @@ -24,23 +24,23 @@ decoder = case pageType of "doc" -> Decode.field "title" Decode.string - |> Decode.map (\title -> Metadata.Documentation { title = title }) + |> Decode.map (\title -> TemplateType.Documentation { title = title }) "page" -> Template.Page.decoder - |> Decode.map Metadata.Page + |> Decode.map TemplateType.Page "blog-index" -> Decode.succeed {} - |> Decode.map Metadata.BlogIndex + |> Decode.map TemplateType.BlogIndex "showcase" -> Template.Showcase.decoder - |> Decode.map Metadata.Showcase + |> Decode.map TemplateType.Showcase "blog" -> Template.BlogPost.decoder - |> Decode.map Metadata.BlogPost + |> Decode.map TemplateType.BlogPost _ -> Decode.fail <| "Unexpected page \"type\" " ++ pageType diff --git a/examples/docs/src/Site.elm b/examples/docs/src/Site.elm index cad9f8a6..96c874bb 100644 --- a/examples/docs/src/Site.elm +++ b/examples/docs/src/Site.elm @@ -6,7 +6,7 @@ import Pages.Manifest as Manifest import Pages.Manifest.Category import Pages.PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp -import TemplateType +import TemplateType exposing (TemplateType) type alias SiteConfig = @@ -27,7 +27,7 @@ type alias StaticData = staticData : - List ( PagePath Pages.PathKey, TemplateType.Metadata ) + List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request StaticData staticData siteMetadata = StaticHttp.succeed () diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index eed20131..13e35b1d 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -5,7 +5,7 @@ import Pages import Pages.PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Shared -import TemplateType +import TemplateType exposing (TemplateType) sandbox : @@ -23,19 +23,19 @@ sandbox : sandbox config = application { view = - \dynamicPayload allMetadata staticPayload rendered -> + \model sharedModel allMetadata staticPayload rendered -> config.view staticPayload.metadata staticPayload.path rendered , head = \staticPayload -> config.head staticPayload.metadata staticPayload.path , staticData = \_ -> StaticHttp.succeed () , init = \_ -> ( (), Cmd.none ) - , update = \_ _ _ -> ( (), Cmd.none, Shared.NoOp ) - , subscriptions = \_ _ _ -> Sub.none + , update = \_ _ _ _ -> ( (), Cmd.none, Shared.NoOp ) + , subscriptions = \_ _ _ _ -> Sub.none } simpler : { view : - List ( PagePath Pages.PathKey, TemplateType.Metadata ) + List ( PagePath Pages.PathKey, TemplateType ) -> StaticPayload templateMetadata () -> templateModel -> Shared.RenderedBody @@ -44,19 +44,19 @@ simpler : StaticPayload templateMetadata () -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> DynamicPayload templateModel -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg ) } -> Template templateMetadata () templateModel templateMsg simpler config = application { view = - \dynamicPayload allMetadata staticPayload rendered -> - config.view allMetadata staticPayload dynamicPayload.model rendered + \model sharedModel allMetadata staticPayload rendered -> + config.view allMetadata staticPayload model rendered , head = config.head , staticData = \_ -> StaticHttp.succeed () , init = config.init - , update = \a1 b1 c1 -> config.update a1 b1 c1 |> (\( a, b ) -> ( a, b, Shared.NoOp )) - , subscriptions = \_ _ _ -> Sub.none + , update = \a1 b1 c1 d1 -> config.update a1 b1 c1 d1 |> (\( a, b ) -> ( a, b, Shared.NoOp )) + , subscriptions = \_ _ _ _ -> Sub.none } @@ -64,10 +64,10 @@ simpler config = -} stateless : { staticData : - List ( PagePath Pages.PathKey, TemplateType.Metadata ) + List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request templateStaticData , view : - List ( PagePath Pages.PathKey, TemplateType.Metadata ) + List ( PagePath Pages.PathKey, TemplateType ) -> StaticPayload templateMetadata templateStaticData -> Shared.RenderedBody -> Shared.PageView templateMsg @@ -79,13 +79,13 @@ stateless : stateless config = application { view = - \dynamicPayload allMetadata staticPayload rendered -> + \model sharedModel allMetadata staticPayload rendered -> config.view allMetadata staticPayload rendered , head = config.head , staticData = config.staticData , init = \_ -> ( (), Cmd.none ) - , update = \_ _ _ -> ( (), Cmd.none, Shared.NoOp ) - , subscriptions = \_ _ _ -> Sub.none + , update = \_ _ _ _ -> ( (), Cmd.none, Shared.NoOp ) + , subscriptions = \_ _ _ _ -> Sub.none } @@ -93,11 +93,12 @@ stateless config = -} application : { staticData : - List ( PagePath Pages.PathKey, TemplateType.Metadata ) + List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request templateStaticData , view : - DynamicPayload templateModel - -> List ( PagePath Pages.PathKey, TemplateType.Metadata ) + templateModel + -> Shared.Model + -> List ( PagePath Pages.PathKey, TemplateType ) -> StaticPayload templateMetadata templateStaticData -> Shared.RenderedBody -> Shared.PageView templateMsg @@ -105,8 +106,8 @@ application : StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> DynamicPayload templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) - , subscriptions : templateMetadata -> PagePath Pages.PathKey -> DynamicPayload templateModel -> Sub templateMsg + , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) + , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg } -> Template templateMetadata templateStaticData templateModel templateMsg application config = @@ -121,11 +122,12 @@ application config = type alias Template templateMetadata templateStaticData templateModel templateMsg = { staticData : - List ( PagePath Pages.PathKey, TemplateType.Metadata ) + List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request templateStaticData , view : - DynamicPayload templateModel - -> List ( PagePath Pages.PathKey, TemplateType.Metadata ) + templateModel + -> Shared.Model + -> List ( PagePath Pages.PathKey, TemplateType ) -> StaticPayload templateMetadata templateStaticData -> Shared.RenderedBody -> Shared.PageView templateMsg @@ -133,8 +135,8 @@ type alias Template templateMetadata templateStaticData templateModel templateMs StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> DynamicPayload templateModel -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) - , subscriptions : templateMetadata -> PagePath Pages.PathKey -> DynamicPayload templateModel -> Sub templateMsg + , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) + , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg } @@ -143,14 +145,8 @@ type alias TemplateSandbox templateMetadata = type alias StaticPayload metadata staticData = - { static : staticData - , sharedStatic : Shared.StaticData + { static : staticData -- local + , sharedStatic : Shared.StaticData -- share , metadata : metadata , path : PagePath Pages.PathKey } - - -type alias DynamicPayload model = - { model : model - , sharedModel : Shared.Model - } diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 7b182197..ab97f3d5 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -10,9 +10,9 @@ import Pages.StaticHttp as StaticHttp import Shared import Showcase import Site -import Template exposing (DynamicPayload, StaticPayload, Template) +import Template exposing (StaticPayload, Template) import TemplateMetadata exposing (BlogIndex) -import TemplateType +import TemplateType exposing (TemplateType) type Msg @@ -27,12 +27,12 @@ template = , staticData = staticData , init = init , update = update - , subscriptions = \_ _ _ -> Sub.none + , subscriptions = \_ _ _ _ -> Sub.none } staticData : - List ( PagePath Pages.PathKey, TemplateType.Metadata ) + List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request StaticData staticData siteMetadata = Showcase.staticRequest @@ -47,9 +47,9 @@ init metadata = ( Model, Cmd.none ) -update : BlogIndex -> Msg -> DynamicPayload Model -> ( Model, Cmd Msg, Shared.SharedMsg ) -update metadata msg model = - ( model.model, Cmd.none, Shared.NoOp ) +update : BlogIndex -> Msg -> Model -> Shared.Model -> ( Model, Cmd Msg, Shared.SharedMsg ) +update metadata msg model sharedModel = + ( model, Cmd.none, Shared.NoOp ) type alias Model = @@ -57,12 +57,13 @@ type alias Model = view : - DynamicPayload Model - -> List ( PagePath Pages.PathKey, TemplateType.Metadata ) + Model + -> Shared.Model + -> List ( PagePath Pages.PathKey, TemplateType ) -> StaticPayload BlogIndex StaticData -> Shared.RenderedBody -> Shared.PageView Msg -view dynamicPayload allMetadata staticPayload rendered = +view model sharedModel allMetadata staticPayload rendered = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 87d24096..7356ec7e 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -16,7 +16,7 @@ import Palette import Shared import Site import StructuredData -import Template exposing (DynamicPayload, StaticPayload, Template, TemplateSandbox) +import Template exposing (StaticPayload, Template, TemplateSandbox) import TemplateMetadata exposing (BlogPost) diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 772b3b41..17d83547 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -15,9 +15,9 @@ import Pages.StaticHttp as StaticHttp import Palette import Shared import Site -import Template exposing (DynamicPayload, StaticPayload, Template) +import Template exposing (StaticPayload, Template) import TemplateMetadata exposing (Documentation) -import TemplateType +import TemplateType exposing (TemplateType) type alias StaticData = @@ -40,7 +40,7 @@ template = , staticData = staticData , init = init , update = update - , subscriptions = \_ _ _ -> Sub.none + , subscriptions = \_ _ _ _ -> Sub.none } @@ -49,15 +49,15 @@ init metadata = ( {}, Cmd.none ) -update : Documentation -> Msg -> DynamicPayload Model -> ( Model, Cmd Msg, Shared.SharedMsg ) -update metadata msg dynamic = +update : Documentation -> Msg -> Model -> Shared.Model -> ( Model, Cmd Msg, Shared.SharedMsg ) +update metadata msg model sharedModel = case msg of Increment -> - ( dynamic.model, Cmd.none, Shared.IncrementFromChild ) + ( model, Cmd.none, Shared.IncrementFromChild ) staticData : - List ( PagePath Pages.PathKey, TemplateType.Metadata ) + List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request StaticData staticData siteMetadata = StaticHttp.succeed () @@ -88,16 +88,17 @@ head staticPayload = view : - DynamicPayload Model - -> List ( PagePath Pages.PathKey, TemplateType.Metadata ) + Model + -> Shared.Model + -> List ( PagePath Pages.PathKey, TemplateType ) -> StaticPayload Documentation StaticData -> Shared.RenderedBody -> Shared.PageView Msg -view dynamicPayload allMetadata staticPayload rendered = +view model sharedModel allMetadata staticPayload rendered = { title = staticPayload.metadata.title , body = [ Element.row [] - [ counterView dynamicPayload.sharedModel + [ counterView sharedModel , DocSidebar.view Pages.pages.index allMetadata diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index 3dae43de..e5988408 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -11,7 +11,7 @@ import Shared import Showcase import Template exposing (StaticPayload, Template) import TemplateMetadata exposing (Showcase) -import TemplateType +import TemplateType exposing (TemplateType) type alias Model = @@ -25,7 +25,6 @@ type Msg template : Template Showcase StaticData () Msg template = Template.stateless - -- static { view = view , head = head , staticData = staticData @@ -38,7 +37,7 @@ decoder = staticData : - List ( PagePath Pages.PathKey, TemplateType.Metadata ) + List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request StaticData staticData siteMetadata = Showcase.staticRequest @@ -49,7 +48,7 @@ type alias StaticData = view : - List ( PagePath Pages.PathKey, TemplateType.Metadata ) + List ( PagePath Pages.PathKey, TemplateType ) -> StaticPayload Showcase StaticData -> Shared.RenderedBody -> Shared.PageView msg diff --git a/examples/docs/src/GlobalMetadata.elm b/examples/docs/src/TemplateType.elm similarity index 78% rename from examples/docs/src/GlobalMetadata.elm rename to examples/docs/src/TemplateType.elm index 3bd43bda..9a52dfdc 100644 --- a/examples/docs/src/GlobalMetadata.elm +++ b/examples/docs/src/TemplateType.elm @@ -1,9 +1,9 @@ -module TemplateType exposing (..) +module TemplateType exposing (TemplateType(..)) import TemplateMetadata -type Metadata +type TemplateType = BlogPost TemplateMetadata.BlogPost | Showcase TemplateMetadata.Showcase | Page TemplateMetadata.Page diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 8b64d25a..abb80402 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -10,7 +10,7 @@ function generateTemplateModuleConnector() { import Browser import Pages.Manifest as Manifest import Shared -import TemplateType as M exposing (Metadata) +import TemplateType as M exposing (TemplateType) import Head import Html exposing (Html) import Pages @@ -30,7 +30,7 @@ type alias Model = , query : Maybe String , fragment : Maybe String } - , metadata : Metadata + , metadata : TemplateType } } @@ -47,16 +47,16 @@ type Msg { path : PagePath Pages.PathKey , query : Maybe String , fragment : Maybe String - , metadata : Metadata + , metadata : TemplateType } | ${templates.map(name => `Msg${name} Template.${name}.Msg\n`).join(" | ")} view : - List ( PagePath Pages.PathKey, Metadata ) + List ( PagePath Pages.PathKey, TemplateType ) -> { path : PagePath Pages.PathKey - , frontmatter : Metadata + , frontmatter : TemplateType } -> StaticHttp.Request @@ -66,7 +66,7 @@ view : view siteMetadata page = case page.frontmatter of ${templates.map(name => - `M.Metadata${name} metadata -> + `M.${name} metadata -> StaticHttp.map2 (\\data globalData -> { view = @@ -74,9 +74,8 @@ view siteMetadata page = case model.page of Model${name} subModel -> Template.${name}.template.view - { model = subModel - , sharedModel = model.global - } + subModel + model.global siteMetadata { static = data , sharedStatic = globalData @@ -120,7 +119,7 @@ init : , query : Maybe String , fragment : Maybe String } - , metadata : Metadata + , metadata : TemplateType } -> ( Model, Cmd Msg ) init currentGlobalModel maybePagePath = @@ -135,7 +134,7 @@ init currentGlobalModel maybePagePath = Just meta -> case meta of - ${templates.map(name => `M.Metadata${name} metadata -> + ${templates.map(name => `M.${name} metadata -> Template.${name}.template.init metadata |> Tuple.mapBoth Model${name} (Cmd.map Msg${name}) @@ -181,11 +180,12 @@ update msg model = let ( updatedPageModel, pageCmd, ( newGlobalModel, newGlobalCmd ) ) = case ( model.page, model.current |> Maybe.map .metadata ) of - ( Model${name} pageModel, Just (M.Metadata${name} metadata) ) -> + ( Model${name} pageModel, Just (M.${name} metadata) ) -> Template.${name}.template.update metadata msg_ - { sharedModel = model.global, model = pageModel } + pageModel + model.global |> mapBoth Model${name} (Cmd.map Msg${name}) |> (\\( a, b, c ) -> ( a, b, Shared.update (Shared.SharedMsg c) model.global ) @@ -206,19 +206,18 @@ type alias SiteConfig = , manifest : Manifest.Config Pages.PathKey } -templateSubscriptions : Metadata -> PagePath Pages.PathKey -> Model -> Sub Msg +templateSubscriptions : TemplateType -> PagePath Pages.PathKey -> Model -> Sub Msg templateSubscriptions metadata path model = case model.page of ${templates.map(name => ` Model${name} templateModel -> case metadata of - M.Metadata${name} templateMetadata -> + M.${name} templateMetadata -> Template.${name}.template.subscriptions templateMetadata path - { model = templateModel - , sharedModel = model.global - } + templateModel + model.global |> Sub.map Msg${name} _ -> From 9423b62a0c480339f64723e9b60d09944f6b8020 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Thu, 24 Sep 2020 09:04:15 -0700 Subject: [PATCH 082/106] Add builder-style Template API. --- examples/docs/src/Template.elm | 120 +++++++++++++++++++ examples/docs/src/Template/BlogIndex.elm | 14 ++- examples/docs/src/Template/BlogPost.elm | 18 ++- examples/docs/src/Template/Documentation.elm | 15 ++- examples/docs/src/Template/Page.elm | 18 ++- examples/docs/src/Template/Showcase.elm | 10 +- tests/src/Template/BlogPost.elm | 24 +--- 7 files changed, 162 insertions(+), 57 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 13e35b1d..b97c1c8c 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -8,6 +8,126 @@ import Shared import TemplateType exposing (TemplateType) +withLocalState : + { init : templateMetadata -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) + , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg + } + -> Builder templateMetadata templateStaticData templateModel templateMsg + -> Builder templateMetadata templateStaticData templateModel templateMsg +withLocalState { init, update } builderState = + builderState + + +type Builder templateMetadata templateStaticData templateModel templateMsg + = WithStaticData + { staticData : + List ( PagePath Pages.PathKey, TemplateType ) + -> StaticHttp.Request templateStaticData + , head : + StaticPayload templateMetadata templateStaticData + -> List (Head.Tag Pages.PathKey) + } + + +buildNoState : + { view : + List ( PagePath Pages.PathKey, TemplateType ) + -> StaticPayload templateMetadata templateStaticData + -> Shared.RenderedBody + -> Shared.PageView Never + } + -> Builder templateMetadata templateStaticData templateModel templateMsg + -> Template templateMetadata templateStaticData () Never +buildNoState { view } builderState = + case builderState of + WithStaticData record -> + application + { view = \() _ -> view + , head = record.head + , staticData = record.staticData + , init = \_ -> ( (), Cmd.none ) + , update = \_ _ _ _ -> ( (), Cmd.none, Shared.NoOp ) + , subscriptions = \_ _ _ _ -> Sub.none + } + + +buildWithLocalState : + { view : + templateModel + -> Shared.Model + -> List ( PagePath Pages.PathKey, TemplateType ) + -> StaticPayload templateMetadata templateStaticData + -> Shared.RenderedBody + -> Shared.PageView templateMsg + , init : templateMetadata -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) + , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg + } + -> Builder templateMetadata templateStaticData templateModel templateMsg + -> Template templateMetadata templateStaticData templateModel templateMsg +buildWithLocalState config builderState = + case builderState of + WithStaticData record -> + application + { view = config.view + , head = record.head + , staticData = record.staticData + , init = config.init + , update = config.update + , subscriptions = config.subscriptions + } + + +buildWithSharedState : + { view : + templateModel + -> Shared.Model + -> List ( PagePath Pages.PathKey, TemplateType ) + -> StaticPayload templateMetadata templateStaticData + -> Shared.RenderedBody + -> Shared.PageView templateMsg + , init : templateMetadata -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) + , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg + } + -> Builder templateMetadata templateStaticData templateModel templateMsg + -> Template templateMetadata templateStaticData templateModel templateMsg +buildWithSharedState config builderState = + case builderState of + WithStaticData record -> + application + { view = config.view + , head = record.head + , staticData = record.staticData + , init = config.init + , update = config.update + , subscriptions = config.subscriptions + } + + +withStaticData : + { staticData : List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request templateStaticData + , head : StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) + } + -> Builder templateMetadata templateStaticData templateModel templateMsg +withStaticData { staticData, head } = + WithStaticData + { staticData = staticData + , head = head + } + + +noStaticData : + { head : StaticPayload templateMetadata () -> List (Head.Tag Pages.PathKey) } + -> Builder templateMetadata () templateModel templateMsg +noStaticData { head } = + WithStaticData + { staticData = \_ -> StaticHttp.succeed () + , head = head + } + + sandbox : { view : templateMetadata diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index ab97f3d5..8ae88e16 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -21,14 +21,16 @@ type Msg template : Template BlogIndex StaticData Model Msg template = - Template.application - { view = view - , head = head + Template.withStaticData + { head = head , staticData = staticData - , init = init - , update = update - , subscriptions = \_ _ _ _ -> Sub.none } + |> Template.buildWithSharedState + { view = view + , init = init + , update = update + , subscriptions = \_ _ _ _ -> Sub.none + } staticData : diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 7356ec7e..7f154c2f 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -18,6 +18,7 @@ import Site import StructuredData import Template exposing (StaticPayload, Template, TemplateSandbox) import TemplateMetadata exposing (BlogPost) +import TemplateType exposing (TemplateType) type alias Model = @@ -30,10 +31,8 @@ type alias Msg = template : TemplateSandbox BlogPost template = - Template.sandbox - { view = view - , head = head - } + Template.noStaticData { head = head } + |> Template.buildNoState { view = view } decoder : Decode.Decoder BlogPost @@ -82,11 +81,11 @@ findMatchingImage imageAssetPath = view : - BlogPost - -> PagePath Pages.PathKey + List ( PagePath Pages.PathKey, TemplateType ) + -> StaticPayload BlogPost () -> Shared.RenderedBody -> Shared.PageView msg -view metadata path rendered = +view allMetadata { metadata } rendered = { title = metadata.title , body = Element.column [ Element.width Element.fill ] @@ -120,10 +119,9 @@ view metadata path rendered = head : - BlogPost - -> PagePath Pages.PathKey + StaticPayload BlogPost () -> List (Head.Tag Pages.PathKey) -head metadata path = +head { metadata, path } = Head.structuredData (StructuredData.article { title = metadata.title diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 17d83547..a394d31f 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -34,14 +34,13 @@ type Msg template : Template Documentation StaticData Model Msg template = - Template.application - { view = view - , head = head - , staticData = staticData - , init = init - , update = update - , subscriptions = \_ _ _ _ -> Sub.none - } + Template.noStaticData { head = head } + |> Template.buildWithSharedState + { view = view + , init = init + , update = update + , subscriptions = \_ _ _ _ -> Sub.none + } init : Documentation -> ( Model, Cmd Msg ) diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index 6e713027..0bb1bf8e 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -11,6 +11,7 @@ import Shared import Site import Template exposing (StaticPayload, Template) import TemplateMetadata exposing (Page) +import TemplateType exposing (TemplateType) type alias Model = @@ -23,10 +24,8 @@ type alias Msg = template : Template.TemplateSandbox Page template = - Template.sandbox - { view = view - , head = head - } + Template.noStaticData { head = head } + |> Template.buildNoState { view = view } decoder : Decode.Decoder Page @@ -36,10 +35,9 @@ decoder = head : - Page - -> PagePath Pages.PathKey + StaticPayload Page () -> List (Head.Tag Pages.PathKey) -head metadata path = +head { metadata } = Seo.summary { canonicalUrlOverride = Nothing , siteName = "elm-pages" @@ -57,11 +55,11 @@ head metadata path = view : - Page - -> PagePath Pages.PathKey + List ( PagePath Pages.PathKey, TemplateType ) + -> StaticPayload Page () -> Shared.RenderedBody -> Shared.PageView msg -view metadata path rendered = +view allMetadata { metadata } rendered = { title = metadata.title , body = [ Element.column diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index e5988408..4ae81cb9 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -18,17 +18,17 @@ type alias Model = () -type Msg - = Msg +type alias Msg = + Never template : Template Showcase StaticData () Msg template = - Template.stateless - { view = view - , head = head + Template.withStaticData + { head = head , staticData = staticData } + |> Template.buildNoState { view = view } decoder : Decoder Showcase diff --git a/tests/src/Template/BlogPost.elm b/tests/src/Template/BlogPost.elm index be5e522c..1498e806 100644 --- a/tests/src/Template/BlogPost.elm +++ b/tests/src/Template/BlogPost.elm @@ -24,23 +24,18 @@ import TemplateDocument exposing (TemplateDocument) import TemplateType -type Model - = Model +type alias Model = + () -type Msg - = Msg +type alias Msg = + Never template : TemplateDocument BlogPost StaticData Model Msg template = - Template.template - { view = view - , head = head - , staticData = staticData - , init = init - , update = update - } + Template.withStaticData staticData head + |> Template.buildNoState { view = view } decoder : Decode.Decoder BlogPost @@ -90,15 +85,8 @@ findMatchingImage imageAssetPath = Pages.allImages -init : BlogPost -> ( Model, Cmd Msg ) -init metadata = - ( Model, Cmd.none ) -update : BlogPost -> Msg -> Model -> ( Model, Cmd Msg ) -update metadata msg model = - ( Model, Cmd.none ) - staticData : a -> StaticHttp.Request StaticData staticData siteMetadata = From 222cd34f887a943a8712960ba126c47e4ec91f74 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Thu, 24 Sep 2020 09:10:30 -0700 Subject: [PATCH 083/106] Remove obsolete type variables. --- examples/docs/src/Template.elm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index b97c1c8c..7c88a1e3 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -13,13 +13,13 @@ withLocalState : , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg } - -> Builder templateMetadata templateStaticData templateModel templateMsg - -> Builder templateMetadata templateStaticData templateModel templateMsg + -> Builder templateMetadata templateStaticData + -> Builder templateMetadata templateStaticData withLocalState { init, update } builderState = builderState -type Builder templateMetadata templateStaticData templateModel templateMsg +type Builder templateMetadata templateStaticData = WithStaticData { staticData : List ( PagePath Pages.PathKey, TemplateType ) @@ -37,7 +37,7 @@ buildNoState : -> Shared.RenderedBody -> Shared.PageView Never } - -> Builder templateMetadata templateStaticData templateModel templateMsg + -> Builder templateMetadata templateStaticData -> Template templateMetadata templateStaticData () Never buildNoState { view } builderState = case builderState of @@ -64,7 +64,7 @@ buildWithLocalState : , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg } - -> Builder templateMetadata templateStaticData templateModel templateMsg + -> Builder templateMetadata templateStaticData -> Template templateMetadata templateStaticData templateModel templateMsg buildWithLocalState config builderState = case builderState of @@ -91,7 +91,7 @@ buildWithSharedState : , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg } - -> Builder templateMetadata templateStaticData templateModel templateMsg + -> Builder templateMetadata templateStaticData -> Template templateMetadata templateStaticData templateModel templateMsg buildWithSharedState config builderState = case builderState of @@ -110,7 +110,7 @@ withStaticData : { staticData : List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request templateStaticData , head : StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) } - -> Builder templateMetadata templateStaticData templateModel templateMsg + -> Builder templateMetadata templateStaticData withStaticData { staticData, head } = WithStaticData { staticData = staticData @@ -120,7 +120,7 @@ withStaticData { staticData, head } = noStaticData : { head : StaticPayload templateMetadata () -> List (Head.Tag Pages.PathKey) } - -> Builder templateMetadata () templateModel templateMsg + -> Builder templateMetadata () noStaticData { head } = WithStaticData { staticData = \_ -> StaticHttp.succeed () From 9bdfee82f66bdb10b9fec0ccc1bf1447ea5d3f4a Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Thu, 24 Sep 2020 09:12:14 -0700 Subject: [PATCH 084/106] Remove unused. --- examples/docs/src/Template.elm | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 7c88a1e3..f8ebfe32 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -8,17 +8,6 @@ import Shared import TemplateType exposing (TemplateType) -withLocalState : - { init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) - , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg - } - -> Builder templateMetadata templateStaticData - -> Builder templateMetadata templateStaticData -withLocalState { init, update } builderState = - builderState - - type Builder templateMetadata templateStaticData = WithStaticData { staticData : From 8182563f12d1acd20eb613e19f5534597b8ff748 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Thu, 24 Sep 2020 09:24:14 -0700 Subject: [PATCH 085/106] Narrow withLocalState signature. --- examples/docs/src/Template.elm | 21 +++++++++++++++------ examples/docs/src/Template/BlogIndex.elm | 17 ++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index f8ebfe32..a3df8422 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -44,14 +44,13 @@ buildNoState { view } builderState = buildWithLocalState : { view : templateModel - -> Shared.Model -> List ( PagePath Pages.PathKey, TemplateType ) -> StaticPayload templateMetadata templateStaticData -> Shared.RenderedBody -> Shared.PageView templateMsg , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) - , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg + , update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg ) + , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Sub templateMsg } -> Builder templateMetadata templateStaticData -> Template templateMetadata templateStaticData templateModel templateMsg @@ -59,12 +58,22 @@ buildWithLocalState config builderState = case builderState of WithStaticData record -> application - { view = config.view + { view = + \model sharedModel allMetadata staticPayload rendered -> + config.view model allMetadata staticPayload rendered , head = record.head , staticData = record.staticData , init = config.init - , update = config.update - , subscriptions = config.subscriptions + , update = + \metadata msg templateModel sharedModel_ -> + let + ( updatedModel, cmd ) = + config.update metadata msg templateModel + in + ( updatedModel, cmd, Shared.NoOp ) + , subscriptions = + \templateMetadata path templateModel sharedModel -> + config.subscriptions templateMetadata path templateModel } diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index 8ae88e16..a8ef67c1 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -25,11 +25,11 @@ template = { head = head , staticData = staticData } - |> Template.buildWithSharedState + |> Template.buildWithLocalState { view = view , init = init , update = update - , subscriptions = \_ _ _ _ -> Sub.none + , subscriptions = \_ _ _ -> Sub.none } @@ -49,9 +49,13 @@ init metadata = ( Model, Cmd.none ) -update : BlogIndex -> Msg -> Model -> Shared.Model -> ( Model, Cmd Msg, Shared.SharedMsg ) -update metadata msg model sharedModel = - ( model, Cmd.none, Shared.NoOp ) +update : + BlogIndex + -> Msg + -> Model + -> ( Model, Cmd Msg ) +update metadata msg model = + ( model, Cmd.none ) type alias Model = @@ -60,12 +64,11 @@ type alias Model = view : Model - -> Shared.Model -> List ( PagePath Pages.PathKey, TemplateType ) -> StaticPayload BlogIndex StaticData -> Shared.RenderedBody -> Shared.PageView Msg -view model sharedModel allMetadata staticPayload rendered = +view model allMetadata staticPayload rendered = { title = "elm-pages blog" , body = Element.column [ Element.width Element.fill ] From 6b5b21e709dd70035f29adbe5fc35f6213327953 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 30 Sep 2020 13:05:35 -0700 Subject: [PATCH 086/106] Update Template types. --- examples/docs/src/Main.elm | 1 - examples/docs/src/Shared.elm | 4 ++ examples/docs/src/Template.elm | 15 ++++- examples/docs/src/Template/BlogPost.elm | 4 +- examples/docs/src/Template/Page.elm | 4 +- .../src/generate-template-module-connector.js | 62 ++++++++++++------- src/Head.elm | 4 +- src/StructuredData.elm | 10 +-- 8 files changed, 67 insertions(+), 37 deletions(-) diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 2c64b923..91a477ab 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -25,7 +25,6 @@ main = } ] , site = Site.config - , subscriptions = Sub.none } |> RssPlugin.generate { siteTagline = Site.tagline diff --git a/examples/docs/src/Shared.elm b/examples/docs/src/Shared.elm index 9c45e6b0..5a19439e 100644 --- a/examples/docs/src/Shared.elm +++ b/examples/docs/src/Shared.elm @@ -92,6 +92,10 @@ type alias StaticData = Int +subscriptions _ _ _ = + Sub.none + + staticData : a -> StaticHttp.Request StaticData staticData siteMetadata = StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages") diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index a3df8422..4b15a04b 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -137,7 +137,7 @@ sandbox : -> PagePath Pages.PathKey -> List (Head.Tag Pages.PathKey) } - -> TemplateSandbox templateMetadata + -> Template_ templateMetadata () sandbox config = application { view = @@ -258,8 +258,17 @@ type alias Template templateMetadata templateStaticData templateModel templateMs } -type alias TemplateSandbox templateMetadata = - Template templateMetadata () () Never +type alias TemplateWithState templateMetadata templateStaticData templateModel templateMsg = + Template templateMetadata templateStaticData templateModel templateMsg + + + +--type alias Template_ templateMetadata = +-- Template templateMetadata () () Never + + +type alias Template_ templateMetadata staticData = + Template templateMetadata staticData () Never type alias StaticPayload metadata staticData = diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index 7f154c2f..aadd94c4 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -16,7 +16,7 @@ import Palette import Shared import Site import StructuredData -import Template exposing (StaticPayload, Template, TemplateSandbox) +import Template exposing (StaticPayload, Template, Template_) import TemplateMetadata exposing (BlogPost) import TemplateType exposing (TemplateType) @@ -29,7 +29,7 @@ type alias Msg = Never -template : TemplateSandbox BlogPost +template : Template_ BlogPost () template = Template.noStaticData { head = head } |> Template.buildNoState { view = view } diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index 0bb1bf8e..b0a37738 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -9,7 +9,7 @@ import Pages exposing (images) import Pages.PagePath exposing (PagePath) import Shared import Site -import Template exposing (StaticPayload, Template) +import Template exposing (StaticPayload, Template, Template_) import TemplateMetadata exposing (Page) import TemplateType exposing (TemplateType) @@ -22,7 +22,7 @@ type alias Msg = Never -template : Template.TemplateSandbox Page +template : Template_ Page () template = Template.noStaticData { head = head } |> Template.buildNoState { view = view } diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index abb80402..166316a1 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -1,11 +1,12 @@ -const globby = require("globby") -const path = require("path") - +const globby = require("globby"); +const path = require("path"); function generateTemplateModuleConnector() { - const templates = globby.sync(["src/Template/*.elm"], {}).map(file => path.basename(file, '.elm')) + const templates = globby + .sync(["src/Template/*.elm"], {}) + .map((file) => path.basename(file, ".elm")); - return `module TemplateDemultiplexer exposing (..) + return `module TemplateDemultiplexer exposing (..) import Browser import Pages.Manifest as Manifest @@ -17,7 +18,7 @@ import Pages import Pages.PagePath exposing (PagePath) import Pages.Platform import Pages.StaticHttp as StaticHttp -${templates.map(name => `import Template.${name}`).join("\n")} +${templates.map((name) => `import Template.${name}`).join("\n")} type alias Model = @@ -36,7 +37,9 @@ type alias Model = type TemplateModel - = ${templates.map(name => `Model${name} Template.${name}.Model\n`).join(" | ")} + = ${templates + .map((name) => `Model${name} Template.${name}.Model\n`) + .join(" | ")} | NotFound @@ -49,7 +52,9 @@ type Msg , fragment : Maybe String , metadata : TemplateType } - | ${templates.map(name => `Msg${name} Template.${name}.Msg\n`).join(" | ")} + | ${templates + .map((name) => `Msg${name} Template.${name}.Msg\n`) + .join(" | ")} view : @@ -65,8 +70,10 @@ view : } view siteMetadata page = case page.frontmatter of - ${templates.map(name => - `M.${name} metadata -> + ${templates + .map( + (name) => + `M.${name} metadata -> StaticHttp.map2 (\\data globalData -> { view = @@ -106,8 +113,9 @@ view siteMetadata page = ) (Template.${name}.template.staticData siteMetadata) (Shared.staticData siteMetadata) -`).join("\n\n ") - } +` + ) + .join("\n\n ")} init : @@ -134,11 +142,15 @@ init currentGlobalModel maybePagePath = Just meta -> case meta of - ${templates.map(name => `M.${name} metadata -> + ${templates + .map( + (name) => `M.${name} metadata -> Template.${name}.template.init metadata |> Tuple.mapBoth Model${name} (Cmd.map Msg${name}) -`).join("\n ")} +` + ) + .join("\n ")} in ( { global = sharedModel , page = templateModel @@ -175,7 +187,9 @@ update msg model = , metadata = record.metadata } - ${templates.map(name => ` + ${templates + .map( + (name) => ` Msg${name} msg_ -> let ( updatedPageModel, pageCmd, ( newGlobalModel, newGlobalCmd ) ) = @@ -198,7 +212,8 @@ update msg model = , Cmd.batch [ pageCmd, newGlobalCmd |> Cmd.map MsgGlobal ] ) ` - ).join("\n ")} + ) + .join("\n ")} type alias SiteConfig = @@ -209,7 +224,9 @@ type alias SiteConfig = templateSubscriptions : TemplateType -> PagePath Pages.PathKey -> Model -> Sub Msg templateSubscriptions metadata path model = case model.page of - ${templates.map(name => ` + ${templates + .map( + (name) => ` Model${name} templateModel -> case metadata of M.${name} templateMetadata -> @@ -223,14 +240,15 @@ templateSubscriptions metadata path model = _ -> Sub.none ` - ).join("\n ")} + ) + .join("\n ")} NotFound -> Sub.none -mainTemplate { documents, subscriptions, site } = +mainTemplate { documents, site } = Pages.Platform.init { init = init Nothing , view = view @@ -238,7 +256,7 @@ mainTemplate { documents, subscriptions, site } = , subscriptions = \\metadata path model -> Sub.batch - [ subscriptions + [ Shared.subscriptions metadata path model.global |> Sub.map MsgGlobal , templateSubscriptions metadata path model ] , documents = documents @@ -259,7 +277,7 @@ mapDocument document = mapBoth fnA fnB ( a, b, c ) = ( fnA a, fnB b, c ) -` +`; } -module.exports = { generateTemplateModuleConnector } \ No newline at end of file +module.exports = { generateTemplateModuleConnector }; diff --git a/src/Head.elm b/src/Head.elm index d3cdfc47..289537ad 100644 --- a/src/Head.elm +++ b/src/Head.elm @@ -105,8 +105,8 @@ To get that data, you would write this in your `elm-pages` head tags: encodeArticle : { title : String , description : String - , author : StructuredData { authorMemberOf | personOrOrganization : () } authorPossibleFields - , publisher : StructuredData { publisherMemberOf | personOrOrganization : () } publisherPossibleFields + , author : StructuredDataHelper { authorMemberOf | personOrOrganization : () } authorPossibleFields + , publisher : StructuredDataHelper { publisherMemberOf | personOrOrganization : () } publisherPossibleFields , url : String , imageUrl : String , datePublished : String diff --git a/src/StructuredData.elm b/src/StructuredData.elm index ef84d72a..ee69d6a6 100644 --- a/src/StructuredData.elm +++ b/src/StructuredData.elm @@ -132,7 +132,7 @@ encode (StructuredData typeName fields) = ---example : StructuredData { personOrOrganization : () } { address : (), affiliation : () } +--example : StructuredDataHelper { personOrOrganization : () } { address : (), affiliation : () } example = @@ -143,12 +143,12 @@ example = --organization : -- {} --- -> StructuredData { personOrOrganization : () } +-- -> StructuredDataHelper { personOrOrganization : () } --organization info = --- StructuredData "Organization" [] ---needsPersonOrOrg : StructuredData {} +-- StructuredDataHelper "Organization" [] +--needsPersonOrOrg : StructuredDataHelper {} --needsPersonOrOrg = --- StructuredData "" [] +-- StructuredDataHelper "" [] {-| From 3f0d3320c644197b6759f9edb6042d2107660240 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Thu, 1 Oct 2020 12:00:03 -0700 Subject: [PATCH 087/106] Add starting point for shared template. --- examples/docs/src/Shared.elm | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/examples/docs/src/Shared.elm b/examples/docs/src/Shared.elm index 5a19439e..33064ac0 100644 --- a/examples/docs/src/Shared.elm +++ b/examples/docs/src/Shared.elm @@ -19,6 +19,7 @@ import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Palette import Secrets +import TemplateType exposing (TemplateType) type SharedMsg @@ -58,6 +59,33 @@ type Msg | SharedMsg SharedMsg +sharedTemplate : + { init : a -> ( Model, Cmd Msg ) + , update : Msg -> Model -> ( Model, Cmd Msg ) + , view : + StaticData + -> + { path : PagePath Pages.PathKey + , frontmatter : TemplateType + } + -> Model + -> (Msg -> msg) + -> PageView msg + -> { body : Html msg, title : String } + , map : (msg1 -> msg2) -> PageView msg1 -> PageView msg2 + , staticData : List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request StaticData + , subscriptions : TemplateType -> PagePath Pages.PathKey -> Model -> Sub Msg + } +sharedTemplate = + { init = init + , update = update + , view = view + , map = map + , staticData = staticData + , subscriptions = subscriptions + } + + init : a -> ( Model, Cmd Msg ) init maybePagePath = ( { showMobileMenu = False @@ -92,6 +120,7 @@ type alias StaticData = Int +subscriptions : TemplateType -> PagePath Pages.PathKey -> Model -> Sub Msg subscriptions _ _ _ = Sub.none @@ -104,7 +133,10 @@ staticData siteMetadata = view : StaticData - -> { a | path : PagePath Pages.PathKey } + -> + { path : PagePath Pages.PathKey + , frontmatter : TemplateType + } -> Model -> (Msg -> msg) -> PageView msg From a9dc8c53e2ac4696c1a49fc136f1badd4fe80926 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Thu, 1 Oct 2020 12:01:54 -0700 Subject: [PATCH 088/106] Remove unused constructor functions. --- examples/docs/src/Template.elm | 177 ++++++--------------------------- 1 file changed, 31 insertions(+), 146 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 4b15a04b..6c3617ea 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -31,14 +31,13 @@ buildNoState : buildNoState { view } builderState = case builderState of WithStaticData record -> - application - { view = \() _ -> view - , head = record.head - , staticData = record.staticData - , init = \_ -> ( (), Cmd.none ) - , update = \_ _ _ _ -> ( (), Cmd.none, Shared.NoOp ) - , subscriptions = \_ _ _ _ -> Sub.none - } + { view = \() _ -> view + , head = record.head + , staticData = record.staticData + , init = \_ -> ( (), Cmd.none ) + , update = \_ _ _ _ -> ( (), Cmd.none, Shared.NoOp ) + , subscriptions = \_ _ _ _ -> Sub.none + } buildWithLocalState : @@ -57,24 +56,23 @@ buildWithLocalState : buildWithLocalState config builderState = case builderState of WithStaticData record -> - application - { view = - \model sharedModel allMetadata staticPayload rendered -> - config.view model allMetadata staticPayload rendered - , head = record.head - , staticData = record.staticData - , init = config.init - , update = - \metadata msg templateModel sharedModel_ -> - let - ( updatedModel, cmd ) = - config.update metadata msg templateModel - in - ( updatedModel, cmd, Shared.NoOp ) - , subscriptions = - \templateMetadata path templateModel sharedModel -> - config.subscriptions templateMetadata path templateModel - } + { view = + \model sharedModel allMetadata staticPayload rendered -> + config.view model allMetadata staticPayload rendered + , head = record.head + , staticData = record.staticData + , init = config.init + , update = + \metadata msg templateModel sharedModel_ -> + let + ( updatedModel, cmd ) = + config.update metadata msg templateModel + in + ( updatedModel, cmd, Shared.NoOp ) + , subscriptions = + \templateMetadata path templateModel sharedModel -> + config.subscriptions templateMetadata path templateModel + } buildWithSharedState : @@ -94,14 +92,13 @@ buildWithSharedState : buildWithSharedState config builderState = case builderState of WithStaticData record -> - application - { view = config.view - , head = record.head - , staticData = record.staticData - , init = config.init - , update = config.update - , subscriptions = config.subscriptions - } + { view = config.view + , head = record.head + , staticData = record.staticData + , init = config.init + , update = config.update + , subscriptions = config.subscriptions + } withStaticData : @@ -126,118 +123,6 @@ noStaticData { head } = } -sandbox : - { view : - templateMetadata - -> PagePath Pages.PathKey - -> Shared.RenderedBody - -> Shared.PageView Never - , head : - templateMetadata - -> PagePath Pages.PathKey - -> List (Head.Tag Pages.PathKey) - } - -> Template_ templateMetadata () -sandbox config = - application - { view = - \model sharedModel allMetadata staticPayload rendered -> - config.view staticPayload.metadata staticPayload.path rendered - , head = \staticPayload -> config.head staticPayload.metadata staticPayload.path - , staticData = \_ -> StaticHttp.succeed () - , init = \_ -> ( (), Cmd.none ) - , update = \_ _ _ _ -> ( (), Cmd.none, Shared.NoOp ) - , subscriptions = \_ _ _ _ -> Sub.none - } - - -simpler : - { view : - List ( PagePath Pages.PathKey, TemplateType ) - -> StaticPayload templateMetadata () - -> templateModel - -> Shared.RenderedBody - -> Shared.PageView templateMsg - , head : - StaticPayload templateMetadata () - -> List (Head.Tag Pages.PathKey) - , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg ) - } - -> Template templateMetadata () templateModel templateMsg -simpler config = - application - { view = - \model sharedModel allMetadata staticPayload rendered -> - config.view allMetadata staticPayload model rendered - , head = config.head - , staticData = \_ -> StaticHttp.succeed () - , init = config.init - , update = \a1 b1 c1 d1 -> config.update a1 b1 c1 d1 |> (\( a, b ) -> ( a, b, Shared.NoOp )) - , subscriptions = \_ _ _ _ -> Sub.none - } - - -{-| Basic `staticData` (including access to Shared static data) --} -stateless : - { staticData : - List ( PagePath Pages.PathKey, TemplateType ) - -> StaticHttp.Request templateStaticData - , view : - List ( PagePath Pages.PathKey, TemplateType ) - -> StaticPayload templateMetadata templateStaticData - -> Shared.RenderedBody - -> Shared.PageView templateMsg - , head : - StaticPayload templateMetadata templateStaticData - -> List (Head.Tag Pages.PathKey) - } - -> Template templateMetadata templateStaticData () templateMsg -stateless config = - application - { view = - \model sharedModel allMetadata staticPayload rendered -> - config.view allMetadata staticPayload rendered - , head = config.head - , staticData = config.staticData - , init = \_ -> ( (), Cmd.none ) - , update = \_ _ _ _ -> ( (), Cmd.none, Shared.NoOp ) - , subscriptions = \_ _ _ _ -> Sub.none - } - - -{-| Full application (including local `Model`, `Msg`, `update`) --} -application : - { staticData : - List ( PagePath Pages.PathKey, TemplateType ) - -> StaticHttp.Request templateStaticData - , view : - templateModel - -> Shared.Model - -> List ( PagePath Pages.PathKey, TemplateType ) - -> StaticPayload templateMetadata templateStaticData - -> Shared.RenderedBody - -> Shared.PageView templateMsg - , head : - StaticPayload templateMetadata templateStaticData - -> List (Head.Tag Pages.PathKey) - , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) - , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg - } - -> Template templateMetadata templateStaticData templateModel templateMsg -application config = - { view = config.view - , head = config.head - , staticData = config.staticData - , init = config.init - , update = config.update - , subscriptions = config.subscriptions - } - - type alias Template templateMetadata templateStaticData templateModel templateMsg = { staticData : List ( PagePath Pages.PathKey, TemplateType ) From 707e4837e1f4a489dad5dd2bcee7ddbb2ddb1a9d Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 4 Oct 2020 13:35:33 -0700 Subject: [PATCH 089/106] Extract shared template function to collect functions in a single entrypoint. --- examples/docs/src/Shared.elm | 107 +++++++++++------- examples/docs/src/SharedTemplate.elm | 0 .../src/generate-template-module-connector.js | 16 +-- 3 files changed, 72 insertions(+), 51 deletions(-) create mode 100644 examples/docs/src/SharedTemplate.elm diff --git a/examples/docs/src/Shared.elm b/examples/docs/src/Shared.elm index 33064ac0..3c7cd953 100644 --- a/examples/docs/src/Shared.elm +++ b/examples/docs/src/Shared.elm @@ -1,4 +1,4 @@ -module Shared exposing (..) +module Shared exposing (Model, Msg(..), PageView, RenderedBody, SharedMsg(..), StaticData, template) import DocumentSvg import Element exposing (Element) @@ -22,21 +22,42 @@ import Secrets import TemplateType exposing (TemplateType) -type SharedMsg - = NoOp - | IncrementFromChild - - -type alias Model = - { showMobileMenu : Bool - , counter : Int +type alias SharedTemplate msg msg1 msg2 = + { init : + Maybe + { path : + { path : PagePath Pages.PathKey + , query : Maybe String + , fragment : Maybe String + } + , metadata : TemplateType + } + -> ( Model, Cmd msg ) + , update : msg -> Model -> ( Model, Cmd msg ) + , view : + StaticData + -> + { path : PagePath Pages.PathKey + , frontmatter : TemplateType + } + -> Model + -> (msg -> msg) + -> PageView msg + -> { body : Html msg, title : String } + , map : (msg1 -> msg2) -> PageView msg1 -> PageView msg2 + , staticData : List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request StaticData + , subscriptions : TemplateType -> PagePath Pages.PathKey -> Model -> Sub msg } -map : (msg1 -> msg2) -> PageView msg1 -> PageView msg2 -map fn doc = - { title = doc.title - , body = Element.map fn doc.body +template : SharedTemplate Msg msg1 msg2 +template = + { init = init + , update = update + , view = view + , map = map + , staticData = staticData + , subscriptions = subscriptions } @@ -59,34 +80,38 @@ type Msg | SharedMsg SharedMsg -sharedTemplate : - { init : a -> ( Model, Cmd Msg ) - , update : Msg -> Model -> ( Model, Cmd Msg ) - , view : - StaticData - -> +type alias StaticData = + Int + + +type SharedMsg + = NoOp + | IncrementFromChild + + +type alias Model = + { showMobileMenu : Bool + , counter : Int + } + + +map : (msg1 -> msg2) -> PageView msg1 -> PageView msg2 +map fn doc = + { title = doc.title + , body = Element.map fn doc.body + } + + +init : + Maybe + { path : { path : PagePath Pages.PathKey - , frontmatter : TemplateType + , query : Maybe String + , fragment : Maybe String } - -> Model - -> (Msg -> msg) - -> PageView msg - -> { body : Html msg, title : String } - , map : (msg1 -> msg2) -> PageView msg1 -> PageView msg2 - , staticData : List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request StaticData - , subscriptions : TemplateType -> PagePath Pages.PathKey -> Model -> Sub Msg - } -sharedTemplate = - { init = init - , update = update - , view = view - , map = map - , staticData = staticData - , subscriptions = subscriptions - } - - -init : a -> ( Model, Cmd Msg ) + , metadata : TemplateType + } + -> ( Model, Cmd Msg ) init maybePagePath = ( { showMobileMenu = False , counter = 0 @@ -116,10 +141,6 @@ update msg model = ( { model | counter = model.counter + 1 }, Cmd.none ) -type alias StaticData = - Int - - subscriptions : TemplateType -> PagePath Pages.PathKey -> Model -> Sub Msg subscriptions _ _ _ = Sub.none diff --git a/examples/docs/src/SharedTemplate.elm b/examples/docs/src/SharedTemplate.elm new file mode 100644 index 00000000..e69de29b diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 166316a1..00f76b8f 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -91,13 +91,13 @@ view siteMetadata page = } rendered |> (\\{ title, body } -> - Shared.view + Shared.template.view globalData page model.global MsgGlobal ({ title = title, body = body } - |> Shared.map Msg${name} + |> Shared.template.map Msg${name} ) ) @@ -112,14 +112,14 @@ view siteMetadata page = } ) (Template.${name}.template.staticData siteMetadata) - (Shared.staticData siteMetadata) + (Shared.template.staticData siteMetadata) ` ) .join("\n\n ")} init : - Maybe Shared.Model + Maybe Shared.template.Model -> Maybe { path : @@ -133,7 +133,7 @@ init : init currentGlobalModel maybePagePath = let ( sharedModel, globalCmd ) = - currentGlobalModel |> Maybe.map (\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Shared.init maybePagePath) + currentGlobalModel |> Maybe.map (\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Shared.template.init maybePagePath) ( templateModel, templateCmd ) = case maybePagePath |> Maybe.map .metadata of @@ -170,7 +170,7 @@ update msg model = MsgGlobal msg_ -> let ( sharedModel, globalCmd ) = - Shared.update msg_ model.global + Shared.template.update msg_ model.global in ( { model | global = sharedModel } , globalCmd |> Cmd.map MsgGlobal @@ -202,7 +202,7 @@ update msg model = model.global |> mapBoth Model${name} (Cmd.map Msg${name}) |> (\\( a, b, c ) -> - ( a, b, Shared.update (Shared.SharedMsg c) model.global ) + ( a, b, Shared.template.update (Shared.SharedMsg c) model.global ) ) _ -> @@ -256,7 +256,7 @@ mainTemplate { documents, site } = , subscriptions = \\metadata path model -> Sub.batch - [ Shared.subscriptions metadata path model.global |> Sub.map MsgGlobal + [ Shared.template.subscriptions metadata path model.global |> Sub.map MsgGlobal , templateSubscriptions metadata path model ] , documents = documents From 12d9decf0464650953f77e4424eb598b68f60163 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 24 Oct 2020 15:46:01 -0700 Subject: [PATCH 090/106] Fix type variables in template modules. --- examples/docs/src/Shared.elm | 31 ++++++++-------- examples/docs/src/Template/BlogIndex.elm | 3 +- examples/docs/src/Template/BlogPost.elm | 3 +- examples/docs/src/Template/Documentation.elm | 35 ++++++++++--------- examples/docs/src/Template/Page.elm | 15 ++++---- examples/docs/src/Template/Showcase.elm | 3 +- .../src/generate-template-module-connector.js | 2 +- 7 files changed, 50 insertions(+), 42 deletions(-) diff --git a/examples/docs/src/Shared.elm b/examples/docs/src/Shared.elm index 3c7cd953..32f05d96 100644 --- a/examples/docs/src/Shared.elm +++ b/examples/docs/src/Shared.elm @@ -22,7 +22,7 @@ import Secrets import TemplateType exposing (TemplateType) -type alias SharedTemplate msg msg1 msg2 = +type alias SharedTemplate templateDemuxMsg msg1 msg2 = { init : Maybe { path : @@ -32,8 +32,8 @@ type alias SharedTemplate msg msg1 msg2 = } , metadata : TemplateType } - -> ( Model, Cmd msg ) - , update : msg -> Model -> ( Model, Cmd msg ) + -> ( Model, Cmd Msg ) + , update : Msg -> Model -> ( Model, Cmd Msg ) , view : StaticData -> @@ -41,16 +41,16 @@ type alias SharedTemplate msg msg1 msg2 = , frontmatter : TemplateType } -> Model - -> (msg -> msg) - -> PageView msg - -> { body : Html msg, title : String } + -> (Msg -> templateDemuxMsg) + -> PageView templateDemuxMsg + -> { body : Html templateDemuxMsg, title : String } , map : (msg1 -> msg2) -> PageView msg1 -> PageView msg2 , staticData : List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request StaticData - , subscriptions : TemplateType -> PagePath Pages.PathKey -> Model -> Sub msg + , subscriptions : TemplateType -> PagePath Pages.PathKey -> Model -> Sub Msg } -template : SharedTemplate Msg msg1 msg2 +template : SharedTemplate msg msg1 msg2 template = { init = init , update = update @@ -66,7 +66,7 @@ type alias RenderedBody = type alias PageView msg = - { title : String, body : Element msg } + { title : String, body : List (Element msg) } type Msg @@ -98,7 +98,7 @@ type alias Model = map : (msg1 -> msg2) -> PageView msg1 -> PageView msg2 map fn doc = { title = doc.title - , body = Element.map fn doc.body + , body = List.map (Element.map fn) doc.body } @@ -180,10 +180,13 @@ view stars page model toMsg pageView = else Element.column [ Element.width Element.fill ] - [ header stars page.path |> Element.map toMsg - , incrementView model |> Element.map toMsg - , pageView.body - ] + (List.concat + [ [ header stars page.path |> Element.map toMsg + , incrementView model |> Element.map toMsg + ] + , pageView.body + ] + ) ) |> Element.layout [ Element.width Element.fill diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index a8ef67c1..e3fafaca 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -71,11 +71,12 @@ view : view model allMetadata staticPayload rendered = { title = "elm-pages blog" , body = - Element.column [ Element.width Element.fill ] + [ Element.column [ Element.width Element.fill ] [ Element.column [ Element.padding 20, Element.centerX ] [ Index.view allMetadata ] ] + ] } diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index aadd94c4..df359527 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -88,7 +88,7 @@ view : view allMetadata { metadata } rendered = { title = metadata.title , body = - Element.column [ Element.width Element.fill ] + [ Element.column [ Element.width Element.fill ] [ Element.column [ Element.padding 30 , Element.spacing 40 @@ -115,6 +115,7 @@ view allMetadata { metadata } rendered = |> List.map (Element.map never) ) ] + ] } diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index a394d31f..a8d1b7d5 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -96,30 +96,31 @@ view : view model sharedModel allMetadata staticPayload rendered = { title = staticPayload.metadata.title , body = - [ Element.row [] - [ counterView sharedModel - , DocSidebar.view - Pages.pages.index - allMetadata - |> Element.el [ Element.width (Element.fillPortion 2), Element.alignTop, Element.height Element.fill ] - , Element.column [ Element.width (Element.fillPortion 8), Element.padding 35, Element.spacing 15 ] - [ Palette.heading 1 [ Element.text staticPayload.metadata.title ] - , Element.column [ Element.spacing 20 ] - [ tocView (Tuple.first rendered) - , Element.column - [ Element.padding 50 - , Element.spacing 30 - , Element.Region.mainContent + [ [ Element.row [] + [ counterView sharedModel + , DocSidebar.view + Pages.pages.index + allMetadata + |> Element.el [ Element.width (Element.fillPortion 2), Element.alignTop, Element.height Element.fill ] + , Element.column [ Element.width (Element.fillPortion 8), Element.padding 35, Element.spacing 15 ] + [ Palette.heading 1 [ Element.text staticPayload.metadata.title ] + , Element.column [ Element.spacing 20 ] + [ tocView (Tuple.first rendered) + , Element.column + [ Element.padding 50 + , Element.spacing 30 + , Element.Region.mainContent + ] + (Tuple.second rendered |> List.map (Element.map never)) ] - (Tuple.second rendered |> List.map (Element.map never)) ] ] - ] - ] + ] |> Element.textColumn [ Element.width Element.fill , Element.height Element.fill ] + ] } diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index b0a37738..232c2dbc 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -62,14 +62,15 @@ view : view allMetadata { metadata } rendered = { title = metadata.title , body = - [ Element.column - [ Element.padding 50 - , Element.spacing 60 - , Element.Region.mainContent - ] - (Tuple.second rendered |> List.map (Element.map never)) - ] + [ [ Element.column + [ Element.padding 50 + , Element.spacing 60 + , Element.Region.mainContent + ] + (Tuple.second rendered |> List.map (Element.map never)) + ] |> Element.textColumn [ Element.width Element.fill ] + ] } diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index 4ae81cb9..daf59d8e 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -55,9 +55,10 @@ view : view allMetadata static rendered = { title = "elm-pages blog" , body = - Element.column [ Element.width Element.fill ] + [ Element.column [ Element.width Element.fill ] [ Element.column [ Element.padding 20, Element.centerX ] [ Showcase.view static.static ] ] + ] } diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 00f76b8f..5f5f5322 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -119,7 +119,7 @@ view siteMetadata page = init : - Maybe Shared.template.Model + Maybe Shared.Model -> Maybe { path : From 28692cf0031c85ea44e39374aa3738d15fa82e82 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 24 Oct 2020 15:55:45 -0700 Subject: [PATCH 091/106] Use new decoder in template module decoder. --- examples/docs/src/MetadataNew.elm | 44 ++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/examples/docs/src/MetadataNew.elm b/examples/docs/src/MetadataNew.elm index 49f3e8af..db15cfe2 100644 --- a/examples/docs/src/MetadataNew.elm +++ b/examples/docs/src/MetadataNew.elm @@ -1,6 +1,11 @@ module MetadataNew exposing (DocMetadata, PageMetadata, decoder) +import Cloudinary +import Data.Author +import Date exposing (Date) import Json.Decode as Decode exposing (Decoder) +import Pages +import Pages.ImagePath exposing (ImagePath) import Template.BlogPost import Template.Page import Template.Showcase @@ -16,6 +21,16 @@ type alias PageMetadata = { title : String } +type alias ArticleMetadata = + { title : String + , description : String + , published : Date + , author : Data.Author.Author + , image : ImagePath Pages.PathKey + , draft : Bool + } + + decoder : Decoder TemplateType decoder = Decode.field "type" Decode.string @@ -39,9 +54,36 @@ decoder = |> Decode.map TemplateType.Showcase "blog" -> - Template.BlogPost.decoder + Decode.map6 ArticleMetadata + (Decode.field "title" Decode.string) + (Decode.field "description" Decode.string) + (Decode.field "published" + (Decode.string + |> Decode.andThen + (\isoString -> + case Date.fromIsoString isoString of + Ok date -> + Decode.succeed date + + Err error -> + Decode.fail error + ) + ) + ) + (Decode.field "author" Data.Author.decoder) + (Decode.field "image" imageDecoder) + (Decode.field "draft" Decode.bool + |> Decode.maybe + |> Decode.map (Maybe.withDefault False) + ) |> Decode.map TemplateType.BlogPost _ -> Decode.fail <| "Unexpected page \"type\" " ++ pageType ) + + +imageDecoder : Decoder (ImagePath Pages.PathKey) +imageDecoder = + Decode.string + |> Decode.map (\cloudinaryAsset -> Cloudinary.url cloudinaryAsset Nothing 800) From 3aaf631c627a61cf07868abdff80cfc691d863f5 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sat, 24 Oct 2020 16:35:54 -0700 Subject: [PATCH 092/106] Generate template modules file in beta build. --- generator/src/codegen.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/generator/src/codegen.js b/generator/src/codegen.js index f3a53b33..825116dd 100644 --- a/generator/src/codegen.js +++ b/generator/src/codegen.js @@ -1,6 +1,9 @@ const fs = require("fs"); const copyModifiedElmJson = require("./rewrite-elm-json.js"); const { elmPagesCliFile, elmPagesUiFile } = require("./elm-file-constants.js"); +const { + generateTemplateModuleConnector, +} = require("./generate-template-module-connector.js"); const path = require("path"); const { ensureDirSync, deleteIfExists } = require("./file-helpers.js"); const globby = require("globby"); @@ -50,6 +53,7 @@ async function writeFiles(markdownContent) { deleteIfExists("./elm-stuff/elm-pages/Pages/Platform.elm"); const uiFileContent = elmPagesUiFile(staticRoutes, markdownContent); + const templateConnectorFile = generateTemplateModuleConnector(); fs.writeFileSync("./gen/Pages.elm", uiFileContent); @@ -58,6 +62,11 @@ async function writeFiles(markdownContent) { "./elm-stuff/elm-pages/Pages.elm", elmPagesCliFile(staticRoutes, markdownContent) ); + fs.writeFileSync( + "./elm-stuff/elm-pages/TemplateDemultiplexer.elm", + templateConnectorFile + ); + fs.writeFileSync("./gen/TemplateDemultiplexer.elm", templateConnectorFile); // write modified elm.json to elm-stuff/elm-pages/ copyModifiedElmJson(); From 7fbcfb60d8b7a6422cc34667979bb09084c01a3f Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 25 Oct 2020 08:22:50 -0700 Subject: [PATCH 093/106] Add setup for local docs for generated module. --- examples/docs/elm-application.json | 8 ++++++++ examples/docs/src/SharedTemplate.elm | 0 examples/docs/src/Template.elm | 21 ++++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 examples/docs/elm-application.json delete mode 100644 examples/docs/src/SharedTemplate.elm diff --git a/examples/docs/elm-application.json b/examples/docs/elm-application.json new file mode 100644 index 00000000..3fcd6afc --- /dev/null +++ b/examples/docs/elm-application.json @@ -0,0 +1,8 @@ +{ + "name": "dillonkearns/elm-pages-local", + "summary": "Elm Pages local docs", + "version": "1.0.0", + "exposed-modules": [ + "Template" + ] +} diff --git a/examples/docs/src/SharedTemplate.elm b/examples/docs/src/SharedTemplate.elm deleted file mode 100644 index e69de29b..00000000 diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 6c3617ea..c0310fe8 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -1,4 +1,13 @@ -module Template exposing (..) +module Template exposing + ( StaticPayload, Template, TemplateWithState, Template_, buildNoState, buildWithLocalState, buildWithSharedState, noStaticData, withStaticData + , Builder(..) + ) + +{-| + +@docs Builder, StaticPayload, Template, TemplateWithState, Template_, buildNoState, buildWithLocalState, buildWithSharedState, noStaticData, withStaticData + +-} import Head import Pages @@ -8,6 +17,7 @@ import Shared import TemplateType exposing (TemplateType) +{-| -} type Builder templateMetadata templateStaticData = WithStaticData { staticData : @@ -19,6 +29,7 @@ type Builder templateMetadata templateStaticData } +{-| -} buildNoState : { view : List ( PagePath Pages.PathKey, TemplateType ) @@ -40,6 +51,7 @@ buildNoState { view } builderState = } +{-| -} buildWithLocalState : { view : templateModel @@ -75,6 +87,7 @@ buildWithLocalState config builderState = } +{-| -} buildWithSharedState : { view : templateModel @@ -101,6 +114,7 @@ buildWithSharedState config builderState = } +{-| -} withStaticData : { staticData : List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request templateStaticData , head : StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) @@ -113,6 +127,7 @@ withStaticData { staticData, head } = } +{-| -} noStaticData : { head : StaticPayload templateMetadata () -> List (Head.Tag Pages.PathKey) } -> Builder templateMetadata () @@ -123,6 +138,7 @@ noStaticData { head } = } +{-| -} type alias Template templateMetadata templateStaticData templateModel templateMsg = { staticData : List ( PagePath Pages.PathKey, TemplateType ) @@ -143,6 +159,7 @@ type alias Template templateMetadata templateStaticData templateModel templateMs } +{-| -} type alias TemplateWithState templateMetadata templateStaticData templateModel templateMsg = Template templateMetadata templateStaticData templateModel templateMsg @@ -152,10 +169,12 @@ type alias TemplateWithState templateMetadata templateStaticData templateModel t -- Template templateMetadata () () Never +{-| -} type alias Template_ templateMetadata staticData = Template templateMetadata staticData () Never +{-| -} type alias StaticPayload metadata staticData = { static : staticData -- local , sharedStatic : Shared.StaticData -- share From 68a25f24c77dd81e1f314c866b69718b56485890 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 25 Oct 2020 08:35:30 -0700 Subject: [PATCH 094/106] Rename template aliases. --- examples/docs/src/Template.elm | 24 +++++++------------- examples/docs/src/Template/BlogIndex.elm | 4 ++-- examples/docs/src/Template/BlogPost.elm | 4 ++-- examples/docs/src/Template/Documentation.elm | 4 ++-- examples/docs/src/Template/Page.elm | 4 ++-- examples/docs/src/Template/Showcase.elm | 4 ++-- 6 files changed, 18 insertions(+), 26 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index c0310fe8..c6f58c96 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -1,11 +1,8 @@ -module Template exposing - ( StaticPayload, Template, TemplateWithState, Template_, buildNoState, buildWithLocalState, buildWithSharedState, noStaticData, withStaticData - , Builder(..) - ) +module Template exposing (Builder(..), StaticPayload, TemplateWithState, Template, buildNoState, buildWithLocalState, buildWithSharedState, noStaticData, withStaticData) {-| -@docs Builder, StaticPayload, Template, TemplateWithState, Template_, buildNoState, buildWithLocalState, buildWithSharedState, noStaticData, withStaticData +@docs Builder, StaticPayload, TemplateWithState, Template, buildNoState, buildWithLocalState, buildWithSharedState, noStaticData, withStaticData -} @@ -38,7 +35,7 @@ buildNoState : -> Shared.PageView Never } -> Builder templateMetadata templateStaticData - -> Template templateMetadata templateStaticData () Never + -> TemplateWithState templateMetadata templateStaticData () Never buildNoState { view } builderState = case builderState of WithStaticData record -> @@ -64,7 +61,7 @@ buildWithLocalState : , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Sub templateMsg } -> Builder templateMetadata templateStaticData - -> Template templateMetadata templateStaticData templateModel templateMsg + -> TemplateWithState templateMetadata templateStaticData templateModel templateMsg buildWithLocalState config builderState = case builderState of WithStaticData record -> @@ -101,7 +98,7 @@ buildWithSharedState : , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg } -> Builder templateMetadata templateStaticData - -> Template templateMetadata templateStaticData templateModel templateMsg + -> TemplateWithState templateMetadata templateStaticData templateModel templateMsg buildWithSharedState config builderState = case builderState of WithStaticData record -> @@ -139,7 +136,7 @@ noStaticData { head } = {-| -} -type alias Template templateMetadata templateStaticData templateModel templateMsg = +type alias TemplateWithState templateMetadata templateStaticData templateModel templateMsg = { staticData : List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request templateStaticData @@ -159,19 +156,14 @@ type alias Template templateMetadata templateStaticData templateModel templateMs } -{-| -} -type alias TemplateWithState templateMetadata templateStaticData templateModel templateMsg = - Template templateMetadata templateStaticData templateModel templateMsg - - --type alias Template_ templateMetadata = -- Template templateMetadata () () Never {-| -} -type alias Template_ templateMetadata staticData = - Template templateMetadata staticData () Never +type alias Template templateMetadata staticData = + TemplateWithState templateMetadata staticData () Never {-| -} diff --git a/examples/docs/src/Template/BlogIndex.elm b/examples/docs/src/Template/BlogIndex.elm index e3fafaca..5944db7e 100644 --- a/examples/docs/src/Template/BlogIndex.elm +++ b/examples/docs/src/Template/BlogIndex.elm @@ -10,7 +10,7 @@ import Pages.StaticHttp as StaticHttp import Shared import Showcase import Site -import Template exposing (StaticPayload, Template) +import Template exposing (StaticPayload, TemplateWithState) import TemplateMetadata exposing (BlogIndex) import TemplateType exposing (TemplateType) @@ -19,7 +19,7 @@ type Msg = Msg -template : Template BlogIndex StaticData Model Msg +template : TemplateWithState BlogIndex StaticData Model Msg template = Template.withStaticData { head = head diff --git a/examples/docs/src/Template/BlogPost.elm b/examples/docs/src/Template/BlogPost.elm index df359527..4b757125 100644 --- a/examples/docs/src/Template/BlogPost.elm +++ b/examples/docs/src/Template/BlogPost.elm @@ -16,7 +16,7 @@ import Palette import Shared import Site import StructuredData -import Template exposing (StaticPayload, Template, Template_) +import Template exposing (StaticPayload, Template, TemplateWithState) import TemplateMetadata exposing (BlogPost) import TemplateType exposing (TemplateType) @@ -29,7 +29,7 @@ type alias Msg = Never -template : Template_ BlogPost () +template : Template BlogPost () template = Template.noStaticData { head = head } |> Template.buildNoState { view = view } diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index a8d1b7d5..7fb4305d 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -15,7 +15,7 @@ import Pages.StaticHttp as StaticHttp import Palette import Shared import Site -import Template exposing (StaticPayload, Template) +import Template exposing (StaticPayload, TemplateWithState) import TemplateMetadata exposing (Documentation) import TemplateType exposing (TemplateType) @@ -32,7 +32,7 @@ type Msg = Increment -template : Template Documentation StaticData Model Msg +template : TemplateWithState Documentation StaticData Model Msg template = Template.noStaticData { head = head } |> Template.buildWithSharedState diff --git a/examples/docs/src/Template/Page.elm b/examples/docs/src/Template/Page.elm index 232c2dbc..340164d1 100644 --- a/examples/docs/src/Template/Page.elm +++ b/examples/docs/src/Template/Page.elm @@ -9,7 +9,7 @@ import Pages exposing (images) import Pages.PagePath exposing (PagePath) import Shared import Site -import Template exposing (StaticPayload, Template, Template_) +import Template exposing (StaticPayload, Template, TemplateWithState) import TemplateMetadata exposing (Page) import TemplateType exposing (TemplateType) @@ -22,7 +22,7 @@ type alias Msg = Never -template : Template_ Page () +template : Template Page () template = Template.noStaticData { head = head } |> Template.buildNoState { view = view } diff --git a/examples/docs/src/Template/Showcase.elm b/examples/docs/src/Template/Showcase.elm index daf59d8e..a58b8c1f 100644 --- a/examples/docs/src/Template/Showcase.elm +++ b/examples/docs/src/Template/Showcase.elm @@ -9,7 +9,7 @@ import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp import Shared import Showcase -import Template exposing (StaticPayload, Template) +import Template exposing (StaticPayload, TemplateWithState) import TemplateMetadata exposing (Showcase) import TemplateType exposing (TemplateType) @@ -22,7 +22,7 @@ type alias Msg = Never -template : Template Showcase StaticData () Msg +template : TemplateWithState Showcase StaticData () Msg template = Template.withStaticData { head = head From b2926149ff92c9843d01bc6127c4f7a3966b5540 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 25 Oct 2020 09:06:21 -0700 Subject: [PATCH 095/106] Update docs. --- examples/docs/src/Template.elm | 117 +++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 42 deletions(-) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index c6f58c96..93e26de7 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -1,8 +1,46 @@ -module Template exposing (Builder(..), StaticPayload, TemplateWithState, Template, buildNoState, buildWithLocalState, buildWithSharedState, noStaticData, withStaticData) +module Template exposing + ( Builder(..) + , StaticPayload + , withStaticData, noStaticData + , Template, buildNoState + , TemplateWithState, buildWithLocalState, buildWithSharedState + ) {-| -@docs Builder, StaticPayload, TemplateWithState, Template, buildNoState, buildWithLocalState, buildWithSharedState, noStaticData, withStaticData + +## Building a Template + +@docs Builder + + +## Static Data + +Every template will have access to a `StaticPayload`. + +@docs StaticPayload + +Since this data is _static_, you have access to it before the user has loaded the page, including at build time. +An example of dynamic data would be keyboard input from the user, query params, or any other data that comes from the app running in the browser. + +But before the user even requests the page, we have the following data: + + - `path` - these paths are static. In other words, we know every single path when we build an elm-pages site. + - `metadata` - we have a decoded Elm value for the page's metadata. + - `sharedStatic` - we can access any shared data between pages. For example, you may have fetched the name of a blog ("Jane's Blog") from the API for a Content Management System (CMS). + - `static` - this is the static data for this specific page. If you use `noStaticData`, then this will be `()`, meaning there is no page-specific static data. + +@docs withStaticData, noStaticData + + +## Stateless Templates + +@docs Template, buildNoState + + +## Stateful Templates + +@docs TemplateWithState, buildWithLocalState, buildWithSharedState -} @@ -14,6 +52,41 @@ import Shared import TemplateType exposing (TemplateType) +{-| -} +type alias TemplateWithState templateMetadata templateStaticData templateModel templateMsg = + { staticData : + List ( PagePath Pages.PathKey, TemplateType ) + -> StaticHttp.Request templateStaticData + , view : + templateModel + -> Shared.Model + -> List ( PagePath Pages.PathKey, TemplateType ) + -> StaticPayload templateMetadata templateStaticData + -> Shared.RenderedBody + -> Shared.PageView templateMsg + , head : + StaticPayload templateMetadata templateStaticData + -> List (Head.Tag Pages.PathKey) + , init : templateMetadata -> ( templateModel, Cmd templateMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) + , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg + } + + +{-| -} +type alias Template templateMetadata staticData = + TemplateWithState templateMetadata staticData () Never + + +{-| -} +type alias StaticPayload metadata staticData = + { static : staticData -- local + , sharedStatic : Shared.StaticData -- share + , metadata : metadata + , path : PagePath Pages.PathKey + } + + {-| -} type Builder templateMetadata templateStaticData = WithStaticData @@ -133,43 +206,3 @@ noStaticData { head } = { staticData = \_ -> StaticHttp.succeed () , head = head } - - -{-| -} -type alias TemplateWithState templateMetadata templateStaticData templateModel templateMsg = - { staticData : - List ( PagePath Pages.PathKey, TemplateType ) - -> StaticHttp.Request templateStaticData - , view : - templateModel - -> Shared.Model - -> List ( PagePath Pages.PathKey, TemplateType ) - -> StaticPayload templateMetadata templateStaticData - -> Shared.RenderedBody - -> Shared.PageView templateMsg - , head : - StaticPayload templateMetadata templateStaticData - -> List (Head.Tag Pages.PathKey) - , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) - , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg - } - - - ---type alias Template_ templateMetadata = --- Template templateMetadata () () Never - - -{-| -} -type alias Template templateMetadata staticData = - TemplateWithState templateMetadata staticData () Never - - -{-| -} -type alias StaticPayload metadata staticData = - { static : staticData -- local - , sharedStatic : Shared.StaticData -- share - , metadata : metadata - , path : PagePath Pages.PathKey - } From 75cca615970641a07626dfcfab10991e989cf765 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 25 Oct 2020 09:15:17 -0700 Subject: [PATCH 096/106] Add a generator for the template modules beta. --- generator/src/codegen-template-module.js | 69 ++++++++++++++++++++++++ package.json | 5 +- 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100755 generator/src/codegen-template-module.js diff --git a/generator/src/codegen-template-module.js b/generator/src/codegen-template-module.js new file mode 100755 index 00000000..8a226f9e --- /dev/null +++ b/generator/src/codegen-template-module.js @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +const fs = require("./dir-helpers.js"); + +if (process.argv.length === 3) { + const moduleName = process.argv[2]; + if (!moduleName.match(/[A-Z][A-Za-z0-9]*/)) { + console.error("Invalid module name."); + process.exit(1); + } + const content = fileContent(moduleName); + fs.tryMkdir("src/Template"); + fs.writeFile(`src/Template/${moduleName}.elm`, content); +} else { + console.error(`Unexpected CLI options: ${process.argv}`); + process.exit(1); +} + +function fileContent(templateName) { + return ` +module Template.${templateName} exposing (Model, Msg, template) + +import Head +import Pages +import Pages.PagePath exposing (PagePath) +import Shared +import Template exposing (StaticPayload, Template) +import TemplateMetadata exposing (${templateName}) +import TemplateType exposing (TemplateType) + + +type alias Model = + () + + +type alias Msg = + Never + + +type alias StaticData = + () + + +template : Template ${templateName} StaticData +template = + Template.noStaticData { head = head } + |> Template.buildNoState { view = view } + + +head : + StaticPayload ${templateName} StaticData + -> List (Head.Tag Pages.PathKey) +head { metadata } = + [] + + +view : + List ( PagePath Pages.PathKey, TemplateType ) + -> StaticPayload ${templateName} StaticData + -> Shared.RenderedBody + -> Shared.PageView msg +view allMetadata static rendered = + { title = Debug.todo "Add title." + , body = + [] + } + +`; +} diff --git a/package.json b/package.json index 0d45ccee..59e125d6 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ ], "bin": { "elm-pages": "generator/src/elm-pages.js", - "elm-pages-beta": "generator/src/cli.js" + "elm-pages-beta": "generator/src/cli.js", + "elm-pages-generate": "generator/src/codegen-template-module.js" } -} +} \ No newline at end of file From 3964dc43b60d76b3a31cda52078eebd275dc94f9 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 25 Oct 2020 11:24:52 -0700 Subject: [PATCH 097/106] Use Maybe instead of NoOp for SharedMsg's. --- examples/docs/src/Shared.elm | 6 +----- examples/docs/src/Template.elm | 8 ++++---- examples/docs/src/Template/Documentation.elm | 4 ++-- examples/simple/src/Main.elm | 13 ++++++++----- generator/src/generate-template-module-connector.js | 7 ++++++- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/examples/docs/src/Shared.elm b/examples/docs/src/Shared.elm index 32f05d96..cfe67acc 100644 --- a/examples/docs/src/Shared.elm +++ b/examples/docs/src/Shared.elm @@ -85,8 +85,7 @@ type alias StaticData = type SharedMsg - = NoOp - | IncrementFromChild + = IncrementFromChild type alias Model = @@ -134,9 +133,6 @@ update msg model = SharedMsg globalMsg -> case globalMsg of - NoOp -> - ( model, Cmd.none ) - IncrementFromChild -> ( { model | counter = model.counter + 1 }, Cmd.none ) diff --git a/examples/docs/src/Template.elm b/examples/docs/src/Template.elm index 93e26de7..878b25e9 100644 --- a/examples/docs/src/Template.elm +++ b/examples/docs/src/Template.elm @@ -68,7 +68,7 @@ type alias TemplateWithState templateMetadata templateStaticData templateModel t StaticPayload templateMetadata templateStaticData -> List (Head.Tag Pages.PathKey) , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Maybe Shared.SharedMsg ) , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg } @@ -116,7 +116,7 @@ buildNoState { view } builderState = , head = record.head , staticData = record.staticData , init = \_ -> ( (), Cmd.none ) - , update = \_ _ _ _ -> ( (), Cmd.none, Shared.NoOp ) + , update = \_ _ _ _ -> ( (), Cmd.none, Nothing ) , subscriptions = \_ _ _ _ -> Sub.none } @@ -150,7 +150,7 @@ buildWithLocalState config builderState = ( updatedModel, cmd ) = config.update metadata msg templateModel in - ( updatedModel, cmd, Shared.NoOp ) + ( updatedModel, cmd, Nothing ) , subscriptions = \templateMetadata path templateModel sharedModel -> config.subscriptions templateMetadata path templateModel @@ -167,7 +167,7 @@ buildWithSharedState : -> Shared.RenderedBody -> Shared.PageView templateMsg , init : templateMetadata -> ( templateModel, Cmd templateMsg ) - , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Shared.SharedMsg ) + , update : templateMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Maybe Shared.SharedMsg ) , subscriptions : templateMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg } -> Builder templateMetadata templateStaticData diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 7fb4305d..85a71d84 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -48,11 +48,11 @@ init metadata = ( {}, Cmd.none ) -update : Documentation -> Msg -> Model -> Shared.Model -> ( Model, Cmd Msg, Shared.SharedMsg ) +update : Documentation -> Msg -> Model -> Shared.Model -> ( Model, Cmd Msg, Maybe Shared.SharedMsg ) update metadata msg model sharedModel = case msg of Increment -> - ( model, Cmd.none, Shared.IncrementFromChild ) + ( model, Cmd.none, Just Shared.IncrementFromChild ) staticData : diff --git a/examples/simple/src/Main.elm b/examples/simple/src/Main.elm index 530f0a27..733bdc7f 100644 --- a/examples/simple/src/Main.elm +++ b/examples/simple/src/Main.elm @@ -157,9 +157,12 @@ type alias Model = init : Maybe - { path : PagePath Pages.PathKey - , query : Maybe String - , fragment : Maybe String + { path : + { path : PagePath Pages.PathKey + , query : Maybe String + , fragment : Maybe String + } + , metadata : Metadata } -> ( Model, Cmd Msg ) init maybePagePath = @@ -189,8 +192,8 @@ update msg model = ( { model | counter = model.counter + 1 }, Cmd.none ) -subscriptions : Model -> Sub Msg -subscriptions _ = +subscriptions : Metadata -> PagePath Pages.PathKey -> Model -> Sub Msg +subscriptions _ _ _ = Time.every 1000 (\_ -> Tick) diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index 5f5f5322..a359af22 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -202,7 +202,12 @@ update msg model = model.global |> mapBoth Model${name} (Cmd.map Msg${name}) |> (\\( a, b, c ) -> - ( a, b, Shared.template.update (Shared.SharedMsg c) model.global ) + case c of + Just sharedMsg -> + ( a, b, Shared.template.update (Shared.SharedMsg sharedMsg) model.global ) + + Nothing -> + ( a, b, ( model.global, Cmd.none ) ) ) _ -> From 747864219082abd8825e7b04c70eca7b3e317f42 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 25 Oct 2020 12:06:08 -0700 Subject: [PATCH 098/106] Wire in OnPageChange to shared. --- examples/docs/src/Shared.elm | 9 +++++++ .../src/generate-template-module-connector.js | 27 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/examples/docs/src/Shared.elm b/examples/docs/src/Shared.elm index cfe67acc..2a3289b0 100644 --- a/examples/docs/src/Shared.elm +++ b/examples/docs/src/Shared.elm @@ -47,6 +47,14 @@ type alias SharedTemplate templateDemuxMsg msg1 msg2 = , map : (msg1 -> msg2) -> PageView msg1 -> PageView msg2 , staticData : List ( PagePath Pages.PathKey, TemplateType ) -> StaticHttp.Request StaticData , subscriptions : TemplateType -> PagePath Pages.PathKey -> Model -> Sub Msg + , onPageChange : + Maybe + ({ path : PagePath Pages.PathKey + , query : Maybe String + , fragment : Maybe String + } + -> Msg + ) } @@ -58,6 +66,7 @@ template = , map = map , staticData = staticData , subscriptions = subscriptions + , onPageChange = Just OnPageChange } diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index a359af22..ee5aa0ad 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -177,7 +177,7 @@ update msg model = ) OnPageChange record -> - init (Just model.global) <| + (init (Just model.global) <| Just { path = { path = record.path @@ -186,6 +186,31 @@ update msg model = } , metadata = record.metadata } + ) + |> (\\( updatedModel, cmd ) -> + case Shared.template.onPageChange of + Nothing -> + ( updatedModel, cmd ) + + Just thingy -> + let + ( updatedGlobalModel, globalCmd ) = + Shared.template.update + (thingy + { path = record.path + , query = record.query + , fragment = record.fragment + } + ) + model.global + in + ( { updatedModel + | global = updatedGlobalModel + } + , Cmd.batch [ cmd, Cmd.map MsgGlobal globalCmd ] + ) + ) + ${templates .map( From 3aa978578b152ea74352d97e7b362cecc4da09a4 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 26 Oct 2020 10:50:11 -0700 Subject: [PATCH 099/106] Update template modules file name. --- examples/docs/src/Main.elm | 6 +-- generator/src/codegen.js | 4 +- generator/src/generate-elm-stuff.js | 43 ++++++++----------- .../src/generate-template-module-connector.js | 2 +- .../generated-files.test.js.snap | 2 +- 5 files changed, 25 insertions(+), 32 deletions(-) diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index e2909375..601f565e 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -18,7 +18,7 @@ import Rss import RssPlugin import Shared import Site -import TemplateDemultiplexer +import TemplateModulesBeta import TemplateType exposing (TemplateType) @@ -56,9 +56,9 @@ socialIcon = --main : Pages.Platform.Program Model Msg Metadata View Pages.PathKey -main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg TemplateType Shared.RenderedBody Pages.PathKey +main : Pages.Platform.Program TemplateModulesBeta.Model TemplateModulesBeta.Msg TemplateType Shared.RenderedBody Pages.PathKey main = - TemplateDemultiplexer.mainTemplate + TemplateModulesBeta.mainTemplate { documents = [ { extension = "md" , metadata = MetadataNew.decoder -- metadata parser/decoder? diff --git a/generator/src/codegen.js b/generator/src/codegen.js index 825116dd..3c5dd422 100644 --- a/generator/src/codegen.js +++ b/generator/src/codegen.js @@ -63,10 +63,10 @@ async function writeFiles(markdownContent) { elmPagesCliFile(staticRoutes, markdownContent) ); fs.writeFileSync( - "./elm-stuff/elm-pages/TemplateDemultiplexer.elm", + "./elm-stuff/elm-pages/TemplateModulesBeta.elm", templateConnectorFile ); - fs.writeFileSync("./gen/TemplateDemultiplexer.elm", templateConnectorFile); + fs.writeFileSync("./gen/TemplateModulesBeta.elm", templateConnectorFile); // write modified elm.json to elm-stuff/elm-pages/ copyModifiedElmJson(); diff --git a/generator/src/generate-elm-stuff.js b/generator/src/generate-elm-stuff.js index 7d652572..3d5e4d06 100644 --- a/generator/src/generate-elm-stuff.js +++ b/generator/src/generate-elm-stuff.js @@ -2,17 +2,14 @@ const fs = require("fs"); const runElm = require("./compile-elm.js"); const copyModifiedElmJson = require("./rewrite-elm-json.js"); const { elmPagesCliFile, elmPagesUiFile } = require("./elm-file-constants.js"); -const { generateTemplateModuleConnector } = require("./generate-template-module-connector.js"); +const { + generateTemplateModuleConnector, +} = require("./generate-template-module-connector.js"); const path = require("path"); -const { ensureDirSync, deleteIfExists } = require('./file-helpers.js') -let wasEqualBefore = false +const { ensureDirSync, deleteIfExists } = require("./file-helpers.js"); +let wasEqualBefore = false; - -module.exports = function run( - mode, - staticRoutes, - markdownContent -) { +module.exports = function run(mode, staticRoutes, markdownContent) { ensureDirSync("./elm-stuff"); ensureDirSync("./gen"); ensureDirSync("./elm-stuff/elm-pages"); @@ -21,30 +18,23 @@ module.exports = function run( deleteIfExists("./elm-stuff/elm-pages/Pages/ContentCache.elm"); deleteIfExists("./elm-stuff/elm-pages/Pages/Platform.elm"); - - const uiFileContent = elmPagesUiFile(staticRoutes, markdownContent) - const templateConnectorFile = generateTemplateModuleConnector() + const uiFileContent = elmPagesUiFile(staticRoutes, markdownContent); + const templateConnectorFile = generateTemplateModuleConnector(); // TODO should just write it once, but webpack doesn't seem to pick up the changes // so this wasEqualBefore code causes it to get written twice to make sure the changes come through for HMR if (wasEqualBefore) { - fs.writeFileSync( - "./gen/Pages.elm", - uiFileContent - ); + fs.writeFileSync("./gen/Pages.elm", uiFileContent); } if (global.previousUiFileContent === uiFileContent) { - wasEqualBefore = false + wasEqualBefore = false; } else { - wasEqualBefore = true - fs.writeFileSync( - "./gen/Pages.elm", - uiFileContent - ); - fs.writeFileSync("./gen/TemplateDemultiplexer.elm", templateConnectorFile); + wasEqualBefore = true; + fs.writeFileSync("./gen/Pages.elm", uiFileContent); + fs.writeFileSync("./gen/TemplateModulesBeta.elm", templateConnectorFile); } - global.previousUiFileContent = uiFileContent + global.previousUiFileContent = uiFileContent; // write `Pages.elm` with cli interface fs.writeFileSync( @@ -52,7 +42,10 @@ module.exports = function run( elmPagesCliFile(staticRoutes, markdownContent) ); - fs.writeFileSync("./elm-stuff/elm-pages/TemplateDemultiplexer.elm", templateConnectorFile); + fs.writeFileSync( + "./elm-stuff/elm-pages/TemplateModulesBeta.elm", + templateConnectorFile + ); // write modified elm.json to elm-stuff/elm-pages/ copyModifiedElmJson(); diff --git a/generator/src/generate-template-module-connector.js b/generator/src/generate-template-module-connector.js index ee5aa0ad..48bed26d 100644 --- a/generator/src/generate-template-module-connector.js +++ b/generator/src/generate-template-module-connector.js @@ -6,7 +6,7 @@ function generateTemplateModuleConnector() { .sync(["src/Template/*.elm"], {}) .map((file) => path.basename(file, ".elm")); - return `module TemplateDemultiplexer exposing (..) + return `module TemplateModulesBeta exposing (..) import Browser import Pages.Manifest as Manifest diff --git a/tests/__snapshots__/generated-files.test.js.snap b/tests/__snapshots__/generated-files.test.js.snap index f187b79c..5c6bfb40 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/tests/__snapshots__/generated-files.test.js.snap @@ -115,7 +115,7 @@ content = `; exports[`generate template module connector 1`] = ` -"module TemplateDemultiplexer exposing (..) +"module TemplateModulesBeta exposing (..) import Browser import Shared From b26d05b88c824dcc1030903e1d0766233683cd5f Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 26 Oct 2020 11:03:43 -0700 Subject: [PATCH 100/106] Generate Template.elm module. --- {examples/docs => generator}/src/Template.elm | 0 generator/src/codegen-template-builder.js | 0 generator/src/codegen.js | 5 +++++ generator/src/generate-elm-stuff.js | 1 + 4 files changed, 6 insertions(+) rename {examples/docs => generator}/src/Template.elm (100%) create mode 100644 generator/src/codegen-template-builder.js diff --git a/examples/docs/src/Template.elm b/generator/src/Template.elm similarity index 100% rename from examples/docs/src/Template.elm rename to generator/src/Template.elm diff --git a/generator/src/codegen-template-builder.js b/generator/src/codegen-template-builder.js new file mode 100644 index 00000000..e69de29b diff --git a/generator/src/codegen.js b/generator/src/codegen.js index 3c5dd422..f0794067 100644 --- a/generator/src/codegen.js +++ b/generator/src/codegen.js @@ -47,6 +47,11 @@ async function writeFiles(markdownContent) { ensureDirSync("./elm-stuff"); ensureDirSync("./gen"); ensureDirSync("./elm-stuff/elm-pages"); + fs.copyFileSync(path.join(__dirname, `./Template.elm`), `./gen/Template.elm`); + fs.copyFileSync( + path.join(__dirname, `./Template.elm`), + `./elm-stuff/elm-pages/Template.elm` + ); // prevent compilation errors if migrating from previous elm-pages version deleteIfExists("./elm-stuff/elm-pages/Pages/ContentCache.elm"); diff --git a/generator/src/generate-elm-stuff.js b/generator/src/generate-elm-stuff.js index 3d5e4d06..8477d714 100644 --- a/generator/src/generate-elm-stuff.js +++ b/generator/src/generate-elm-stuff.js @@ -36,6 +36,7 @@ module.exports = function run(mode, staticRoutes, markdownContent) { global.previousUiFileContent = uiFileContent; + fs.copyFileSync(path.join(__dirname, `./Template.elm`), `./gen/Template.elm`); // write `Pages.elm` with cli interface fs.writeFileSync( "./elm-stuff/elm-pages/Pages.elm", From dfa71340a21f4d07e835d240b09ab3d990c05f7a Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 26 Oct 2020 11:09:26 -0700 Subject: [PATCH 101/106] Hide counter views and fix current path highlighting in docs page. --- examples/docs/src/Shared.elm | 3 ++- examples/docs/src/Template/Documentation.elm | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/docs/src/Shared.elm b/examples/docs/src/Shared.elm index 2a3289b0..d00e19b3 100644 --- a/examples/docs/src/Shared.elm +++ b/examples/docs/src/Shared.elm @@ -187,7 +187,8 @@ view stars page model toMsg pageView = Element.column [ Element.width Element.fill ] (List.concat [ [ header stars page.path |> Element.map toMsg - , incrementView model |> Element.map toMsg + + --, incrementView model |> Element.map toMsg ] , pageView.body ] diff --git a/examples/docs/src/Template/Documentation.elm b/examples/docs/src/Template/Documentation.elm index 85a71d84..583bff33 100644 --- a/examples/docs/src/Template/Documentation.elm +++ b/examples/docs/src/Template/Documentation.elm @@ -97,9 +97,9 @@ view model sharedModel allMetadata staticPayload rendered = { title = staticPayload.metadata.title , body = [ [ Element.row [] - [ counterView sharedModel - , DocSidebar.view - Pages.pages.index + [ --counterView sharedModel, + DocSidebar.view + staticPayload.path allMetadata |> Element.el [ Element.width (Element.fillPortion 2), Element.alignTop, Element.height Element.fill ] , Element.column [ Element.width (Element.fillPortion 8), Element.padding 35, Element.spacing 15 ] From f6b956c5aa49abf001e902a78fe4d552097ea742 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 26 Oct 2020 11:15:50 -0700 Subject: [PATCH 102/106] Run prettier on markdown. --- CHANGELOG-ELM.md | 58 ++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/CHANGELOG-ELM.md b/CHANGELOG-ELM.md index 7e50c178..daf885be 100644 --- a/CHANGELOG-ELM.md +++ b/CHANGELOG-ELM.md @@ -12,34 +12,39 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [6.0.0] - 2020-07-14 ### Fixed + - Fixed missing content message flash for pages that are hosted on a sub path: https://github.com/dillonkearns/elm-pages/issues/106. ## [5.0.2] - 2020-06-16 ### Fixed + - Fixed issue where CLI would hang when fetching StaticHttp data for `generateFiles` functions. The problem was a looping condition for completing the CLI process to fetch StaticHttp data. See [#120](https://github.com/dillonkearns/elm-pages/pull/120). ## [5.0.1] - 2020-05-13 ### Fixed + - Make sure the build fails when there are `Err` results in any markdown content. Fixes [#102](https://github.com/dillonkearns/elm-pages/issues/102). This fix also means that any markdown errors will cause the error overlay in the dev server to show. ## [5.0.0] - 2020-05-11 ### Changed + - Use builder pattern to build application. In place of the old `Pages.Platform.application`, you now start building an application config with `Pages.Platform.init`, and complete it with `Pages.Platform.toProgram`. You can chain on some calls to your application builder. This is handy for creating plugins that generate some files and add some head tags using `withGlobalHeadTags`. - The `documents` key is now a List of records. The `Pages.Document` module has been removed entirely in place of a simplified API. `elm-markup` files no longer have any special handling and the direct dependency was removed from `elm-pages`. Instead, to use `elm-markup` with `elm-pages`, you now wire it in as you would with a markdown parser or any other document handler. - Replaced `generateFiles` field in `Pages.Platform.application` with the `Pages.Platform.withFileGenerator` function. - Instead of using the `zwilias/json-decode-exploration` package directly to build up optimizable decoders, you now use the `OptimizedDecoder` API. It provides the same drop-in replacement, - with the same underlying package. But it now uses a major optimization where in your production build, it will run a plain `elm/json` decoder + with the same underlying package. But it now uses a major optimization where in your production build, it will run a plain `elm/json` decoder (on the optimized JSON asset that was produced in the build step) to improve performance. ### Added + - Added `Head.Seo.structuredData`. Check out Google's [structured data gallery](https://developers.google.com/search/docs/guides/search-gallery) to see some examples of what structured - data looks like in rich search results that it provides. Right now, the API takes a simple `Json.Encode.Value`. In the `elm-pages` repo, I have an example API that I use, + data looks like in rich search results that it provides. Right now, the API takes a simple `Json.Encode.Value`. In the `elm-pages` repo, I have an example API that I use, but it's not public yet because I want to refine the API before releasing it (and it's a large undertaking!). But for now, you can add whatever structured data you need, you'll just have to be careful to build up a valid format according to schema.org. - `Pages.Directory.basePath` and `Pages.Directory.basePathToString` helpers. @@ -49,6 +54,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [4.0.1] - 2020-03-28 ### Added + - You can now host your `elm-pages` site in a sub-directory. For example, you could host it at mysite.com/blog, where the top-level mysite.com/ is hosting a different app. This works using [HTML `` tags](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base). The paths you get from `PagePath.toString` and `ImagePath.toString` will use relative paths (e.g. `blog/my-article`) instead of absolute URLs (e.g. `/blog/my-article`), so you can take advantage of this functionality by just making sure you @@ -57,9 +63,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [4.0.0] - 2020-03-04 ### Changed + - `StaticHttp.stringBody` now takes an argument for the MIME type. ### Added + - `StaticHttp.unoptimizedRequest` allows you to decode responses of any type by passing in a `StaticHttp.Expect`. - `StaticHttp.expectString` can be used to parse any values, like XML or plaintext. Note that the payload won't be stripped down so be sure to check the asset sizes that you're fetching carefully. @@ -67,21 +75,24 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [3.0.2] - 2020-02-03 ### Fixed + - Fixed an issue where "Missing content" message flashed for the root page. - Scroll up to the top of the page on page navigations (Elm's core Browser.application doesn't do this automatically). This change - preserves the behavior for navigating to anchor links, so you can still go to a fragment and it will take you to the appropriate part - of the page without scrolling to the top in those cases. + preserves the behavior for navigating to anchor links, so you can still go to a fragment and it will take you to the appropriate part + of the page without scrolling to the top in those cases. ## [3.0.1] - 2020-01-30 ### Changed + - Pass allRoutes into pre-rendering for https://github.com/dillonkearns/elm-pages/pull/60. ## [3.0.0] - 2020-01-25 ### Changed + - Added URL query and fragment in addition to the PagePath provided by `init` and `onPageChange`. - See [#39](https://github.com/dillonkearns/elm-pages/pull/39). The new data structure used looks like this: + See [#39](https://github.com/dillonkearns/elm-pages/pull/39). The new data structure used looks like this: ```elm { path : PagePath Pages.PathKey @@ -93,50 +104,55 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [2.0.0] - 2020-01-25 ### Added -- There's a new `generateFiles` endpoint. You pass in a function that takes a page's path, - page metadata, and page body, and that returns a list representing the files to generate. - You can see a working example for elm-pages.com, here's the [entry point](https://github.com/dillonkearns/elm-pages/blob/master/examples/docs/src/Main.elm#L76-L92), and here's where it - [generates the RSS feed](https://github.com/dillonkearns/elm-pages/blob/master/examples/docs/src/Feed.elm). - You can pass in a no-op function like `\pages -> []` to not generate any files. +- There's a new `generateFiles` endpoint. You pass in a function that takes a page's path, + page metadata, and page body, and that returns a list representing the files to generate. + You can see a working example for elm-pages.com, here's the [entry point](https://github.com/dillonkearns/elm-pages/blob/master/examples/docs/src/Main.elm#L76-L92), and here's where it + [generates the RSS feed](https://github.com/dillonkearns/elm-pages/blob/master/examples/docs/src/Feed.elm). + You can pass in a no-op function like `\pages -> []` to not generate any files. ## [1.1.3] - 2020-01-23 ### Fixed + - Fix missing content flash (that was partially fixed with [#48](https://github.com/dillonkearns/elm-pages/pull/48)) for - some cases where paths weren't normalized correctly. + some cases where paths weren't normalized correctly. ## [1.1.2] - 2020-01-20 ### Fixed + - "Missing content" message no longer flashes between pre-rendered HTML and the Elm app hydrating and taking over the page. See [#48](https://github.com/dillonkearns/elm-pages/pull/48). ## [1.1.1] - 2020-01-04 ### Fixed -* Don't reload pages when clicking a link to the exact same URL as current URL. Fixes [#29](https://github.com/dillonkearns/elm-pages/issues/29). + +- Don't reload pages when clicking a link to the exact same URL as current URL. Fixes [#29](https://github.com/dillonkearns/elm-pages/issues/29). ## [1.1.0] - 2020-01-03 Check out [this upgrade checklist](https://github.com/dillonkearns/elm-pages/blob/master/docs/upgrade-guide.md#upgrading-to-elm-package-110-and-npm-package-113) for more details and steps for upgrading your project. ### Added + - There's a new StaticHttp API. Read more about it in [this `StaticHttp` announcement blog post](http://elm-pages.com/blog/static-http)! - The generated `Pages.elm` module now includes `builtAt : Time.Posix`. Make sure you have `elm/time` as a dependency in your project! - You can use this when you make API requests to filter based on a date range starting with the current date. - If you want a random seed that changes on each build (or every week, or every month, etc.), then you can use this time stamp - (and perform modulo arithemtic based on the date for each week, month, etc.) and use that number as a random seed. + You can use this when you make API requests to filter based on a date range starting with the current date. + If you want a random seed that changes on each build (or every week, or every month, etc.), then you can use this time stamp + (and perform modulo arithemtic based on the date for each week, month, etc.) and use that number as a random seed. ### Changed -- Instead of initializing an application using `Pages.application` from the generated `Pages` module, you now initialize the app - using `Pages.Platform.application` which is part of the published Elm package. So now it's easier to browse the docs. - You pass in some internal data from the generated `Pages.elm` module now by including - this in the application config record: `Pages.Platform.application { internals = Pages.internals, ... }`. -- Add init argument and user Msg for initial PagePath and page changes (see [#4](https://github.com/dillonkearns/elm-pages/issues/4)). +- Instead of initializing an application using `Pages.application` from the generated `Pages` module, you now initialize the app + using `Pages.Platform.application` which is part of the published Elm package. So now it's easier to browse the docs. + You pass in some internal data from the generated `Pages.elm` module now by including + this in the application config record: `Pages.Platform.application { internals = Pages.internals, ... }`. +- Add init argument and user Msg for initial PagePath and page changes (see [#4](https://github.com/dillonkearns/elm-pages/issues/4)). ## [1.0.1] - 2019-11-04 ### Fixed + - Generate files for extensions other than `.md` and `.emu` (fixes [#16](https://github.com/dillonkearns/elm-pages/issues/16)). - As always, be sure to also use the latest NPM package. + As always, be sure to also use the latest NPM package. From 3f1af7bb21a1d1eefa5f1aa19e8c520a07bb0d75 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 26 Oct 2020 11:28:36 -0700 Subject: [PATCH 103/106] Add initial release notes info. --- CHANGELOG-ELM.md | 7 ++ docs/7.0.0-elm-package-upgrade-guide.md | 92 +++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 docs/7.0.0-elm-package-upgrade-guide.md diff --git a/CHANGELOG-ELM.md b/CHANGELOG-ELM.md index daf885be..440ab90f 100644 --- a/CHANGELOG-ELM.md +++ b/CHANGELOG-ELM.md @@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [7.0.0] - 2020-10-26 + +### Fixed + +- Fixed a bug where using `ImagePath.external` in any `Head` tags would prepend the canonical site URL to the external URL, creating an invalid URL. Now it will only prepend the canonical site URL for local images, and it will use external image URLs directly with no modifications. +- StaticHttp performance improvements - whether you use the new beta build or the existing `elm-pages build` or `elm-pages develop` commands, you should see significantly faster StaticHttp any place you combined multiple StaticHttp results together. I would welcome getting any before/after performance numbers! + ## [6.0.0] - 2020-07-14 ### Fixed diff --git a/docs/7.0.0-elm-package-upgrade-guide.md b/docs/7.0.0-elm-package-upgrade-guide.md new file mode 100644 index 00000000..8d2aa64e --- /dev/null +++ b/docs/7.0.0-elm-package-upgrade-guide.md @@ -0,0 +1,92 @@ +# 7.0.0 Elm package upgrade guide + +Please ensure that you're on the latest elm-pages version of both the Elm package _and_ the NPM package before following these steps. + +There are two new beta features, which you can opt into by running a different build command (see 2) or calling a new generated function (see 3). + +There are 3 broad areas of change in this release. + +1. Breaking API changes +2. Beta build command +3. Beta Template Modules feature + +You can ignore (2) and (3) if you aren't interested in beta features. And even if you do choose to try these beta features, I recommend starting with (1) and getting things compiling without using any beta features first. + +## 1 - Breaking API changes + +### Manifest.Config now has `icons` + +- The `icons` field in the manifest config will only be used for the beta, no-webpack build (see section 2). If you aren't using it, you can simply pass in an empty list for icons. The new field in the Manifest.Config has this type `icons : List.List (Pages.Manifest.Icon pathKey)`. +- `Program model msg metadata view` changed to `Program model msg metadata view pathKey`. That means there is a new type variable in `Pages.Platform.Program`. You can fix this by adding `Pages.PathKey` (a type defined in the generated Pages.elm module) as the last type variable wherever you had an annotation using the `Pages.Platform.Program` type. + + + , onPageChange : + Maybe + ( + { path : PagePath pathKey + , query : Maybe String + , fragment : Maybe String + } + -> msg + ) + , onPageChange : + Maybe.Maybe + ( + { path : Pages.PagePath.PagePath pathKey + , query : Maybe.Maybe String.String + , fragment : Maybe.Maybe String.String + , metadata : metadata + } + -> msg + ) + + + { init : + Maybe + { path : PagePath pathKey + , query : Maybe String + , fragment : Maybe String + } + -> ( model, Cmd msg ) + + { init : + Maybe.Maybe + { path : + { path : Pages.PagePath.PagePath pathKey + , query : Maybe.Maybe String.String + , fragment : Maybe.Maybe String.String + } + , metadata : metadata + } + -> ( model, Platform.Cmd.Cmd msg ) + + + + + + + + , subscriptions : model -> Sub msg + + , subscriptions : + metadata + -> Pages.PagePath.PagePath pathKey + -> model + -> Platform.Sub.Sub msg + +## 2 - Beta build command + +---- Head - MINOR ---- + + Added: + appleTouchIcon : + Maybe.Maybe Basics.Int + -> Pages.ImagePath.ImagePath pathKey + -> Head.Tag pathKey + icon : + List.List ( Basics.Int, Basics.Int ) + -> MimeType.MimeImage + -> Pages.ImagePath.ImagePath pathKey + -> Head.Tag pathKey + +## 3 - Beta Template Modules feature From 7bb55dd9ffc50575635cdab5bba2ea2c40921036 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 26 Oct 2020 11:40:15 -0700 Subject: [PATCH 104/106] Update upgrade guide. --- docs/7.0.0-elm-package-upgrade-guide.md | 32 +++++++++++++++---------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/docs/7.0.0-elm-package-upgrade-guide.md b/docs/7.0.0-elm-package-upgrade-guide.md index 8d2aa64e..87e2f59a 100644 --- a/docs/7.0.0-elm-package-upgrade-guide.md +++ b/docs/7.0.0-elm-package-upgrade-guide.md @@ -19,7 +19,9 @@ You can ignore (2) and (3) if you aren't interested in beta features. And even i - The `icons` field in the manifest config will only be used for the beta, no-webpack build (see section 2). If you aren't using it, you can simply pass in an empty list for icons. The new field in the Manifest.Config has this type `icons : List.List (Pages.Manifest.Icon pathKey)`. - `Program model msg metadata view` changed to `Program model msg metadata view pathKey`. That means there is a new type variable in `Pages.Platform.Program`. You can fix this by adding `Pages.PathKey` (a type defined in the generated Pages.elm module) as the last type variable wherever you had an annotation using the `Pages.Platform.Program` type. +The following functions in `Pages.Platform.init` have also changed: +```elm , onPageChange : Maybe ( @@ -39,17 +41,14 @@ You can ignore (2) and (3) if you aren't interested in beta features. And even i } -> msg ) - - - { init : + , init : Maybe { path : PagePath pathKey , query : Maybe String , fragment : Maybe String } -> ( model, Cmd msg ) - - { init : + , init : Maybe.Maybe { path : { path : Pages.PagePath.PagePath pathKey @@ -59,23 +58,30 @@ You can ignore (2) and (3) if you aren't interested in beta features. And even i , metadata : metadata } -> ( model, Platform.Cmd.Cmd msg ) - - - - - - - , subscriptions : model -> Sub msg - , subscriptions : metadata -> Pages.PagePath.PagePath pathKey -> model -> Platform.Sub.Sub msg +``` ## 2 - Beta build command +You can run the regular build command and the beta build command side by side, and have the beta entrypoints living next to the current JS entrypoint you have (index.js). Hopefully that makes it easy to try out the beta and experiment with it without needing to change over right away. + +- `elm-pages build` and `elm-pages develop` use the `index.js` entrypoint. +- A new command, `elm-pages-beta` (doesn't take any arguments) uses the `beta-index.js` and `beta-style.css` entrypoints. + +Note that before you would use webpack to import CSS from the JS entrypoint (or something that was imported from there). Now there are separate entrypoints for JS and CSS. + +Some key points about the no-webpack build: + +- Whether you're using the beta no-webpack build or the previous build, you will see significant performance improvements for StaticHttp +- You can continue using the current elm-pages build and elm-pages develop commands. If you do that, you can just pass in icons = [] for the manifest config as the icons are only read for the new beta build. +- For the beta build, you can use the Manifest config's icons to set the PWA icon set, and you can set the favicon set using head tags an example here: https://github.com/dillonkearns/elm-pages/blob/5ad85cad0d5de9631ea06f98bba8ef1c96b1908a/examples/simple/src/Main.elm#L41-L130. Note that the beta build does not generate icons for you (I'm using cloudinary in the example, and it works way better and doesn't slow down the build). The beta build also doesn't do all of these things to remove bloat and give the user more control, while also making the elm-pages build more focused on doing a great job with the Elm code: https://github.com/dillonkearns/elm-pages/issues/148 +- To use the elm-pages-beta, you just need to create beta-index.js (using ES module syntax, see this example: https://github.com/dillonkearns/elm-pages/blob/elm-to-html/examples/simple/beta-index.js), and a beta-style.css entrypoint (this only using @import syntax, see https://github.com/dillonkearns/elm-pages/blob/elm-to-html/examples/simple/beta-style.css - you can bundle CSS code to this entrypoint if you need CSS bundling). + ---- Head - MINOR ---- Added: From aa2c80165c3d8c4db86fb18127aa22afeb87aaa6 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 26 Oct 2020 11:48:13 -0700 Subject: [PATCH 105/106] Move jest tests to another directory. --- .../generated-files.test.js.snap | 431 ++++++++++++------ jest-tests/generated-files.test.js | 18 + .../images/static-http-error.png | Bin .../src/Template/BlogIndex.elm | 0 .../src/Template/BlogPost.elm | 0 .../src/Template/Documentation.elm | 0 {tests => jest-tests}/src/Template/Page.elm | 0 .../src/Template/Showcase.elm | 0 package.json | 2 +- 9 files changed, 306 insertions(+), 145 deletions(-) rename {tests => jest-tests}/__snapshots__/generated-files.test.js.snap (55%) create mode 100644 jest-tests/generated-files.test.js rename {tests => jest-tests}/images/static-http-error.png (100%) rename {tests => jest-tests}/src/Template/BlogIndex.elm (100%) rename {tests => jest-tests}/src/Template/BlogPost.elm (100%) rename {tests => jest-tests}/src/Template/Documentation.elm (100%) rename {tests => jest-tests}/src/Template/Page.elm (100%) rename {tests => jest-tests}/src/Template/Showcase.elm (100%) diff --git a/tests/__snapshots__/generated-files.test.js.snap b/jest-tests/__snapshots__/generated-files.test.js.snap similarity index 55% rename from tests/__snapshots__/generated-files.test.js.snap rename to jest-tests/__snapshots__/generated-files.test.js.snap index 5c6bfb40..2e056da0 100644 --- a/tests/__snapshots__/generated-files.test.js.snap +++ b/jest-tests/__snapshots__/generated-files.test.js.snap @@ -118,15 +118,15 @@ exports[`generate template module connector 1`] = ` "module TemplateModulesBeta exposing (..) import Browser +import Pages.Manifest as Manifest import Shared -import TemplateType as M exposing (Metadata) +import TemplateType as M exposing (TemplateType) import Head import Html exposing (Html) import Pages import Pages.PagePath exposing (PagePath) import Pages.Platform import Pages.StaticHttp as StaticHttp -import Site import Template.BlogIndex import Template.BlogPost import Template.Documentation @@ -144,7 +144,7 @@ type alias Model = , query : Maybe String , fragment : Maybe String } - , metadata : Metadata + , metadata : TemplateType } } @@ -166,7 +166,7 @@ type Msg { path : PagePath Pages.PathKey , query : Maybe String , fragment : Maybe String - , metadata : Metadata + , metadata : TemplateType } | MsgBlogIndex Template.BlogIndex.Msg | MsgBlogPost Template.BlogPost.Msg @@ -177,10 +177,10 @@ type Msg view : - List ( PagePath Pages.PathKey, Metadata ) + List ( PagePath Pages.PathKey, TemplateType ) -> { path : PagePath Pages.PathKey - , frontmatter : Metadata + , frontmatter : TemplateType } -> StaticHttp.Request @@ -197,29 +197,38 @@ view siteMetadata page = case model.page of ModelBlogIndex subModel -> Template.BlogIndex.template.view - siteMetadata - data subModel - metadata + model.global + siteMetadata + { static = data + , sharedStatic = globalData + , metadata = metadata + , path = page.path + } rendered |> (\\\\{ title, body } -> - Shared.view + Shared.template.view globalData page model.global MsgGlobal ({ title = title, body = body } - |> Shared.map MsgBlogIndex + |> Shared.template.map MsgBlogIndex ) ) _ -> { title = \\"\\", body = Html.text \\"\\" } - , head = Template.BlogIndex.template.head data page.path metadata + , head = Template.BlogIndex.template.head + { static = data + , sharedStatic = globalData + , metadata = metadata + , path = page.path + } } ) (Template.BlogIndex.template.staticData siteMetadata) - (Shared.staticData siteMetadata) + (Shared.template.staticData siteMetadata) M.BlogPost metadata -> @@ -230,29 +239,38 @@ view siteMetadata page = case model.page of ModelBlogPost subModel -> Template.BlogPost.template.view - siteMetadata - data subModel - metadata + model.global + siteMetadata + { static = data + , sharedStatic = globalData + , metadata = metadata + , path = page.path + } rendered |> (\\\\{ title, body } -> - Shared.view + Shared.template.view globalData page model.global MsgGlobal ({ title = title, body = body } - |> Shared.map MsgBlogPost + |> Shared.template.map MsgBlogPost ) ) _ -> { title = \\"\\", body = Html.text \\"\\" } - , head = Template.BlogPost.template.head data page.path metadata + , head = Template.BlogPost.template.head + { static = data + , sharedStatic = globalData + , metadata = metadata + , path = page.path + } } ) (Template.BlogPost.template.staticData siteMetadata) - (Shared.staticData siteMetadata) + (Shared.template.staticData siteMetadata) M.Documentation metadata -> @@ -263,29 +281,38 @@ view siteMetadata page = case model.page of ModelDocumentation subModel -> Template.Documentation.template.view - siteMetadata - data subModel - metadata + model.global + siteMetadata + { static = data + , sharedStatic = globalData + , metadata = metadata + , path = page.path + } rendered |> (\\\\{ title, body } -> - Shared.view + Shared.template.view globalData page model.global MsgGlobal ({ title = title, body = body } - |> Shared.map MsgDocumentation + |> Shared.template.map MsgDocumentation ) ) _ -> { title = \\"\\", body = Html.text \\"\\" } - , head = Template.Documentation.template.head data page.path metadata + , head = Template.Documentation.template.head + { static = data + , sharedStatic = globalData + , metadata = metadata + , path = page.path + } } ) (Template.Documentation.template.staticData siteMetadata) - (Shared.staticData siteMetadata) + (Shared.template.staticData siteMetadata) M.Page metadata -> @@ -296,29 +323,38 @@ view siteMetadata page = case model.page of ModelPage subModel -> Template.Page.template.view - siteMetadata - data subModel - metadata + model.global + siteMetadata + { static = data + , sharedStatic = globalData + , metadata = metadata + , path = page.path + } rendered |> (\\\\{ title, body } -> - Shared.view + Shared.template.view globalData page model.global MsgGlobal ({ title = title, body = body } - |> Shared.map MsgPage + |> Shared.template.map MsgPage ) ) _ -> { title = \\"\\", body = Html.text \\"\\" } - , head = Template.Page.template.head data page.path metadata + , head = Template.Page.template.head + { static = data + , sharedStatic = globalData + , metadata = metadata + , path = page.path + } } ) (Template.Page.template.staticData siteMetadata) - (Shared.staticData siteMetadata) + (Shared.template.staticData siteMetadata) M.Showcase metadata -> @@ -329,29 +365,38 @@ view siteMetadata page = case model.page of ModelShowcase subModel -> Template.Showcase.template.view - siteMetadata - data subModel - metadata + model.global + siteMetadata + { static = data + , sharedStatic = globalData + , metadata = metadata + , path = page.path + } rendered |> (\\\\{ title, body } -> - Shared.view + Shared.template.view globalData page model.global MsgGlobal ({ title = title, body = body } - |> Shared.map MsgShowcase + |> Shared.template.map MsgShowcase ) ) _ -> { title = \\"\\", body = Html.text \\"\\" } - , head = Template.Showcase.template.head data page.path metadata + , head = Template.Showcase.template.head + { static = data + , sharedStatic = globalData + , metadata = metadata + , path = page.path + } } ) (Template.Showcase.template.staticData siteMetadata) - (Shared.staticData siteMetadata) + (Shared.template.staticData siteMetadata) @@ -364,54 +409,46 @@ init : , query : Maybe String , fragment : Maybe String } - , metadata : Metadata + , metadata : TemplateType } -> ( Model, Cmd Msg ) init currentGlobalModel maybePagePath = let ( sharedModel, globalCmd ) = - currentGlobalModel |> Maybe.map (\\\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Shared.init maybePagePath) + currentGlobalModel |> Maybe.map (\\\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Shared.template.init maybePagePath) - page = + ( templateModel, templateCmd ) = case maybePagePath |> Maybe.map .metadata of Nothing -> - NotFound + ( NotFound, Cmd.none ) Just meta -> case meta of M.BlogIndex metadata -> Template.BlogIndex.template.init metadata - |> Tuple.first - |> ModelBlogIndex + |> Tuple.mapBoth ModelBlogIndex (Cmd.map MsgBlogIndex) M.BlogPost metadata -> Template.BlogPost.template.init metadata - |> Tuple.first - |> ModelBlogPost + |> Tuple.mapBoth ModelBlogPost (Cmd.map MsgBlogPost) M.Documentation metadata -> Template.Documentation.template.init metadata - |> Tuple.first - |> ModelDocumentation + |> Tuple.mapBoth ModelDocumentation (Cmd.map MsgDocumentation) M.Page metadata -> Template.Page.template.init metadata - |> Tuple.first - |> ModelPage + |> Tuple.mapBoth ModelPage (Cmd.map MsgPage) M.Showcase metadata -> Template.Showcase.template.init metadata - |> Tuple.first - |> ModelShowcase + |> Tuple.mapBoth ModelShowcase (Cmd.map MsgShowcase) - - ( templateModel, templateCmd ) = - load sharedModel page in ( { global = sharedModel , page = templateModel @@ -431,23 +468,14 @@ update msg model = MsgGlobal msg_ -> let ( sharedModel, globalCmd ) = - Shared.update msg_ model.global - - ( templateModel, templateCmd ) = - load sharedModel model.page + Shared.template.update msg_ model.global in - ( { model - | global = sharedModel - , page = templateModel - } - , Cmd.batch - [ templateCmd - , globalCmd |> Cmd.map MsgGlobal - ] + ( { model | global = sharedModel } + , globalCmd |> Cmd.map MsgGlobal ) OnPageChange record -> - init (Just model.global) <| + (init (Just model.global) <| Just { path = { path = record.path @@ -456,171 +484,286 @@ update msg model = } , metadata = record.metadata } + ) + |> (\\\\( updatedModel, cmd ) -> + case Shared.template.onPageChange of + Nothing -> + ( updatedModel, cmd ) + + Just thingy -> + let + ( updatedGlobalModel, globalCmd ) = + Shared.template.update + (thingy + { path = record.path + , query = record.query + , fragment = record.fragment + } + ) + model.global + in + ( { updatedModel + | global = updatedGlobalModel + } + , Cmd.batch [ cmd, Cmd.map MsgGlobal globalCmd ] + ) + ) + MsgBlogIndex msg_ -> let - ( updatedPageModel, pageCmd ) = + ( updatedPageModel, pageCmd, ( newGlobalModel, newGlobalCmd ) ) = case ( model.page, model.current |> Maybe.map .metadata ) of ( ModelBlogIndex pageModel, Just (M.BlogIndex metadata) ) -> Template.BlogIndex.template.update metadata msg_ pageModel - |> Tuple.mapBoth ModelBlogIndex (Cmd.map MsgBlogIndex) + model.global + |> mapBoth ModelBlogIndex (Cmd.map MsgBlogIndex) + |> (\\\\( a, b, c ) -> + case c of + Just sharedMsg -> + ( a, b, Shared.template.update (Shared.SharedMsg sharedMsg) model.global ) + + Nothing -> + ( a, b, ( model.global, Cmd.none ) ) + ) _ -> - ( model.page, Cmd.none ) + ( model.page, Cmd.none, ( model.global, Cmd.none ) ) in - ( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd ) + ( { model | page = updatedPageModel, global = newGlobalModel } + , Cmd.batch [ pageCmd, newGlobalCmd |> Cmd.map MsgGlobal ] + ) MsgBlogPost msg_ -> let - ( updatedPageModel, pageCmd ) = + ( updatedPageModel, pageCmd, ( newGlobalModel, newGlobalCmd ) ) = case ( model.page, model.current |> Maybe.map .metadata ) of ( ModelBlogPost pageModel, Just (M.BlogPost metadata) ) -> Template.BlogPost.template.update metadata msg_ pageModel - |> Tuple.mapBoth ModelBlogPost (Cmd.map MsgBlogPost) + model.global + |> mapBoth ModelBlogPost (Cmd.map MsgBlogPost) + |> (\\\\( a, b, c ) -> + case c of + Just sharedMsg -> + ( a, b, Shared.template.update (Shared.SharedMsg sharedMsg) model.global ) + + Nothing -> + ( a, b, ( model.global, Cmd.none ) ) + ) _ -> - ( model.page, Cmd.none ) + ( model.page, Cmd.none, ( model.global, Cmd.none ) ) in - ( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd ) + ( { model | page = updatedPageModel, global = newGlobalModel } + , Cmd.batch [ pageCmd, newGlobalCmd |> Cmd.map MsgGlobal ] + ) MsgDocumentation msg_ -> let - ( updatedPageModel, pageCmd ) = + ( updatedPageModel, pageCmd, ( newGlobalModel, newGlobalCmd ) ) = case ( model.page, model.current |> Maybe.map .metadata ) of ( ModelDocumentation pageModel, Just (M.Documentation metadata) ) -> Template.Documentation.template.update metadata msg_ pageModel - |> Tuple.mapBoth ModelDocumentation (Cmd.map MsgDocumentation) + model.global + |> mapBoth ModelDocumentation (Cmd.map MsgDocumentation) + |> (\\\\( a, b, c ) -> + case c of + Just sharedMsg -> + ( a, b, Shared.template.update (Shared.SharedMsg sharedMsg) model.global ) + + Nothing -> + ( a, b, ( model.global, Cmd.none ) ) + ) _ -> - ( model.page, Cmd.none ) + ( model.page, Cmd.none, ( model.global, Cmd.none ) ) in - ( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd ) + ( { model | page = updatedPageModel, global = newGlobalModel } + , Cmd.batch [ pageCmd, newGlobalCmd |> Cmd.map MsgGlobal ] + ) MsgPage msg_ -> let - ( updatedPageModel, pageCmd ) = + ( updatedPageModel, pageCmd, ( newGlobalModel, newGlobalCmd ) ) = case ( model.page, model.current |> Maybe.map .metadata ) of ( ModelPage pageModel, Just (M.Page metadata) ) -> Template.Page.template.update metadata msg_ pageModel - |> Tuple.mapBoth ModelPage (Cmd.map MsgPage) + model.global + |> mapBoth ModelPage (Cmd.map MsgPage) + |> (\\\\( a, b, c ) -> + case c of + Just sharedMsg -> + ( a, b, Shared.template.update (Shared.SharedMsg sharedMsg) model.global ) + + Nothing -> + ( a, b, ( model.global, Cmd.none ) ) + ) _ -> - ( model.page, Cmd.none ) + ( model.page, Cmd.none, ( model.global, Cmd.none ) ) in - ( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd ) + ( { model | page = updatedPageModel, global = newGlobalModel } + , Cmd.batch [ pageCmd, newGlobalCmd |> Cmd.map MsgGlobal ] + ) MsgShowcase msg_ -> let - ( updatedPageModel, pageCmd ) = + ( updatedPageModel, pageCmd, ( newGlobalModel, newGlobalCmd ) ) = case ( model.page, model.current |> Maybe.map .metadata ) of ( ModelShowcase pageModel, Just (M.Showcase metadata) ) -> Template.Showcase.template.update metadata msg_ pageModel - |> Tuple.mapBoth ModelShowcase (Cmd.map MsgShowcase) + model.global + |> mapBoth ModelShowcase (Cmd.map MsgShowcase) + |> (\\\\( a, b, c ) -> + case c of + Just sharedMsg -> + ( a, b, Shared.template.update (Shared.SharedMsg sharedMsg) model.global ) + + Nothing -> + ( a, b, ( model.global, Cmd.none ) ) + ) _ -> - ( model.page, Cmd.none ) + ( model.page, Cmd.none, ( model.global, Cmd.none ) ) in - ( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd ) + ( { model | page = updatedPageModel, global = newGlobalModel } + , Cmd.batch [ pageCmd, newGlobalCmd |> Cmd.map MsgGlobal ] + ) +type alias SiteConfig = + { canonicalUrl : String + , manifest : Manifest.Config Pages.PathKey + } -load : Shared.Model -> TemplateModel -> ( TemplateModel, Cmd Msg ) -load sharedModel model = - case model of - ModelBlogIndex m -> - Template.BlogIndex.template.load sharedModel m - |> Tuple.mapFirst (ModelBlogIndex) - |> Tuple.mapSecond (Cmd.map MsgBlogIndex) +templateSubscriptions : TemplateType -> PagePath Pages.PathKey -> Model -> Sub Msg +templateSubscriptions metadata path model = + case model.page of + + ModelBlogIndex templateModel -> + case metadata of + M.BlogIndex templateMetadata -> + Template.BlogIndex.template.subscriptions + templateMetadata + path + templateModel + model.global + |> Sub.map MsgBlogIndex - ModelBlogPost m -> - Template.BlogPost.template.load sharedModel m - |> Tuple.mapFirst (ModelBlogPost) - |> Tuple.mapSecond (Cmd.map MsgBlogPost) + _ -> + Sub.none - ModelDocumentation m -> - Template.Documentation.template.load sharedModel m - |> Tuple.mapFirst (ModelDocumentation) - |> Tuple.mapSecond (Cmd.map MsgDocumentation) + + ModelBlogPost templateModel -> + case metadata of + M.BlogPost templateMetadata -> + Template.BlogPost.template.subscriptions + templateMetadata + path + templateModel + model.global + |> Sub.map MsgBlogPost - ModelPage m -> - Template.Page.template.load sharedModel m - |> Tuple.mapFirst (ModelPage) - |> Tuple.mapSecond (Cmd.map MsgPage) + _ -> + Sub.none + + + ModelDocumentation templateModel -> + case metadata of + M.Documentation templateMetadata -> + Template.Documentation.template.subscriptions + templateMetadata + path + templateModel + model.global + |> Sub.map MsgDocumentation + + _ -> + Sub.none + + + ModelPage templateModel -> + case metadata of + M.Page templateMetadata -> + Template.Page.template.subscriptions + templateMetadata + path + templateModel + model.global + |> Sub.map MsgPage + + _ -> + Sub.none + + + ModelShowcase templateModel -> + case metadata of + M.Showcase templateMetadata -> + Template.Showcase.template.subscriptions + templateMetadata + path + templateModel + model.global + |> Sub.map MsgShowcase + + _ -> + Sub.none - ModelShowcase m -> - Template.Showcase.template.load sharedModel m - |> Tuple.mapFirst (ModelShowcase) - |> Tuple.mapSecond (Cmd.map MsgShowcase) NotFound -> - ( model, Cmd.none ) + Sub.none - -save : TemplateModel -> Shared.Model -> Shared.Model -save model sharedModel= - case model of - ModelBlogIndex m -> - Template.BlogIndex.template.save m sharedModel - - ModelBlogPost m -> - Template.BlogPost.template.save m sharedModel - - ModelDocumentation m -> - Template.Documentation.template.save m sharedModel - - ModelPage m -> - Template.Page.template.save m sharedModel - - ModelShowcase m -> - Template.Showcase.template.save m sharedModel - - - NotFound -> - sharedModel - - - -mainTemplate { documents, manifest, canonicalSiteUrl, subscriptions } = +mainTemplate { documents, site } = Pages.Platform.init { init = init Nothing , view = view , update = update - , subscriptions = subscriptions + , subscriptions = + \\\\metadata path model -> + Sub.batch + [ Shared.template.subscriptions metadata path model.global |> Sub.map MsgGlobal + , templateSubscriptions metadata path model + ] , documents = documents , onPageChange = Just OnPageChange - , manifest = manifest -- Site.manifest - , canonicalSiteUrl = canonicalSiteUrl -- Site.canonicalUrl + , manifest = site.manifest + , canonicalSiteUrl = site.canonicalUrl , internals = Pages.internals } + mapDocument : Browser.Document Never -> Browser.Document mapped mapDocument document = { title = document.title , body = document.body |> List.map (Html.map never) } + + +mapBoth fnA fnB ( a, b, c ) = + ( fnA a, fnB b, c ) " `; diff --git a/jest-tests/generated-files.test.js b/jest-tests/generated-files.test.js new file mode 100644 index 00000000..8a4cbac9 --- /dev/null +++ b/jest-tests/generated-files.test.js @@ -0,0 +1,18 @@ +const { elmPagesCliFile, elmPagesUiFile } = require("../generator/src/elm-file-constants.js"); +const { generateTemplateModuleConnector } = require("../generator/src/generate-template-module-connector.js"); +const generateRecords = require("../generator/src/generate-records.js"); + +test('generate UI file', async () => { + process.chdir(__dirname); + const staticRoutes = await generateRecords(); + + global.builtAt = new Date("Sun, 17 May 2020 16:53:22 GMT"); + expect(elmPagesUiFile(staticRoutes, [])).toMatchSnapshot(); +}); + +test('generate template module connector', async () => { + process.chdir(__dirname); + const generated = await generateTemplateModuleConnector(); + + expect(generated).toMatchSnapshot(); +}); diff --git a/tests/images/static-http-error.png b/jest-tests/images/static-http-error.png similarity index 100% rename from tests/images/static-http-error.png rename to jest-tests/images/static-http-error.png diff --git a/tests/src/Template/BlogIndex.elm b/jest-tests/src/Template/BlogIndex.elm similarity index 100% rename from tests/src/Template/BlogIndex.elm rename to jest-tests/src/Template/BlogIndex.elm diff --git a/tests/src/Template/BlogPost.elm b/jest-tests/src/Template/BlogPost.elm similarity index 100% rename from tests/src/Template/BlogPost.elm rename to jest-tests/src/Template/BlogPost.elm diff --git a/tests/src/Template/Documentation.elm b/jest-tests/src/Template/Documentation.elm similarity index 100% rename from tests/src/Template/Documentation.elm rename to jest-tests/src/Template/Documentation.elm diff --git a/tests/src/Template/Page.elm b/jest-tests/src/Template/Page.elm similarity index 100% rename from tests/src/Template/Page.elm rename to jest-tests/src/Template/Page.elm diff --git a/tests/src/Template/Showcase.elm b/jest-tests/src/Template/Showcase.elm similarity index 100% rename from tests/src/Template/Showcase.elm rename to jest-tests/src/Template/Showcase.elm diff --git a/package.json b/package.json index 59e125d6..24e6300a 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "main": "index.js", "scripts": { "build": "cd generator && elm make src/Main.elm --output src/Main.js --optimize", - "test": "elm-test && jest" + "test": "elm-test && jest --rootDir jest-tests" }, "repository": "https://github.com/dillonkearns/elm-pages", "keywords": [ From 74b3ba2b5e373d2a8f5838a023add3b8ee29ac4c Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 26 Oct 2020 11:50:06 -0700 Subject: [PATCH 106/106] Fix compiler error. --- tests/BetaStaticHttpRequestsTests.elm | 2 +- tests/StaticHttpRequestsTests.elm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/BetaStaticHttpRequestsTests.elm b/tests/BetaStaticHttpRequestsTests.elm index 151256f7..d249fd27 100644 --- a/tests/BetaStaticHttpRequestsTests.elm +++ b/tests/BetaStaticHttpRequestsTests.elm @@ -169,7 +169,7 @@ startLowLevel generateFiles documentBodyResult staticHttpCache pages = Nothing -> Debug.todo "Couldn't find page" - , subscriptions = \_ -> Sub.none + , subscriptions = \_ _ _ -> Sub.none , document = document , content = [ ( [ "elm-pages" ] diff --git a/tests/StaticHttpRequestsTests.elm b/tests/StaticHttpRequestsTests.elm index 854d54db..61fa907c 100644 --- a/tests/StaticHttpRequestsTests.elm +++ b/tests/StaticHttpRequestsTests.elm @@ -852,7 +852,7 @@ startLowLevel generateFiles documentBodyResult staticHttpCache pages = Nothing -> Debug.todo "Couldn't find page" - , subscriptions = \_ -> Sub.none + , subscriptions = \_ _ _ -> Sub.none , document = document , content = [] , canonicalSiteUrl = canonicalSiteUrl