mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-28 23:12:22 +03:00
Remove unused code.
This commit is contained in:
parent
48ce4ee87c
commit
6bc4c8aab0
@ -4,7 +4,6 @@ import Cloudinary
|
||||
import Date exposing (Date)
|
||||
import Element exposing (Element)
|
||||
import Glob
|
||||
import MarkdownRenderer
|
||||
import OptimizedDecoder
|
||||
import Pages
|
||||
import Pages.ImagePath exposing (ImagePath)
|
||||
|
@ -7,7 +7,7 @@ import Element exposing (Element)
|
||||
import Element.Border
|
||||
import Element.Font
|
||||
import Pages
|
||||
import Pages.ImagePath as ImagePath exposing (ImagePath)
|
||||
import Pages.ImagePath as ImagePath
|
||||
import Pages.PagePath as PagePath exposing (PagePath)
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ view posts =
|
||||
-- Nothing
|
||||
-- )
|
||||
|> List.sortBy
|
||||
(\( path, metadata ) -> -(metadata.published |> Date.toRataDie))
|
||||
(\( _, metadata ) -> -(metadata.published |> Date.toRataDie))
|
||||
|> List.map postSummary
|
||||
)
|
||||
|
||||
|
@ -8,9 +8,8 @@ import Element.Font as Font
|
||||
import Element.Input
|
||||
import Element.Region
|
||||
import Ellie
|
||||
import Html exposing (Attribute, Html)
|
||||
import Html.Attributes exposing (property)
|
||||
import Json.Encode as Encode exposing (Value)
|
||||
import Html
|
||||
import Html.Attributes
|
||||
import Markdown.Block as Block exposing (Block, Inline, ListItem(..), Task(..))
|
||||
import Markdown.Html
|
||||
import Markdown.Parser
|
||||
@ -20,7 +19,7 @@ import Palette
|
||||
import SyntaxHighlight
|
||||
|
||||
|
||||
buildToc : List Block.Block -> TableOfContents
|
||||
buildToc : List Block -> TableOfContents
|
||||
buildToc blocks =
|
||||
let
|
||||
headings =
|
||||
@ -71,7 +70,7 @@ renderer =
|
||||
, emphasis = \content -> Element.paragraph [ Font.italic ] content
|
||||
, codeSpan = code
|
||||
, link =
|
||||
\{ title, destination } body ->
|
||||
\{ destination } body ->
|
||||
Element.newTabLink []
|
||||
{ url = destination
|
||||
, label =
|
||||
@ -86,7 +85,7 @@ renderer =
|
||||
, image =
|
||||
\image ->
|
||||
case image.title of
|
||||
Just title ->
|
||||
Just _ ->
|
||||
Element.image [ Element.width Element.fill ] { src = image.src, description = image.alt }
|
||||
|
||||
Nothing ->
|
||||
@ -143,7 +142,7 @@ renderer =
|
||||
, tableBody = Element.column []
|
||||
, tableRow = Element.row []
|
||||
, tableHeaderCell =
|
||||
\maybeAlignment children ->
|
||||
\_ children ->
|
||||
Element.paragraph [] children
|
||||
, tableCell = Element.paragraph []
|
||||
, html =
|
||||
@ -211,7 +210,7 @@ renderer =
|
||||
children
|
||||
)
|
||||
, Markdown.Html.tag "oembed"
|
||||
(\url children ->
|
||||
(\url _ ->
|
||||
Oembed.view [] Nothing url
|
||||
|> Maybe.map Element.html
|
||||
|> Maybe.withDefault Element.none
|
||||
@ -219,7 +218,7 @@ renderer =
|
||||
)
|
||||
|> Markdown.Html.withAttribute "url"
|
||||
, Markdown.Html.tag "ellie-output"
|
||||
(\ellieId children ->
|
||||
(\ellieId _ ->
|
||||
-- Oembed.view [] Nothing url
|
||||
-- |> Maybe.map Element.html
|
||||
-- |> Maybe.withDefault Element.none
|
||||
@ -307,11 +306,3 @@ codeBlock details =
|
||||
(Html.pre [] [ Html.code [] [ Html.text details.body ] ])
|
||||
|> Element.html
|
||||
|> Element.el [ Element.width Element.fill ]
|
||||
|
||||
|
||||
editorValue : String -> Attribute msg
|
||||
editorValue value =
|
||||
value
|
||||
|> String.trim
|
||||
|> Encode.string
|
||||
|> property "editorValue"
|
||||
|
@ -1,15 +1,9 @@
|
||||
module Metadata exposing (ArticleMetadata, DocMetadata, Metadata(..), PageMetadata, decoder)
|
||||
module Metadata exposing (ArticleMetadata, DocMetadata, Metadata(..), PageMetadata)
|
||||
|
||||
import Cloudinary
|
||||
import Data.Author
|
||||
import Date exposing (Date)
|
||||
import Dict exposing (Dict)
|
||||
import Element exposing (Element)
|
||||
import Element.Font as Font
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import List.Extra
|
||||
import Pages
|
||||
import Pages.ImagePath as ImagePath exposing (ImagePath)
|
||||
import Pages.ImagePath exposing (ImagePath)
|
||||
|
||||
|
||||
type Metadata
|
||||
@ -37,65 +31,3 @@ type alias DocMetadata =
|
||||
|
||||
type alias PageMetadata =
|
||||
{ title : String }
|
||||
|
||||
|
||||
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" ->
|
||||
Decode.succeed Showcase
|
||||
|
||||
"blog" ->
|
||||
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 Article
|
||||
|
||||
_ ->
|
||||
Decode.fail <| "Unexpected page \"type\" " ++ pageType
|
||||
)
|
||||
|
||||
|
||||
imageDecoder : Decoder (ImagePath Pages.PathKey)
|
||||
imageDecoder =
|
||||
Decode.string
|
||||
|> Decode.map (\cloudinaryAsset -> Cloudinary.url cloudinaryAsset Nothing 800)
|
||||
|
||||
|
||||
findMatchingImage : String -> Maybe (ImagePath Pages.PathKey)
|
||||
findMatchingImage imageAssetPath =
|
||||
List.Extra.find
|
||||
(\image -> ImagePath.toString image == imageAssetPath)
|
||||
Pages.allImages
|
||||
|
@ -1,7 +1,6 @@
|
||||
module RssPlugin exposing (generate)
|
||||
|
||||
import Head
|
||||
import NoMetadata exposing (NoMetadata)
|
||||
import Pages.PagePath as PagePath exposing (PagePath)
|
||||
import Pages.Platform exposing (Builder)
|
||||
import Pages.StaticHttp as StaticHttp
|
||||
|
@ -10,8 +10,7 @@ import Element.Region
|
||||
import FontAwesome
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as Attr
|
||||
import MarkdownRenderer
|
||||
import NoMetadata exposing (NoMetadata(..), NoView)
|
||||
import NoMetadata exposing (NoMetadata)
|
||||
import OptimizedDecoder as D
|
||||
import Pages exposing (pages)
|
||||
import Pages.Directory as Directory exposing (Directory)
|
||||
@ -127,7 +126,7 @@ init maybePagePath =
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
OnPageChange page ->
|
||||
OnPageChange _ ->
|
||||
( { model | showMobileMenu = False }, Cmd.none )
|
||||
|
||||
ToggleMobileMenu ->
|
||||
@ -200,11 +199,6 @@ view stars page model toMsg pageView =
|
||||
}
|
||||
|
||||
|
||||
incrementView : Model -> Element Msg
|
||||
incrementView model =
|
||||
Element.el [ Element.Events.onClick Increment ] (Element.text <| "Shared count: " ++ String.fromInt model.counter)
|
||||
|
||||
|
||||
logoLinkMobile =
|
||||
Element.link []
|
||||
{ url = "/"
|
||||
|
@ -8,7 +8,6 @@ import OptimizedDecoder as Decode
|
||||
import Pages.Secrets as Secrets
|
||||
import Pages.StaticHttp as StaticHttp
|
||||
import Palette
|
||||
import Url.Builder
|
||||
|
||||
|
||||
view : List Entry -> Element.Element msg
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Site exposing (canonicalUrl, config, tagline)
|
||||
module Site exposing (config)
|
||||
|
||||
import Cloudinary
|
||||
import Color
|
||||
@ -8,7 +8,6 @@ import Pages exposing (images, pages)
|
||||
import Pages.ImagePath exposing (ImagePath)
|
||||
import Pages.Manifest as Manifest
|
||||
import Pages.Manifest.Category
|
||||
import Pages.PagePath exposing (PagePath)
|
||||
import Pages.SiteConfig exposing (SiteConfig)
|
||||
import Pages.StaticFile as StaticFile
|
||||
import Pages.StaticHttp as StaticHttp
|
||||
@ -117,8 +116,3 @@ cloudinaryIcon :
|
||||
-> ImagePath pathKey
|
||||
cloudinaryIcon mimeType width =
|
||||
Cloudinary.urlSquare "v1603234028/elm-pages/elm-pages-icon" (Just mimeType) width
|
||||
|
||||
|
||||
socialIcon : ImagePath pathKey
|
||||
socialIcon =
|
||||
Cloudinary.urlSquare "v1603234028/elm-pages/elm-pages-icon" Nothing 250
|
||||
|
@ -1,31 +1,4 @@
|
||||
module SiteOld exposing (canonicalUrl, config, tagline)
|
||||
|
||||
import Cloudinary
|
||||
import Color
|
||||
import MimeType
|
||||
import Pages exposing (images, pages)
|
||||
import Pages.ImagePath exposing (ImagePath)
|
||||
import Pages.Manifest as Manifest
|
||||
import Pages.Manifest.Category
|
||||
import Pages.PagePath exposing (PagePath)
|
||||
import Pages.StaticHttp as StaticHttp
|
||||
|
||||
|
||||
type alias SiteConfig =
|
||||
{ canonicalUrl : String
|
||||
, manifest : Manifest.Config Pages.PathKey
|
||||
}
|
||||
|
||||
|
||||
config : SiteConfig
|
||||
config =
|
||||
{ canonicalUrl = canonicalUrl
|
||||
, manifest = manifest
|
||||
}
|
||||
|
||||
|
||||
type alias StaticData =
|
||||
()
|
||||
module SiteOld exposing (canonicalUrl, tagline)
|
||||
|
||||
|
||||
canonicalUrl : String
|
||||
@ -33,58 +6,6 @@ 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
|
||||
, icons =
|
||||
[ icon webp 192
|
||||
, icon webp 512
|
||||
, icon MimeType.Png 192
|
||||
, icon MimeType.Png 512
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
tagline : String
|
||||
tagline =
|
||||
"A statically typed site generator - elm-pages"
|
||||
|
||||
|
||||
webp : MimeType.MimeImage
|
||||
webp =
|
||||
MimeType.OtherImage "webp"
|
||||
|
||||
|
||||
icon :
|
||||
MimeType.MimeImage
|
||||
-> Int
|
||||
-> Manifest.Icon pathKey
|
||||
icon format width =
|
||||
{ src = cloudinaryIcon format width
|
||||
, sizes = [ ( width, width ) ]
|
||||
, mimeType = format |> Just
|
||||
, purposes = [ Manifest.IconPurposeAny, Manifest.IconPurposeMaskable ]
|
||||
}
|
||||
|
||||
|
||||
cloudinaryIcon :
|
||||
MimeType.MimeImage
|
||||
-> Int
|
||||
-> ImagePath pathKey
|
||||
cloudinaryIcon mimeType width =
|
||||
Cloudinary.urlSquare "v1603234028/elm-pages/elm-pages-icon" (Just mimeType) width
|
||||
|
||||
|
||||
socialIcon : ImagePath pathKey
|
||||
socialIcon =
|
||||
Cloudinary.urlSquare "v1603234028/elm-pages/elm-pages-icon" Nothing 250
|
||||
|
@ -1,20 +1,14 @@
|
||||
module Template.Blog exposing (Model, Msg, template)
|
||||
|
||||
import Article
|
||||
import Cloudinary
|
||||
import Date exposing (Date)
|
||||
import Element exposing (Element)
|
||||
import Element
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
import Index
|
||||
import OptimizedDecoder
|
||||
import Pages exposing (images)
|
||||
import Pages.ImagePath exposing (ImagePath)
|
||||
import Pages.PagePath as PagePath exposing (PagePath)
|
||||
import Pages.StaticFile as StaticFile
|
||||
import Pages.PagePath exposing (PagePath)
|
||||
import Pages.StaticHttp as StaticHttp
|
||||
import Shared
|
||||
import Showcase
|
||||
import SiteOld
|
||||
import Template exposing (StaticPayload, TemplateWithState)
|
||||
|
||||
@ -127,43 +121,3 @@ head staticPayload =
|
||||
-- )
|
||||
-- (StaticFile.frontmatter frontmatterDecoder)
|
||||
-- )
|
||||
|
||||
|
||||
type alias ArticleMetadata =
|
||||
{ title : String
|
||||
, description : String
|
||||
, published : Date
|
||||
, image : ImagePath Pages.PathKey
|
||||
, draft : Bool
|
||||
}
|
||||
|
||||
|
||||
frontmatterDecoder : OptimizedDecoder.Decoder ArticleMetadata
|
||||
frontmatterDecoder =
|
||||
OptimizedDecoder.map5 ArticleMetadata
|
||||
(OptimizedDecoder.field "title" OptimizedDecoder.string)
|
||||
(OptimizedDecoder.field "description" OptimizedDecoder.string)
|
||||
(OptimizedDecoder.field "published"
|
||||
(OptimizedDecoder.string
|
||||
|> OptimizedDecoder.andThen
|
||||
(\isoString ->
|
||||
case Date.fromIsoString isoString of
|
||||
Ok date ->
|
||||
OptimizedDecoder.succeed date
|
||||
|
||||
Err error ->
|
||||
OptimizedDecoder.fail error
|
||||
)
|
||||
)
|
||||
)
|
||||
(OptimizedDecoder.field "image" imageDecoder)
|
||||
(OptimizedDecoder.field "draft" OptimizedDecoder.bool
|
||||
|> OptimizedDecoder.maybe
|
||||
|> OptimizedDecoder.map (Maybe.withDefault False)
|
||||
)
|
||||
|
||||
|
||||
imageDecoder : OptimizedDecoder.Decoder (ImagePath Pages.PathKey)
|
||||
imageDecoder =
|
||||
OptimizedDecoder.string
|
||||
|> OptimizedDecoder.map (\cloudinaryAsset -> Cloudinary.url cloudinaryAsset Nothing 800)
|
||||
|
@ -68,11 +68,6 @@ template =
|
||||
|> Template.buildNoState { view = view }
|
||||
|
||||
|
||||
findMatchingImage : String -> Maybe (ImagePath Pages.PathKey)
|
||||
findMatchingImage imageAssetPath =
|
||||
List.Extra.find (\image -> ImagePath.toString image == imageAssetPath) Pages.allImages
|
||||
|
||||
|
||||
view :
|
||||
StaticPayload DataFromFile Route
|
||||
-> Shared.PageView msg
|
||||
@ -164,7 +159,7 @@ head { path, static } =
|
||||
)
|
||||
|
||||
|
||||
publishedDateView : { a | published : Date.Date } -> Element msg
|
||||
publishedDateView : { a | published : Date } -> Element msg
|
||||
publishedDateView metadata =
|
||||
Element.text
|
||||
(metadata.published
|
||||
|
@ -1,15 +1,13 @@
|
||||
module Template.Hello.Name_ exposing (Model, Msg, template)
|
||||
|
||||
import Element exposing (Element)
|
||||
import Element.Region
|
||||
import Element
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
import Pages exposing (images)
|
||||
import Pages.PagePath exposing (PagePath)
|
||||
import Pages.StaticHttp as StaticHttp
|
||||
import Shared
|
||||
import SiteOld
|
||||
import Template exposing (StaticPayload, Template, TemplateWithState)
|
||||
import Template exposing (StaticPayload, Template)
|
||||
|
||||
|
||||
type alias Model =
|
||||
|
@ -1,15 +1,14 @@
|
||||
module Template.Page exposing (Model, Msg, template)
|
||||
|
||||
import Element exposing (Element)
|
||||
import Element
|
||||
import Element.Region
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
import Pages exposing (images)
|
||||
import Pages.PagePath exposing (PagePath)
|
||||
import Pages.StaticHttp as StaticHttp
|
||||
import Shared
|
||||
import SiteOld
|
||||
import Template exposing (StaticPayload, Template, TemplateWithState)
|
||||
import Template exposing (StaticPayload, Template)
|
||||
|
||||
|
||||
type alias Model =
|
||||
|
@ -3,10 +3,7 @@ module Template.Showcase exposing (Model, Msg, template)
|
||||
import Element exposing (Element)
|
||||
import Head
|
||||
import Head.Seo as Seo
|
||||
import MarkdownRenderer
|
||||
import OptimizedDecoder
|
||||
import Pages exposing (images)
|
||||
import Pages.StaticFile as StaticFile
|
||||
import Pages.StaticHttp as StaticHttp
|
||||
import Shared
|
||||
import Showcase
|
||||
@ -47,26 +44,6 @@ type alias DataFromFile =
|
||||
{ body : List (Element Msg), title : String }
|
||||
|
||||
|
||||
fileRequest : StaticHttp.Request DataFromFile
|
||||
fileRequest =
|
||||
StaticFile.request
|
||||
"content/blog/static-http.md"
|
||||
(OptimizedDecoder.map2 DataFromFile
|
||||
(StaticFile.body
|
||||
|> OptimizedDecoder.andThen
|
||||
(\rawBody ->
|
||||
case rawBody |> MarkdownRenderer.view |> Result.map Tuple.second of
|
||||
Ok renderedBody ->
|
||||
OptimizedDecoder.succeed renderedBody
|
||||
|
||||
Err error ->
|
||||
OptimizedDecoder.fail error
|
||||
)
|
||||
)
|
||||
(StaticFile.frontmatter (OptimizedDecoder.field "title" OptimizedDecoder.string))
|
||||
)
|
||||
|
||||
|
||||
type alias StaticData =
|
||||
List Showcase.Entry
|
||||
|
||||
|
@ -80,9 +80,9 @@ type PathKey
|
||||
= PathKey
|
||||
|
||||
|
||||
buildImage : List String -> ImagePath.Dimensions -> ImagePath PathKey
|
||||
buildImage path dimensions =
|
||||
ImagePath.build PathKey ("images" :: path) dimensions
|
||||
buildImage : List String -> ImagePath PathKey
|
||||
buildImage path =
|
||||
ImagePath.build PathKey ("images" :: path)
|
||||
|
||||
|
||||
buildPage : List String -> PagePath PathKey
|
||||
@ -157,9 +157,9 @@ type PathKey
|
||||
= PathKey
|
||||
|
||||
|
||||
buildImage : List String -> ImagePath.Dimensions -> ImagePath PathKey
|
||||
buildImage path dimensions =
|
||||
ImagePath.build PathKey ("images" :: path) dimensions
|
||||
buildImage : List String -> ImagePath PathKey
|
||||
buildImage path =
|
||||
ImagePath.build PathKey ("images" :: path)
|
||||
|
||||
|
||||
buildPage : List String -> PagePath PathKey
|
||||
|
@ -6,7 +6,7 @@ const sharp = require("sharp");
|
||||
const parseFrontmatter = require("./frontmatter.js");
|
||||
|
||||
// Because we use node-glob, we must use `/` as a separator on all platforms. See https://github.com/isaacs/node-glob#windows
|
||||
const PATH_SEPARATOR = '/';
|
||||
const PATH_SEPARATOR = "/";
|
||||
|
||||
module.exports = async function wrapper() {
|
||||
return generate(scan());
|
||||
@ -16,13 +16,13 @@ function scan() {
|
||||
// scan content directory for documents
|
||||
const content = glob
|
||||
.sync(dir + "**/*", {})
|
||||
.filter(filePath => !fs.lstatSync(filePath).isDirectory())
|
||||
.filter((filePath) => !fs.lstatSync(filePath).isDirectory())
|
||||
.map(unpackFile());
|
||||
return content;
|
||||
}
|
||||
|
||||
function unpackFile() {
|
||||
return filepath => {
|
||||
return (filepath) => {
|
||||
const fullPath = filepath;
|
||||
|
||||
var relative = filepath.slice(dir.length);
|
||||
@ -35,7 +35,7 @@ function unpackFile() {
|
||||
const metadata = {
|
||||
path: relative,
|
||||
metadata: JSON.stringify(foundMetadata.data),
|
||||
document: true
|
||||
document: true,
|
||||
};
|
||||
return metadata;
|
||||
};
|
||||
@ -72,7 +72,9 @@ async function generate(scanned) {
|
||||
for (var i = 0; i < scanned.length; i++) {
|
||||
var pathFragments = scanned[i].path;
|
||||
//remove extesion and split into fragments
|
||||
pathFragments = pathFragments.replace(/\.[^/.]+$/, "").split(PATH_SEPARATOR);
|
||||
pathFragments = pathFragments
|
||||
.replace(/\.[^/.]+$/, "")
|
||||
.split(PATH_SEPARATOR);
|
||||
const is404 = pathFragments.length == 1 && pathFragments[0] == "404";
|
||||
const ext = path.extname(scanned[i].path);
|
||||
|
||||
@ -80,8 +82,8 @@ async function generate(scanned) {
|
||||
const elmType =
|
||||
"(buildPage [ " +
|
||||
pathFragments
|
||||
.filter(fragment => fragment !== "index")
|
||||
.map(fragment => `"${fragment}"`)
|
||||
.filter((fragment) => fragment !== "index")
|
||||
.map((fragment) => `"${fragment}"`)
|
||||
.join(", ") +
|
||||
" ])";
|
||||
if (!is404) {
|
||||
@ -100,34 +102,37 @@ async function generate(scanned) {
|
||||
// routeToDocExtension: formatCaseStatement("toExt", routeToExt),
|
||||
// routeToSource: formatCaseStatement("toSourcePath", routeToSource),
|
||||
imageAssetsRecord: toElmRecord("images", await getImageAssets(), true),
|
||||
allImages: await allImageAssetNames()
|
||||
allImages: await allImageAssetNames(),
|
||||
};
|
||||
}
|
||||
function listImageAssets() {
|
||||
return glob
|
||||
.sync("images/**/*", {})
|
||||
.filter(filePath => !fs.lstatSync(filePath).isDirectory())
|
||||
.filter((filePath) => !fs.lstatSync(filePath).isDirectory())
|
||||
.map(relativeImagePath);
|
||||
}
|
||||
async function getImageAssets() {
|
||||
var assetsRecord = {};
|
||||
await Promise.all(listImageAssets().map(async info => {
|
||||
captureRouteRecord(info.pathFragments, await elmType(info), assetsRecord);
|
||||
}));
|
||||
await Promise.all(
|
||||
listImageAssets().map(async (info) => {
|
||||
captureRouteRecord(info.pathFragments, await elmType(info), assetsRecord);
|
||||
})
|
||||
);
|
||||
|
||||
return assetsRecord;
|
||||
}
|
||||
function allImageAssetNames() {
|
||||
return Promise.all(listImageAssets().map(async info => {
|
||||
return elmType(info);
|
||||
}));
|
||||
return Promise.all(
|
||||
listImageAssets().map(async (info) => {
|
||||
return elmType(info);
|
||||
})
|
||||
);
|
||||
}
|
||||
async function elmType(info) {
|
||||
const pathFragments = info.fragmentsWithExtension
|
||||
.map(fragment => `"${fragment}"`)
|
||||
.map((fragment) => `"${fragment}"`)
|
||||
.join(", ");
|
||||
const metadata = await sharp(`images/${info.path}`).metadata();
|
||||
return `(buildImage [ ${pathFragments} ] { width = ${metadata.width}, height = ${metadata.height} })`
|
||||
return `(buildImage [ ${pathFragments} ])`;
|
||||
}
|
||||
function toPascalCase(str) {
|
||||
var pascal = str.replace(/(\-\w)/g, function (m) {
|
||||
@ -174,15 +179,15 @@ function formatRecord(directoryPath, rec, asType, level) {
|
||||
} else {
|
||||
keyVals.push(
|
||||
key +
|
||||
" =\n" +
|
||||
formatRecord(directoryPath.concat(key), val, asType, level + 1)
|
||||
" =\n" +
|
||||
formatRecord(directoryPath.concat(key), val, asType, level + 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
keyVals.push(
|
||||
`directory = ${
|
||||
keys.includes("index") ? "directoryWithIndex" : "directoryWithoutIndex"
|
||||
} [${directoryPath.map(pathFragment => `"${pathFragment}"`).join(", ")}]`
|
||||
keys.includes("index") ? "directoryWithIndex" : "directoryWithoutIndex"
|
||||
} [${directoryPath.map((pathFragment) => `"${pathFragment}"`).join(", ")}]`
|
||||
);
|
||||
const indentationDelimiter = `\n${indentation}, `;
|
||||
return `${indentation}{ ${keyVals.join(indentationDelimiter)}
|
||||
@ -235,7 +240,7 @@ ${branches.join("\n\n")}`;
|
||||
}
|
||||
|
||||
function formatAsElmUrlToString(pieces) {
|
||||
var toString = pieces.map(p => p.toString).join("\n\n");
|
||||
var toString = pieces.map((p) => p.toString).join("\n\n");
|
||||
|
||||
return `routeToString : Route -> String
|
||||
routeToString route =
|
||||
|
Loading…
Reference in New Issue
Block a user