mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2025-01-03 01:16:14 +03:00
Merge branch 'generate-vendor-files'
This commit is contained in:
commit
acdf85fcb8
1
examples/docs/.npmrc
Normal file
1
examples/docs/.npmrc
Normal file
@ -0,0 +1 @@
|
||||
loglevel=warn
|
@ -2,7 +2,6 @@
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"src",
|
||||
"../../elm-package/src",
|
||||
"../../src",
|
||||
"gen",
|
||||
"elm-markdown-parser"
|
||||
@ -48,4 +47,4 @@
|
||||
"elm/random": "1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,158 +0,0 @@
|
||||
port module PagesNew exposing (PathKey, allPages, allImages, application, images, isValidRoute, pages)
|
||||
|
||||
import Dict exposing (Dict)
|
||||
import Color exposing (Color)
|
||||
import Head
|
||||
import Html exposing (Html)
|
||||
import Json.Decode
|
||||
import Json.Encode
|
||||
import Mark
|
||||
import Pages
|
||||
import Pages.ContentCache exposing (Page)
|
||||
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.ImagePath as ImagePath exposing (ImagePath)
|
||||
import Pages.PagePath as PagePath exposing (PagePath)
|
||||
|
||||
|
||||
type PathKey
|
||||
= PathKey
|
||||
|
||||
|
||||
buildImage : List String -> ImagePath PathKey
|
||||
buildImage path =
|
||||
ImagePath.build PathKey ("images" :: path)
|
||||
|
||||
|
||||
|
||||
buildPage : List String -> PagePath PathKey
|
||||
buildPage path =
|
||||
PagePath.build PathKey path
|
||||
|
||||
|
||||
port toJsPort : Json.Encode.Value -> Cmd msg
|
||||
|
||||
|
||||
application :
|
||||
{ init : ( userModel, Cmd userMsg )
|
||||
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
|
||||
, subscriptions : userModel -> Sub userMsg
|
||||
, view : userModel -> List ( List String, metadata ) -> Page metadata view -> { title : String, body : Html userMsg }
|
||||
, head : metadata -> List (Head.Tag PathKey)
|
||||
, documents : List (Pages.Document.DocumentParser metadata view)
|
||||
, manifest : Pages.Manifest.Config PathKey
|
||||
, canonicalSiteUrl : String
|
||||
}
|
||||
-> Pages.Program userModel userMsg metadata view
|
||||
application config =
|
||||
Pages.application
|
||||
{ init = config.init
|
||||
, view = config.view
|
||||
, update = config.update
|
||||
, subscriptions = config.subscriptions
|
||||
, document = Dict.fromList config.documents
|
||||
, content = content
|
||||
, toJsPort = toJsPort
|
||||
, head = config.head
|
||||
, manifest = config.manifest
|
||||
, canonicalSiteUrl = config.canonicalSiteUrl
|
||||
}
|
||||
|
||||
|
||||
|
||||
allPages : List (PagePath PathKey)
|
||||
allPages =
|
||||
[ (buildPage [ "blog" ])
|
||||
, (buildPage [ "blog", "types-over-conventions" ])
|
||||
, (buildPage [ "docs", "directory-structure" ])
|
||||
, (buildPage [ "docs" ])
|
||||
, (buildPage [ ])
|
||||
]
|
||||
|
||||
pages =
|
||||
{ blog =
|
||||
{ index = (buildPage [ "blog" ])
|
||||
, typesOverConventions = (buildPage [ "blog", "types-over-conventions" ])
|
||||
, all = [ (buildPage [ "blog" ]), (buildPage [ "blog", "types-over-conventions" ]) ]
|
||||
}
|
||||
, docs =
|
||||
{ directoryStructure = (buildPage [ "docs", "directory-structure" ])
|
||||
, index = (buildPage [ "docs" ])
|
||||
, all = [ (buildPage [ "docs", "directory-structure" ]), (buildPage [ "docs" ]) ]
|
||||
}
|
||||
, index = (buildPage [ ])
|
||||
, all = [ (buildPage [ ]) ]
|
||||
}
|
||||
|
||||
images =
|
||||
{ dillon = (buildImage [ "dillon.jpg" ])
|
||||
, icon = (buildImage [ "icon.svg" ])
|
||||
, mountains = (buildImage [ "mountains.jpg" ])
|
||||
, all = [ (buildImage [ "dillon.jpg" ]), (buildImage [ "icon.svg" ]), (buildImage [ "mountains.jpg" ]) ]
|
||||
}
|
||||
|
||||
allImages : List (ImagePath PathKey)
|
||||
allImages =
|
||||
[(buildImage [ "dillon.jpg" ])
|
||||
, (buildImage [ "icon.svg" ])
|
||||
, (buildImage [ "mountains.jpg" ])
|
||||
]
|
||||
|
||||
|
||||
isValidRoute : String -> Result String ()
|
||||
isValidRoute route =
|
||||
let
|
||||
validRoutes =
|
||||
List.map PagePath.toString allPages
|
||||
in
|
||||
if
|
||||
(route |> String.startsWith "http://")
|
||||
|| (route |> String.startsWith "https://")
|
||||
|| (route |> String.startsWith "#")
|
||||
|| (validRoutes |> List.member route)
|
||||
then
|
||||
Ok ()
|
||||
|
||||
else
|
||||
("Valid routes:\n"
|
||||
++ String.join "\n\n" validRoutes
|
||||
)
|
||||
|> Err
|
||||
|
||||
|
||||
content : List ( List String, { extension: String, frontMatter : String, body : Maybe String } )
|
||||
content =
|
||||
[
|
||||
( ["blog"]
|
||||
, { frontMatter = """{"title":"elm-pages blog","type":"blog-index"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
,
|
||||
( ["blog", "types-over-conventions"]
|
||||
, { frontMatter = """{"type":"blog","author":"Dillon Kearns","title":"Types Over Conventions","description":"TODO","published":"2019-09-09"}
|
||||
""" , 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","type":"page"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
|
||||
]
|
@ -10,6 +10,7 @@ const doCliStuff = require("./generate-elm-stuff.js");
|
||||
const { elmPagesUiFile } = require("./elm-file-constants.js");
|
||||
const generateRecords = require("./generate-records.js");
|
||||
const parseFrontmatter = require("./frontmatter.js");
|
||||
const path = require("path");
|
||||
|
||||
const contentGlobPath = "content/**/*.emu";
|
||||
|
||||
@ -82,6 +83,15 @@ function run() {
|
||||
"./gen/Pages.elm",
|
||||
elmPagesUiFile(staticRoutes, markdownContent, content)
|
||||
);
|
||||
ensureDirSync("./gen/Pages");
|
||||
fs.copyFileSync(
|
||||
path.resolve(__dirname, "../../elm-package/src/Pages/ContentCache.elm"),
|
||||
"./gen/Pages/ContentCache.elm"
|
||||
);
|
||||
fs.copyFileSync(
|
||||
path.resolve(__dirname, "../../elm-package/src/Pages/Platform.elm"),
|
||||
"./gen/Pages/Platform.elm"
|
||||
);
|
||||
console.log("elm-pages DONE");
|
||||
doCliStuff(staticRoutes, markdownContent, content, function(payload) {
|
||||
if (contents.watch) {
|
||||
@ -151,3 +161,11 @@ function toRoute(entry) {
|
||||
fullPath.splice(0, 1);
|
||||
return `/${fullPath.join("/")}`;
|
||||
}
|
||||
|
||||
function ensureDirSync(dirpath) {
|
||||
try {
|
||||
fs.mkdirSync(dirpath, { recursive: true });
|
||||
} catch (err) {
|
||||
if (err.code !== "EEXIST") throw err;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ const fs = require("fs");
|
||||
const runElm = require("./compile-elm.js");
|
||||
const copyModifiedElmJson = require("./rewrite-elm-json.js");
|
||||
const { elmPagesCliFile } = require("./elm-file-constants.js");
|
||||
const path = require("path");
|
||||
|
||||
module.exports = function run(
|
||||
staticRoutes,
|
||||
@ -19,9 +20,27 @@ module.exports = function run(
|
||||
elmPagesCliFile(staticRoutes, markdownContent, markupContent)
|
||||
);
|
||||
|
||||
ensureDirSync("./elm-stuff/elm-pages/Pages");
|
||||
fs.copyFileSync(
|
||||
path.resolve(__dirname, "../../elm-package/src/Pages/ContentCache.elm"),
|
||||
"./elm-stuff/elm-pages/Pages/ContentCache.elm"
|
||||
);
|
||||
fs.copyFileSync(
|
||||
path.resolve(__dirname, "../../elm-package/src/Pages/Platform.elm"),
|
||||
"./elm-stuff/elm-pages/Pages/Platform.elm"
|
||||
);
|
||||
|
||||
// write modified elm.json to elm-stuff/elm-pages/
|
||||
copyModifiedElmJson();
|
||||
|
||||
// run Main.elm from elm-stuff/elm-pages with `runElm`
|
||||
runElm(callback);
|
||||
};
|
||||
|
||||
function ensureDirSync(dirpath) {
|
||||
try {
|
||||
fs.mkdirSync(dirpath, { recursive: true });
|
||||
} catch (err) {
|
||||
if (err.code !== "EEXIST") throw err;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user