mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-28 06:05:31 +03:00
Update generator code to use new Path type.
This commit is contained in:
parent
1fa5dba75e
commit
a6b25bb53d
@ -1,7 +1,7 @@
|
||||
port module PagesNew exposing (PathKey, all, allImages, application, buildPage, images, isValidRoute, pages)
|
||||
|
||||
import Color exposing (Color)
|
||||
import Dict exposing (Dict)
|
||||
import Color exposing (Color)
|
||||
import Head
|
||||
import Html exposing (Html)
|
||||
import Json.Decode
|
||||
@ -9,11 +9,11 @@ import Json.Encode
|
||||
import Mark
|
||||
import Pages
|
||||
import Pages.ContentCache exposing (Page)
|
||||
import Pages.Document
|
||||
import Pages.Manifest exposing (DisplayMode, Orientation)
|
||||
import Pages.Manifest.Category as Category exposing (Category)
|
||||
import Pages.Path as Path exposing (Path)
|
||||
import Url.Parser as Url exposing ((</>), s)
|
||||
import Pages.Document
|
||||
import Pages.Path as Path exposing (Path)
|
||||
|
||||
|
||||
type PathKey
|
||||
@ -22,14 +22,13 @@ type PathKey
|
||||
|
||||
buildImage : List String -> Path PathKey Path.ToImage
|
||||
buildImage path =
|
||||
Path.buildImage PathKey path
|
||||
Path.buildImage PathKey ("images" :: path)
|
||||
|
||||
|
||||
|
||||
buildPage : List String -> Path PathKey Path.ToPage
|
||||
buildPage path =
|
||||
Path.buildPage PathKey path
|
||||
|
||||
|
||||
port toJsPort : Json.Encode.Value -> Cmd msg
|
||||
|
||||
|
||||
@ -57,54 +56,51 @@ application config =
|
||||
}
|
||||
|
||||
|
||||
|
||||
all : List (Path PathKey Path.ToPage)
|
||||
all =
|
||||
[ buildPage [ "blog", "types-over-conventions" ]
|
||||
, buildPage [ "docs", "directory-structure" ]
|
||||
, buildPage [ "docs" ]
|
||||
, buildPage []
|
||||
, buildPage [ "markdown" ]
|
||||
[ (buildPage [ "blog", "types-over-conventions" ])
|
||||
, (buildPage [ "docs", "directory-structure" ])
|
||||
, (buildPage [ "docs" ])
|
||||
, (buildPage [ ])
|
||||
, (buildPage [ "markdown" ])
|
||||
]
|
||||
|
||||
|
||||
pages =
|
||||
{ blog =
|
||||
{ typesOverConventions = buildPage [ "blog", "types-over-conventions" ]
|
||||
, all = [ buildPage [ "blog", "types-over-conventions" ] ]
|
||||
{ typesOverConventions = (buildPage [ "blog", "types-over-conventions" ])
|
||||
, all = [ (buildPage [ "blog", "types-over-conventions" ]) ]
|
||||
}
|
||||
, docs =
|
||||
{ directoryStructure = buildPage [ "docs", "directory-structure" ]
|
||||
, index = buildPage [ "docs" ]
|
||||
, all = [ buildPage [ "docs", "directory-structure" ], buildPage [ "docs" ] ]
|
||||
{ directoryStructure = (buildPage [ "docs", "directory-structure" ])
|
||||
, index = (buildPage [ "docs" ])
|
||||
, all = [ (buildPage [ "docs", "directory-structure" ]), (buildPage [ "docs" ]) ]
|
||||
}
|
||||
, index = buildPage []
|
||||
, markdown = buildPage [ "markdown" ]
|
||||
, all = [ buildPage [], buildPage [ "markdown" ] ]
|
||||
, index = (buildPage [ ])
|
||||
, markdown = (buildPage [ "markdown" ])
|
||||
, all = [ (buildPage [ ]), (buildPage [ "markdown" ]) ]
|
||||
}
|
||||
|
||||
|
||||
urlParser : Url.Parser (Path PathKey Path.ToPage -> a) a
|
||||
urlParser =
|
||||
Url.oneOf
|
||||
[ Url.map (buildPage [ "blog", "types-over-conventions" ]) (s "blog" </> s "types-over-conventions")
|
||||
, Url.map (buildPage [ "docs", "directory-structure" ]) (s "docs" </> s "directory-structure")
|
||||
, Url.map (buildPage [ "docs" ]) (s "docs" </> s "index")
|
||||
, Url.map (buildPage []) (s "index")
|
||||
, Url.map (buildPage [ ]) (s "index")
|
||||
, Url.map (buildPage [ "markdown" ]) (s "markdown")
|
||||
]
|
||||
|
||||
]
|
||||
|
||||
images =
|
||||
{ icon = buildImage [ "icon.svg" ]
|
||||
, mountains = buildImage [ "mountains.jpg" ]
|
||||
, all = [ buildImage [ "icon.svg" ], buildImage [ "mountains.jpg" ] ]
|
||||
{ icon = (buildImage [ "icon.svg" ])
|
||||
, mountains = (buildImage [ "mountains.jpg" ])
|
||||
, all = [ (buildImage [ "icon.svg" ]), (buildImage [ "mountains.jpg" ]) ]
|
||||
}
|
||||
|
||||
|
||||
allImages : List (Path PathKey Path.ToImage)
|
||||
allImages =
|
||||
[ buildImage [ "icon.svg" ]
|
||||
, buildImage [ "mountains.jpg" ]
|
||||
[(buildImage [ "icon.svg" ])
|
||||
, (buildImage [ "mountains.jpg" ])
|
||||
]
|
||||
|
||||
|
||||
@ -117,6 +113,7 @@ isValidRoute route =
|
||||
if
|
||||
(route |> String.startsWith "http://")
|
||||
|| (route |> String.startsWith "https://")
|
||||
|| (route |> String.startsWith "#")
|
||||
|| (validRoutes |> List.member route)
|
||||
then
|
||||
Ok ()
|
||||
@ -128,41 +125,37 @@ isValidRoute route =
|
||||
|> Err
|
||||
|
||||
|
||||
content : List ( List String, { extension : String, frontMatter : String, body : Maybe String } )
|
||||
content : List ( List String, { extension: String, frontMatter : String, body : Maybe String } )
|
||||
content =
|
||||
[ ( [ "blog", "types-over-conventions" ]
|
||||
, { frontMatter = """{"author":"Dillon Kearns","title":"Types Over Conventions","description":"TODO"}
|
||||
"""
|
||||
, body = Nothing
|
||||
, extension = "md"
|
||||
}
|
||||
)
|
||||
, ( [ "docs", "directory-structure" ]
|
||||
, { frontMatter = """{"title":"Directory Structure","type":"doc"}
|
||||
"""
|
||||
, body = Nothing
|
||||
, extension = "md"
|
||||
}
|
||||
)
|
||||
, ( [ "docs" ]
|
||||
, { frontMatter = """{"title":"Quick Start","type":"doc"}
|
||||
"""
|
||||
, body = Nothing
|
||||
, extension = "md"
|
||||
}
|
||||
)
|
||||
, ( []
|
||||
, { frontMatter = """{"title":"elm-pages - a statically typed site generator"}
|
||||
"""
|
||||
, body = Nothing
|
||||
, extension = "md"
|
||||
}
|
||||
)
|
||||
, ( [ "markdown" ]
|
||||
, { frontMatter = """{"title":"Hello from markdown! 👋"}
|
||||
"""
|
||||
, body = Nothing
|
||||
, extension = "md"
|
||||
}
|
||||
)
|
||||
[
|
||||
( ["blog", "types-over-conventions"]
|
||||
, { frontMatter = """{"author":"Dillon Kearns","title":"Types Over Conventions","description":"TODO"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
,
|
||||
( ["docs", "directory-structure"]
|
||||
, { frontMatter = """{"title":"Directory Structure","type":"doc"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
,
|
||||
( ["docs"]
|
||||
, { frontMatter = """{"title":"Quick Start","type":"doc"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
,
|
||||
( []
|
||||
, { frontMatter = """{"title":"elm-pages - a statically typed site generator"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
,
|
||||
( ["markdown"]
|
||||
, { frontMatter = """{"title":"Hello from markdown! 👋"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
|
||||
]
|
||||
|
@ -1,18 +1,10 @@
|
||||
generateRawContent = require("./generate-raw-content.js");
|
||||
const exposingList =
|
||||
"(application, PageRoute, all, pages, routeToString, Image, imageUrl, images, allImages, isValidRoute)";
|
||||
"(PathKey, all, allImages, application, buildPage, images, isValidRoute, pages)";
|
||||
|
||||
function staticRouteStuff(staticRoutes) {
|
||||
return `
|
||||
|
||||
type PageRoute = PageRoute (List String)
|
||||
|
||||
type Image = Image (List String)
|
||||
|
||||
imageUrl : Image -> String
|
||||
imageUrl (Image path) =
|
||||
"/"
|
||||
++ String.join "/" ("images" :: path)
|
||||
|
||||
${staticRoutes.allRoutes}
|
||||
|
||||
@ -22,26 +14,22 @@ ${staticRoutes.urlParser}
|
||||
|
||||
${staticRoutes.imageAssetsRecord}
|
||||
|
||||
allImages : List Image
|
||||
allImages : List (Path PathKey Path.ToImage)
|
||||
allImages =
|
||||
[${staticRoutes.allImages.join("\n , ")}
|
||||
]
|
||||
|
||||
routeToString : PageRoute -> String
|
||||
routeToString (PageRoute route) =
|
||||
"/"
|
||||
++ (route |> String.join "/")
|
||||
|
||||
|
||||
isValidRoute : String -> Result String ()
|
||||
isValidRoute route =
|
||||
let
|
||||
validRoutes =
|
||||
List.map routeToString all
|
||||
List.map Path.toString all
|
||||
in
|
||||
if
|
||||
(route |> String.startsWith "http://")
|
||||
|| (route |> String.startsWith "https://")
|
||||
|| (route |> String.startsWith "#")
|
||||
|| (validRoutes |> List.member route)
|
||||
then
|
||||
Ok ()
|
||||
@ -70,8 +58,22 @@ import Pages.Manifest exposing (DisplayMode, Orientation)
|
||||
import Pages.Manifest.Category as Category exposing (Category)
|
||||
import Url.Parser as Url exposing ((</>), s)
|
||||
import Pages.Document
|
||||
import Pages.Path as Path exposing (Path)
|
||||
|
||||
|
||||
type PathKey
|
||||
= PathKey
|
||||
|
||||
|
||||
buildImage : List String -> Path PathKey Path.ToImage
|
||||
buildImage path =
|
||||
Path.buildImage PathKey ("images" :: path)
|
||||
|
||||
|
||||
|
||||
buildPage : List String -> Path PathKey Path.ToPage
|
||||
buildPage path =
|
||||
Path.buildPage PathKey path
|
||||
port toJsPort : Json.Encode.Value -> Cmd msg
|
||||
|
||||
|
||||
@ -82,19 +84,7 @@ application :
|
||||
, view : userModel -> List ( List String, metadata ) -> Page metadata view -> { title : String, body : Html userMsg }
|
||||
, head : metadata -> List Head.Tag
|
||||
, documents : List (Pages.Document.DocumentParser metadata view)
|
||||
, manifest :
|
||||
{ backgroundColor : Maybe Color
|
||||
, categories : List Category
|
||||
, displayMode : DisplayMode
|
||||
, orientation : Orientation
|
||||
, description : String
|
||||
, iarcRatingId : Maybe String
|
||||
, name : String
|
||||
, themeColor : Maybe Color
|
||||
, startUrl : PageRoute
|
||||
, shortName : Maybe String
|
||||
, sourceIcon : Image
|
||||
}
|
||||
, manifest : Pages.Manifest.Config PathKey
|
||||
}
|
||||
-> Pages.Program userModel userMsg metadata view
|
||||
application config =
|
||||
@ -107,19 +97,7 @@ application config =
|
||||
, content = content
|
||||
, toJsPort = toJsPort
|
||||
, head = config.head
|
||||
, manifest =
|
||||
{ backgroundColor = config.manifest.backgroundColor
|
||||
, categories = config.manifest.categories
|
||||
, displayMode = config.manifest.displayMode
|
||||
, orientation = config.manifest.orientation
|
||||
, description = config.manifest.description
|
||||
, iarcRatingId = config.manifest.iarcRatingId
|
||||
, name = config.manifest.name
|
||||
, themeColor = config.manifest.themeColor
|
||||
, startUrl = Just (routeToString config.manifest.startUrl)
|
||||
, shortName = config.manifest.shortName
|
||||
, sourceIcon = "./" ++ imageUrl config.manifest.sourceIcon
|
||||
}
|
||||
, manifest = config.manifest
|
||||
}
|
||||
${staticRouteStuff(staticRoutes)}
|
||||
|
||||
@ -143,7 +121,20 @@ import Pages.Manifest exposing (DisplayMode, Orientation)
|
||||
import Pages.Manifest.Category as Category exposing (Category)
|
||||
import Url.Parser as Url exposing ((</>), s)
|
||||
import Pages.Document
|
||||
import Pages.Path as Path exposing (Path)
|
||||
|
||||
type PathKey
|
||||
= PathKey
|
||||
|
||||
|
||||
buildImage : List String -> Path PathKey Path.ToImage
|
||||
buildImage path =
|
||||
Path.buildImage PathKey ("images" :: path)
|
||||
|
||||
|
||||
buildPage : List String -> Path PathKey Path.ToPage
|
||||
buildPage path =
|
||||
Path.buildPage PathKey path
|
||||
|
||||
port toJsPort : Json.Encode.Value -> Cmd msg
|
||||
|
||||
@ -155,19 +146,7 @@ application :
|
||||
, view : userModel -> List ( List String, metadata ) -> Page metadata view -> { title : String, body : Html userMsg }
|
||||
, documents : List (Pages.Document.DocumentParser metadata view)
|
||||
, head : metadata -> List Head.Tag
|
||||
, manifest :
|
||||
{ backgroundColor : Maybe Color
|
||||
, categories : List Category
|
||||
, displayMode : DisplayMode
|
||||
, orientation : Orientation
|
||||
, description : String
|
||||
, iarcRatingId : Maybe String
|
||||
, name : String
|
||||
, themeColor : Maybe Color
|
||||
, startUrl : PageRoute
|
||||
, shortName : Maybe String
|
||||
, sourceIcon : Image
|
||||
}
|
||||
, manifest : Pages.Manifest.Config PathKey
|
||||
}
|
||||
-> Pages.Program userModel userMsg metadata view
|
||||
application config =
|
||||
@ -180,19 +159,7 @@ application config =
|
||||
, content = content
|
||||
, toJsPort = toJsPort
|
||||
, head = config.head
|
||||
, manifest =
|
||||
{ backgroundColor = config.manifest.backgroundColor
|
||||
, categories = config.manifest.categories
|
||||
, displayMode = config.manifest.displayMode
|
||||
, orientation = config.manifest.orientation
|
||||
, description = config.manifest.description
|
||||
, iarcRatingId = config.manifest.iarcRatingId
|
||||
, name = config.manifest.name
|
||||
, themeColor = config.manifest.themeColor
|
||||
, startUrl = Just (routeToString config.manifest.startUrl)
|
||||
, shortName = config.manifest.shortName
|
||||
, sourceIcon = "./" ++ imageUrl config.manifest.sourceIcon
|
||||
}
|
||||
, manifest = config.manifest
|
||||
}
|
||||
|
||||
|
||||
|
@ -76,7 +76,7 @@ function generate(scanned) {
|
||||
|
||||
// const elmType = pathFragments.map(toPascalCase).join("");
|
||||
const elmType =
|
||||
"(PageRoute [ " +
|
||||
"(buildPage [ " +
|
||||
pathFragments
|
||||
.filter(fragment => fragment !== "index")
|
||||
.map(fragment => `"${fragment}"`)
|
||||
@ -114,7 +114,7 @@ function getImageAssets() {
|
||||
.map(relativeImagePath)
|
||||
.forEach(info => {
|
||||
const elmType =
|
||||
"(Image [ " +
|
||||
"(buildImage [ " +
|
||||
info.fragmentsWithExtension
|
||||
.map(fragment => `"${fragment}"`)
|
||||
.join(", ") +
|
||||
@ -131,7 +131,7 @@ function allImageAssetNames() {
|
||||
.map(relativeImagePath)
|
||||
.map(info => {
|
||||
return (
|
||||
"(Image [ " +
|
||||
"(buildImage [ " +
|
||||
info.fragmentsWithExtension
|
||||
.map(fragment => `"${fragment}"`)
|
||||
.join(", ") +
|
||||
@ -208,7 +208,7 @@ function captureRouteRecord(pieces, elmType, record) {
|
||||
function formatAsElmList(name, items) {
|
||||
var formatted = items.join("\n , ");
|
||||
|
||||
var signature = name + " : List PageRoute\n";
|
||||
var signature = name + " : List (Path PathKey Path.ToPage)\n";
|
||||
|
||||
return signature + name + " =\n [ " + formatted + "\n ]";
|
||||
}
|
||||
@ -257,6 +257,6 @@ function formatAsElmUrlParser(pieces) {
|
||||
var parser =
|
||||
" [ " + pieces.map(p => p.parser).join("\n , ") + "\n ]";
|
||||
|
||||
return `urlParser : Url.Parser (PageRoute -> a) a
|
||||
return `urlParser : Url.Parser (Path PathKey Path.ToPage -> a) a
|
||||
urlParser =\n Url.oneOf\n ${parser} `;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user