mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-28 06:05:31 +03:00
Add starting point for function to extract StaticRequests for each page.
This commit is contained in:
parent
40089da983
commit
899f872223
@ -155,14 +155,17 @@ pageViewOrError pathKey viewFn model cache =
|
||||
}
|
||||
|
||||
Err error ->
|
||||
{ title = "Parsing error"
|
||||
, body = Html.text error
|
||||
}
|
||||
Debug.todo "asdf"
|
||||
|
||||
ContentCache.NeedContent extension _ ->
|
||||
-- { title = "Parsing error"
|
||||
-- , body = Html.text error
|
||||
-- }
|
||||
ContentCache.NeedContent extension a ->
|
||||
{ title = "", body = Html.text "" }
|
||||
|
||||
ContentCache.Unparsed extension _ _ ->
|
||||
-- Debug.todo (Debug.toString a)
|
||||
ContentCache.Unparsed extension a b ->
|
||||
-- Debug.todo (Debug.toString b)
|
||||
{ title = "", body = Html.text "" }
|
||||
|
||||
Nothing ->
|
||||
@ -335,7 +338,8 @@ init pathKey canonicalSiteUrl document toJsPort viewFn content initUserModel fla
|
||||
-- Debug.todo error
|
||||
-- Cmd.none
|
||||
_ ->
|
||||
Cmd.none
|
||||
-- Cmd.none
|
||||
Debug.todo "Error"
|
||||
|
||||
( maybePagePath, maybeMetadata ) =
|
||||
case ContentCache.lookupMetadata pathKey (Ok okCache) url of
|
||||
@ -401,7 +405,7 @@ update :
|
||||
-> ModelDetails userModel metadata view
|
||||
-> ( ModelDetails userModel metadata view, Cmd (Msg userMsg metadata view) )
|
||||
update pathKey onPageChangeMsg toJsPort document userUpdate msg model =
|
||||
case msg of
|
||||
case msg |> Debug.log "msg" of
|
||||
LinkClicked urlRequest ->
|
||||
case urlRequest of
|
||||
Browser.Internal url ->
|
||||
@ -590,6 +594,13 @@ cliApplication config =
|
||||
Platform.worker
|
||||
{ init =
|
||||
\flags ->
|
||||
let
|
||||
okCache =
|
||||
Debug.todo ""
|
||||
|
||||
_ =
|
||||
Debug.log "@@@@@@@@@@@@@@@@@@ log from cli"
|
||||
in
|
||||
( CliModel
|
||||
, case contentCache of
|
||||
Ok _ ->
|
||||
@ -599,6 +610,7 @@ cliApplication config =
|
||||
(Json.Encode.object
|
||||
[ ( "errors", encodeErrors pageErrors )
|
||||
, ( "manifest", Manifest.toJson config.manifest )
|
||||
, ( "pages", Json.Encode.string "pages!" )
|
||||
]
|
||||
)
|
||||
|
||||
@ -606,6 +618,7 @@ cliApplication config =
|
||||
config.toJsPort
|
||||
(Json.Encode.object
|
||||
[ ( "manifest", Manifest.toJson config.manifest )
|
||||
, ( "pages", Json.Encode.string "pages!" )
|
||||
]
|
||||
)
|
||||
|
||||
@ -622,6 +635,78 @@ cliApplication config =
|
||||
}
|
||||
|
||||
|
||||
staticResponseForPage :
|
||||
List ( PagePath pathKey, metadata )
|
||||
->
|
||||
(List ( PagePath pathKey, metadata )
|
||||
->
|
||||
{ path : PagePath pathKey
|
||||
, frontmatter : metadata
|
||||
}
|
||||
->
|
||||
( StaticHttp.Request
|
||||
, Decode.Value
|
||||
->
|
||||
Result String
|
||||
{ view :
|
||||
userModel
|
||||
-> view
|
||||
->
|
||||
{ title : String
|
||||
, body : Html userMsg
|
||||
}
|
||||
, head : List (Head.Tag pathKey)
|
||||
}
|
||||
)
|
||||
)
|
||||
-> pathKey
|
||||
-> Result (List String) (List ( PagePath pathKey, String ))
|
||||
staticResponseForPage siteMetadata viewFn pathKey =
|
||||
siteMetadata
|
||||
|> List.map
|
||||
(\( pagePath, frontmatter ) ->
|
||||
let
|
||||
thing =
|
||||
viewFn siteMetadata
|
||||
{ path = pagePath
|
||||
, frontmatter = frontmatter
|
||||
}
|
||||
in
|
||||
Ok ( pagePath, "" )
|
||||
)
|
||||
|> combine
|
||||
|
||||
|
||||
combine : List (Result error ( key, success )) -> Result (List error) (List ( key, success ))
|
||||
combine list =
|
||||
list
|
||||
|> List.foldr resultFolder (Ok [])
|
||||
|
||||
|
||||
resultFolder : Result error a -> Result (List error) (List a) -> Result (List error) (List a)
|
||||
resultFolder current soFarResult =
|
||||
case soFarResult of
|
||||
Ok soFarOk ->
|
||||
case current of
|
||||
Ok currentOk ->
|
||||
currentOk
|
||||
:: soFarOk
|
||||
|> Ok
|
||||
|
||||
Err error ->
|
||||
Err [ error ]
|
||||
|
||||
Err soFarErr ->
|
||||
case current of
|
||||
Ok currentOk ->
|
||||
Err soFarErr
|
||||
|
||||
Err error ->
|
||||
error
|
||||
:: soFarErr
|
||||
|> Err
|
||||
|
||||
|
||||
encodeErrors errors =
|
||||
errors
|
||||
|> Json.Encode.dict
|
||||
|
@ -130,14 +130,14 @@ view siteMetadata page =
|
||||
case page.frontmatter of
|
||||
Metadata.Page metadata ->
|
||||
StaticHttp.withData ""
|
||||
(Decode.succeed "abcdefg")
|
||||
(Decode.field "stargazers_count" Decode.int)
|
||||
(\staticData ->
|
||||
{ view =
|
||||
\model viewForPage ->
|
||||
{ title = metadata.title
|
||||
, body =
|
||||
"The value is: "
|
||||
++ staticData
|
||||
"elm-pages ⭐️'s: "
|
||||
++ String.fromInt staticData
|
||||
|> Element.text
|
||||
|> wrapBody
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
module.exports = function(markdown, markup, includeBody) {
|
||||
return `content : List ( List String, { extension: String, frontMatter : String, body : Maybe String, staticData : Maybe String } )
|
||||
return `content : List ( List String, { extension: String, frontMatter : String, body : Maybe String } )
|
||||
content =
|
||||
[ ${markdown.concat(markup).map(entry => toEntry(entry, includeBody))}
|
||||
]`;
|
||||
@ -17,7 +17,6 @@ function toEntry(entry, includeBody) {
|
||||
( [${fullPath.join(", ")}]
|
||||
, { frontMatter = """${entry.metadata}
|
||||
""" , body = ${body(entry, includeBody)}
|
||||
, staticData = ${staticData(entry, includeBody)}
|
||||
, extension = "${entry.extension}"
|
||||
} )
|
||||
`;
|
||||
@ -33,12 +32,12 @@ function body(entry, includeBody) {
|
||||
}
|
||||
}
|
||||
|
||||
function staticData(entry, includeBody) {
|
||||
if (includeBody) {
|
||||
return `Just """${entry.staticData.replace(/\\/g, "\\\\")}
|
||||
"""
|
||||
`;
|
||||
} else {
|
||||
return `Nothing`;
|
||||
}
|
||||
}
|
||||
// function staticData(entry, includeBody) {
|
||||
// if (includeBody) {
|
||||
// return `Just """${entry.staticData.replace(/\\/g, "\\\\")}
|
||||
// """
|
||||
// `;
|
||||
// } else {
|
||||
// return `Nothing`;
|
||||
// }
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user