mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-01 07:45:22 +03:00
Remove siteMetadata arguments for generateFiles.
This commit is contained in:
parent
3372c04e0d
commit
a7cdddb41a
@ -1,8 +1,6 @@
|
||||
module MySitemap exposing (install)
|
||||
|
||||
import Head
|
||||
import NoMetadata exposing (NoMetadata)
|
||||
import Pages.PagePath as PagePath exposing (PagePath)
|
||||
import Pages.Platform exposing (Builder)
|
||||
import Pages.StaticHttp as StaticHttp
|
||||
import Sitemap
|
||||
@ -11,25 +9,21 @@ import Sitemap
|
||||
install :
|
||||
{ siteUrl : String
|
||||
}
|
||||
->
|
||||
(List
|
||||
{ path : PagePath pathKey
|
||||
, frontmatter : NoMetadata
|
||||
, body : String
|
||||
}
|
||||
-> List { path : String, lastMod : Maybe String }
|
||||
)
|
||||
-> Builder pathKey userModel userMsg NoMetadata
|
||||
-> Builder pathKey userModel userMsg NoMetadata
|
||||
install config toSitemapEntry builder =
|
||||
-> (List item -> List { path : String, lastMod : Maybe String })
|
||||
-> StaticHttp.Request (List item)
|
||||
-> Builder pathKey userModel userMsg route
|
||||
-> Builder pathKey userModel userMsg route
|
||||
install config toSitemapEntry request builder =
|
||||
builder
|
||||
|> Pages.Platform.withGlobalHeadTags [ Head.sitemapLink "/sitemap.xml" ]
|
||||
|> Pages.Platform.withFileGenerator
|
||||
(\siteMetadata ->
|
||||
StaticHttp.succeed
|
||||
[ Ok
|
||||
{ path = [ "sitemap.xml" ]
|
||||
, content = Sitemap.build config (toSitemapEntry siteMetadata)
|
||||
}
|
||||
]
|
||||
(request
|
||||
|> StaticHttp.map
|
||||
(\items ->
|
||||
[ Ok
|
||||
{ path = [ "sitemap.xml" ]
|
||||
, content = Sitemap.build config (toSitemapEntry items)
|
||||
}
|
||||
]
|
||||
)
|
||||
)
|
||||
|
@ -16,16 +16,11 @@ generate :
|
||||
, builtAt : Time.Posix
|
||||
, indexPage : PagePath pathKey
|
||||
}
|
||||
->
|
||||
({ path : PagePath pathKey
|
||||
, frontmatter : NoMetadata
|
||||
, body : String
|
||||
}
|
||||
-> Maybe Rss.Item
|
||||
)
|
||||
-> Builder pathKey userModel userMsg NoMetadata
|
||||
-> Builder pathKey userModel userMsg NoMetadata
|
||||
generate options metadataToRssItem builder =
|
||||
-> (item -> Maybe Rss.Item)
|
||||
-> StaticHttp.Request (List item)
|
||||
-> Builder pathKey userModel userMsg route
|
||||
-> Builder pathKey userModel userMsg route
|
||||
generate options metadataToRssItem itemsRequest builder =
|
||||
let
|
||||
feedFilePath =
|
||||
(options.indexPage
|
||||
@ -35,23 +30,25 @@ generate options metadataToRssItem builder =
|
||||
in
|
||||
builder
|
||||
|> Pages.Platform.withFileGenerator
|
||||
(\siteMetadata ->
|
||||
{ path = feedFilePath
|
||||
, content =
|
||||
Rss.generate
|
||||
{ title = options.title
|
||||
, description = options.siteTagline
|
||||
(itemsRequest
|
||||
|> StaticHttp.map
|
||||
(\items ->
|
||||
{ path = feedFilePath
|
||||
, content =
|
||||
Rss.generate
|
||||
{ title = options.title
|
||||
, description = options.siteTagline
|
||||
|
||||
-- TODO make sure you don't add an extra "/"
|
||||
, url = options.siteUrl ++ "/" ++ PagePath.toString options.indexPage
|
||||
, lastBuildTime = options.builtAt
|
||||
, generator = Just "elm-pages"
|
||||
, items = siteMetadata |> List.filterMap metadataToRssItem
|
||||
, siteUrl = options.siteUrl
|
||||
-- TODO make sure you don't add an extra "/"
|
||||
, url = options.siteUrl ++ "/" ++ PagePath.toString options.indexPage
|
||||
, lastBuildTime = options.builtAt
|
||||
, generator = Just "elm-pages"
|
||||
, items = items |> List.filterMap metadataToRssItem
|
||||
, siteUrl = options.siteUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
|> Ok
|
||||
|> List.singleton
|
||||
|> StaticHttp.succeed
|
||||
|> Ok
|
||||
|> List.singleton
|
||||
)
|
||||
)
|
||||
|> Pages.Platform.withGlobalHeadTags [ Head.rssLink (feedFilePath |> String.join "/") ]
|
||||
|
@ -9,7 +9,6 @@ import Head
|
||||
import Head.Seo as Seo
|
||||
import Json.Decode as Decode
|
||||
import MarkdownRenderer
|
||||
import NoMetadata exposing (NoMetadata(..), NoView)
|
||||
import Pages exposing (images)
|
||||
import Pages.PagePath as PagePath exposing (PagePath)
|
||||
import Pages.StaticHttp as StaticHttp
|
||||
|
@ -642,21 +642,15 @@ application :
|
||||
, fromJsPort : Sub Decode.Value
|
||||
, manifest : Manifest.Config pathKey
|
||||
, generateFiles :
|
||||
List
|
||||
{ path : PagePath pathKey
|
||||
, frontmatter : NoMetadata
|
||||
, body : String
|
||||
}
|
||||
->
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
)
|
||||
, canonicalSiteUrl : String
|
||||
, pathKey : pathKey
|
||||
, onPageChange :
|
||||
@ -801,21 +795,15 @@ cliApplication :
|
||||
, fromJsPort : Sub Decode.Value
|
||||
, manifest : Manifest.Config pathKey
|
||||
, generateFiles :
|
||||
List
|
||||
{ path : PagePath pathKey
|
||||
, frontmatter : NoMetadata
|
||||
, body : String
|
||||
}
|
||||
->
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
)
|
||||
, canonicalSiteUrl : String
|
||||
, pathKey : pathKey
|
||||
, onPageChange :
|
||||
|
@ -94,21 +94,15 @@ type alias Config pathKey userMsg userModel route =
|
||||
, fromJsPort : Sub Decode.Value
|
||||
, manifest : Manifest.Config pathKey
|
||||
, generateFiles :
|
||||
List
|
||||
{ path : PagePath pathKey
|
||||
, frontmatter : NoMetadata
|
||||
, body : String
|
||||
}
|
||||
->
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
)
|
||||
, canonicalSiteUrl : String
|
||||
, pathKey : pathKey
|
||||
, onPageChange :
|
||||
@ -398,7 +392,7 @@ init toModel contentCache siteMetadata config flags =
|
||||
-- elmToHtmlBetaInit { secrets = secrets, mode = mode, staticHttpCache = staticHttpCache } toModel contentCache siteMetadata config flags
|
||||
--
|
||||
_ ->
|
||||
initLegacy staticRoutes { secrets = secrets, mode = mode, staticHttpCache = staticHttpCache } toModel contentCache siteMetadata config
|
||||
initLegacy staticRoutes { secrets = secrets, mode = mode, staticHttpCache = staticHttpCache } toModel contentCache config
|
||||
|
||||
Err error ->
|
||||
updateAndSendPortIfDone
|
||||
@ -446,10 +440,9 @@ initLegacy :
|
||||
-> { a | secrets : SecretsDict, mode : Mode, staticHttpCache : Dict String (Maybe String) }
|
||||
-> (Model pathKey route -> model)
|
||||
-> ContentCache
|
||||
-> Result (List BuildError) (List ( PagePath pathKey, NoMetadata ))
|
||||
-> Config pathKey userMsg userModel route
|
||||
-> ( model, Effect pathKey )
|
||||
initLegacy staticRoutes { secrets, mode, staticHttpCache } toModel contentCache siteMetadata config =
|
||||
initLegacy staticRoutes { secrets, mode, staticHttpCache } toModel contentCache config =
|
||||
case contentCache of
|
||||
Ok _ ->
|
||||
let
|
||||
@ -460,11 +453,11 @@ initLegacy staticRoutes { secrets, mode, staticHttpCache } toModel contentCache
|
||||
staticResponses =
|
||||
case requests of
|
||||
Ok okRequests ->
|
||||
StaticResponses.init siteMetadata config okRequests
|
||||
StaticResponses.init config okRequests
|
||||
|
||||
Err _ ->
|
||||
-- TODO need to handle errors better?
|
||||
StaticResponses.init siteMetadata config []
|
||||
StaticResponses.init config []
|
||||
in
|
||||
StaticResponses.nextStep config mode secrets staticHttpCache [] staticResponses
|
||||
|> nextStepToEffect contentCache config (Model staticResponses secrets [] staticHttpCache mode [] [] staticRoutes)
|
||||
|
@ -37,74 +37,30 @@ error =
|
||||
|
||||
|
||||
init :
|
||||
Result (List BuildError) (List ( PagePath pathKey, NoMetadata ))
|
||||
->
|
||||
{ config
|
||||
| content : Content
|
||||
, generateFiles :
|
||||
List
|
||||
{ path : PagePath pathKey
|
||||
, frontmatter : NoMetadata
|
||||
, body : String
|
||||
}
|
||||
->
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
{ config
|
||||
| content : Content
|
||||
, generateFiles :
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
-> List ( PagePath pathKey, StaticHttp.Request value )
|
||||
-> StaticResponses
|
||||
init siteMetadataResult config list =
|
||||
init config list =
|
||||
let
|
||||
generateFilesRequest : StaticHttp.Request (List (Result String { path : List String, content : String }))
|
||||
generateFilesRequest =
|
||||
config.generateFiles siteMetadataWithContent
|
||||
|
||||
generateFilesStaticRequest =
|
||||
( -- we don't want to include the CLI-only StaticHttp responses in the production bundle
|
||||
-- since that data is only needed to run these functions during the build step
|
||||
-- in the future, this could be refactored to have a type to represent this more clearly
|
||||
cliDictKey
|
||||
, NotFetched (generateFilesRequest |> StaticHttp.map (\_ -> ())) Dict.empty
|
||||
, NotFetched (config.generateFiles |> StaticHttp.map (\_ -> ())) Dict.empty
|
||||
)
|
||||
|
||||
siteMetadataWithContent =
|
||||
siteMetadataResult
|
||||
|> Result.withDefault []
|
||||
|> List.map
|
||||
(\( pagePath, metadata ) ->
|
||||
let
|
||||
contentForPage =
|
||||
config.content
|
||||
|> List.filterMap
|
||||
(\( path, { body } ) ->
|
||||
let
|
||||
pagePathToGenerate =
|
||||
PagePath.toString pagePath
|
||||
|
||||
currentContentPath =
|
||||
"/" ++ (path |> String.join "/")
|
||||
in
|
||||
if pagePathToGenerate == currentContentPath then
|
||||
Just body
|
||||
|
||||
else
|
||||
Nothing
|
||||
)
|
||||
|> List.head
|
||||
|> Maybe.andThen identity
|
||||
in
|
||||
{ path = pagePath
|
||||
, frontmatter = metadata
|
||||
, body = contentForPage |> Maybe.withDefault ""
|
||||
}
|
||||
)
|
||||
in
|
||||
list
|
||||
|> List.map
|
||||
@ -189,21 +145,15 @@ nextStep :
|
||||
| content : Content
|
||||
, manifest : Manifest.Config pathKey
|
||||
, generateFiles :
|
||||
List
|
||||
{ path : PagePath pathKey
|
||||
, frontmatter : NoMetadata
|
||||
, body : String
|
||||
}
|
||||
->
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
-> Mode
|
||||
-> SecretsDict
|
||||
@ -213,9 +163,6 @@ nextStep :
|
||||
-> NextStep pathKey
|
||||
nextStep config mode secrets allRawResponses errors (StaticResponses staticResponses) =
|
||||
let
|
||||
metadataForGenerateFiles =
|
||||
[]
|
||||
|
||||
generatedFiles : List (Result String { path : List String, content : String })
|
||||
generatedFiles =
|
||||
resolvedGenerateFilesResult |> Result.withDefault []
|
||||
@ -223,7 +170,7 @@ nextStep config mode secrets allRawResponses errors (StaticResponses staticRespo
|
||||
resolvedGenerateFilesResult : Result StaticHttpRequest.Error (List (Result String { path : List String, content : String }))
|
||||
resolvedGenerateFilesResult =
|
||||
StaticHttpRequest.resolve ApplicationType.Cli
|
||||
(config.generateFiles metadataForGenerateFiles)
|
||||
config.generateFiles
|
||||
(allRawResponses |> Dict.Extra.filterMap (\_ value -> Just value))
|
||||
|
||||
generatedOkayFiles : List { path : List String, content : String }
|
||||
|
@ -107,21 +107,15 @@ type Builder pathKey model msg route
|
||||
}
|
||||
, manifest : Pages.Manifest.Config pathKey
|
||||
, generateFiles :
|
||||
List
|
||||
{ path : PagePath pathKey
|
||||
, frontmatter : NoMetadata
|
||||
, body : String
|
||||
}
|
||||
->
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
)
|
||||
, onPageChange :
|
||||
Maybe
|
||||
({ path : PagePath pathKey
|
||||
@ -205,7 +199,7 @@ init config =
|
||||
, subscriptions = config.subscriptions
|
||||
, manifest = config.manifest
|
||||
, onPageChange = config.onPageChange
|
||||
, generateFiles = \_ -> StaticHttp.succeed []
|
||||
, generateFiles = StaticHttp.succeed []
|
||||
, canonicalSiteUrl = config.canonicalSiteUrl
|
||||
, internals = config.internals
|
||||
}
|
||||
@ -266,28 +260,24 @@ Disallow: /cgi-bin/
|
||||
|
||||
-}
|
||||
withFileGenerator :
|
||||
(List { path : PagePath pathKey, frontmatter : NoMetadata, body : String }
|
||||
->
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
-> Builder pathKey model msg route
|
||||
-> Builder pathKey model msg route
|
||||
withFileGenerator generateFiles (Builder config) =
|
||||
Builder
|
||||
{ config
|
||||
| generateFiles =
|
||||
\data ->
|
||||
StaticHttp.map2 (++)
|
||||
(generateFiles data)
|
||||
(config.generateFiles data)
|
||||
StaticHttp.map2 (++)
|
||||
generateFiles
|
||||
config.generateFiles
|
||||
}
|
||||
|
||||
|
||||
@ -336,21 +326,15 @@ application :
|
||||
}
|
||||
, manifest : Pages.Manifest.Config pathKey
|
||||
, generateFiles :
|
||||
List
|
||||
{ path : PagePath pathKey
|
||||
, frontmatter : NoMetadata
|
||||
, body : String
|
||||
}
|
||||
->
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
StaticHttp.Request
|
||||
(List
|
||||
(Result
|
||||
String
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
)
|
||||
)
|
||||
, onPageChange :
|
||||
Maybe
|
||||
({ path : PagePath pathKey
|
||||
|
Loading…
Reference in New Issue
Block a user