mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-25 04:43:03 +03:00
Use ImagePath for manifest icons.
This commit is contained in:
parent
173233a6c6
commit
5ad85cad0d
@ -55,7 +55,7 @@ webp =
|
||||
icon :
|
||||
MimeType.MimeImage
|
||||
-> Int
|
||||
-> Manifest.Icon
|
||||
-> Manifest.Icon pathKey
|
||||
icon format width =
|
||||
{ src = cloudinaryIcon format width
|
||||
, sizes = [ ( width, width ) ]
|
||||
@ -67,7 +67,7 @@ icon format width =
|
||||
cloudinaryIcon :
|
||||
MimeType.MimeImage
|
||||
-> Int
|
||||
-> String
|
||||
-> ImagePath pathKey
|
||||
cloudinaryIcon format width =
|
||||
let
|
||||
base =
|
||||
@ -96,11 +96,7 @@ cloudinaryIcon format width =
|
||||
]
|
||||
|> String.join ","
|
||||
in
|
||||
base
|
||||
++ "/"
|
||||
++ transforms
|
||||
++ "/"
|
||||
++ asset
|
||||
ImagePath.external (base ++ "/" ++ transforms ++ "/" ++ asset)
|
||||
|
||||
|
||||
type alias View =
|
||||
@ -127,10 +123,10 @@ main =
|
||||
}
|
||||
|> Pages.Platform.withFileGenerator fileGenerator
|
||||
|> Pages.Platform.withGlobalHeadTags
|
||||
[ Head.icon [ ( 32, 32 ) ] MimeType.Png (cloudinaryIcon MimeType.Png 32 |> ImagePath.external)
|
||||
, Head.icon [ ( 16, 16 ) ] MimeType.Png (cloudinaryIcon MimeType.Png 16 |> ImagePath.external)
|
||||
, Head.appleTouchIcon (Just 180) (cloudinaryIcon MimeType.Png 180 |> ImagePath.external)
|
||||
, Head.appleTouchIcon (Just 192) (cloudinaryIcon MimeType.Png 192 |> ImagePath.external)
|
||||
[ Head.icon [ ( 32, 32 ) ] MimeType.Png (cloudinaryIcon MimeType.Png 32)
|
||||
, Head.icon [ ( 16, 16 ) ] MimeType.Png (cloudinaryIcon MimeType.Png 16)
|
||||
, Head.appleTouchIcon (Just 180) (cloudinaryIcon MimeType.Png 180)
|
||||
, Head.appleTouchIcon (Just 192) (cloudinaryIcon MimeType.Png 192)
|
||||
]
|
||||
|> Pages.Platform.toProgram
|
||||
|
||||
|
@ -202,7 +202,7 @@ perform config cliMsgConstructor toJsPort effect =
|
||||
|
||||
Effect.SendJsData value ->
|
||||
value
|
||||
|> Codec.encoder ToJsPayload.toJsCodec
|
||||
|> Codec.encoder (ToJsPayload.toJsCodec config.canonicalSiteUrl)
|
||||
|> toJsPort
|
||||
|> Cmd.map never
|
||||
|
||||
|
@ -73,8 +73,8 @@ toJsPayload encodedStatic manifest generated allRawResponses allErrors =
|
||||
Errors <| BuildError.errorsToString allErrors
|
||||
|
||||
|
||||
toJsCodec : Codec (ToJsPayload pathKey)
|
||||
toJsCodec =
|
||||
toJsCodec : String -> Codec (ToJsPayload pathKey)
|
||||
toJsCodec canonicalSiteUrl =
|
||||
Codec.custom
|
||||
(\errorsTag success value ->
|
||||
case value of
|
||||
@ -85,7 +85,7 @@ toJsCodec =
|
||||
success (ToJsSuccessPayload pages manifest filesToGenerate staticHttpCache errors)
|
||||
)
|
||||
|> Codec.variant1 "Errors" Errors Codec.string
|
||||
|> Codec.variant1 "Success" Success successCodec
|
||||
|> Codec.variant1 "Success" Success (successCodec canonicalSiteUrl)
|
||||
|> Codec.buildCustom
|
||||
|
||||
|
||||
@ -106,15 +106,15 @@ stubManifest =
|
||||
}
|
||||
|
||||
|
||||
successCodec : Codec (ToJsSuccessPayload pathKey)
|
||||
successCodec =
|
||||
successCodec : String -> Codec (ToJsSuccessPayload pathKey)
|
||||
successCodec canonicalSiteUrl =
|
||||
Codec.object ToJsSuccessPayload
|
||||
|> Codec.field "pages"
|
||||
.pages
|
||||
(Codec.dict (Codec.dict Codec.string))
|
||||
|> Codec.field "manifest"
|
||||
.manifest
|
||||
(Codec.build Manifest.toJson (Decode.succeed stubManifest))
|
||||
(Codec.build (Manifest.toJson canonicalSiteUrl) (Decode.succeed stubManifest))
|
||||
|> Codec.field "filesToGenerate"
|
||||
.filesToGenerate
|
||||
(Codec.build
|
||||
@ -190,13 +190,13 @@ successCodecNew2 canonicalSiteUrl currentPagePath =
|
||||
initialData payload
|
||||
)
|
||||
|> Codec.variant1 "PageProgress" PageProgress (successCodecNew canonicalSiteUrl currentPagePath)
|
||||
|> Codec.variant1 "InitialData" InitialData initialDataCodec
|
||||
|> Codec.variant1 "InitialData" InitialData (initialDataCodec canonicalSiteUrl)
|
||||
|> Codec.buildCustom
|
||||
|
||||
|
||||
manifestCodec : Codec (Manifest.Config pathKey)
|
||||
manifestCodec =
|
||||
Codec.build Manifest.toJson (Decode.succeed stubManifest)
|
||||
manifestCodec : String -> Codec (Manifest.Config pathKey)
|
||||
manifestCodec canonicalSiteUrl =
|
||||
Codec.build (Manifest.toJson canonicalSiteUrl) (Decode.succeed stubManifest)
|
||||
|
||||
|
||||
filesToGenerateCodec : Codec (List { path : List String, content : String })
|
||||
@ -220,13 +220,13 @@ filesToGenerateCodec =
|
||||
)
|
||||
|
||||
|
||||
initialDataCodec : Codec (InitialDataRecord pathKey)
|
||||
initialDataCodec =
|
||||
initialDataCodec : String -> Codec (InitialDataRecord pathKey)
|
||||
initialDataCodec canonicalSiteUrl =
|
||||
Codec.object InitialDataRecord
|
||||
|> Codec.field "filesToGenerate"
|
||||
.filesToGenerate
|
||||
filesToGenerateCodec
|
||||
|> Codec.field "manifest"
|
||||
.manifest
|
||||
manifestCodec
|
||||
(manifestCodec canonicalSiteUrl)
|
||||
|> Codec.buildObject
|
||||
|
@ -166,14 +166,14 @@ type alias Config pathKey =
|
||||
-- https://developer.mozilla.org/en-US/docs/Web/Manifest/short_name
|
||||
, shortName : Maybe String
|
||||
, sourceIcon : ImagePath pathKey
|
||||
, icons : List Icon
|
||||
, icons : List (Icon pathKey)
|
||||
}
|
||||
|
||||
|
||||
{-| <https://developer.mozilla.org/en-US/docs/Web/Manifest/icons>
|
||||
-}
|
||||
type alias Icon =
|
||||
{ src : String -- TODO should this be an ImagePath? If so, I need to fix the bug with external
|
||||
type alias Icon pathKey =
|
||||
{ src : ImagePath pathKey
|
||||
, sizes : List ( Int, Int )
|
||||
, mimeType : Maybe MimeType.MimeImage
|
||||
, purposes : List IconPurpose
|
||||
@ -209,10 +209,10 @@ displayModeToAttribute displayMode =
|
||||
"browser"
|
||||
|
||||
|
||||
encodeIcon : Icon -> Encode.Value
|
||||
encodeIcon icon =
|
||||
encodeIcon : String -> Icon pathKey -> Encode.Value
|
||||
encodeIcon canonicalSiteUrl icon =
|
||||
encodeMaybeObject
|
||||
[ ( "src", icon.src |> Encode.string |> Just )
|
||||
[ ( "src", icon.src |> ImagePath.toAbsoluteUrl canonicalSiteUrl |> Encode.string |> Just )
|
||||
, ( "type", icon.mimeType |> Maybe.map MimeType.Image |> Maybe.map MimeType.toString |> Maybe.map Encode.string )
|
||||
, ( "sizes", icon.sizes |> nonEmptyList |> Maybe.map sizesString |> Maybe.map Encode.string )
|
||||
, ( "purpose", icon.purposes |> nonEmptyList |> Maybe.map purposesString |> Maybe.map Encode.string )
|
||||
@ -258,8 +258,8 @@ nonEmptyList list =
|
||||
{-| Feel free to use this, but in 99% of cases you won't need it. The generated
|
||||
code will run this for you to generate your `manifest.json` file automatically!
|
||||
-}
|
||||
toJson : Config pathKey -> Encode.Value
|
||||
toJson config =
|
||||
toJson : String -> Config pathKey -> Encode.Value
|
||||
toJson canonicalSiteUrl config =
|
||||
[ ( "sourceIcon"
|
||||
, config.sourceIcon
|
||||
|> ImagePath.toString
|
||||
@ -268,7 +268,7 @@ toJson config =
|
||||
)
|
||||
, ( "icons"
|
||||
, config.icons
|
||||
|> Encode.list encodeIcon
|
||||
|> Encode.list (encodeIcon canonicalSiteUrl)
|
||||
|> Just
|
||||
)
|
||||
, ( "background_color"
|
||||
|
@ -176,7 +176,7 @@ startLowLevel generateFiles documentBodyResult staticHttpCache pages =
|
||||
, { extension = "md", frontMatter = "{}", body = Nothing }
|
||||
)
|
||||
]
|
||||
, canonicalSiteUrl = ""
|
||||
, canonicalSiteUrl = canonicalSiteUrl
|
||||
, pathKey = PathKey
|
||||
, onPageChange = Just (\_ -> ())
|
||||
}
|
||||
@ -222,6 +222,10 @@ startLowLevel generateFiles documentBodyResult staticHttpCache pages =
|
||||
|> ProgramTest.start (flags (Encode.encode 0 encodedFlags))
|
||||
|
||||
|
||||
canonicalSiteUrl =
|
||||
""
|
||||
|
||||
|
||||
flags : String -> JD.Value
|
||||
flags jsonString =
|
||||
case JD.decodeString JD.value jsonString of
|
||||
@ -239,7 +243,7 @@ simulateEffects effect =
|
||||
SimulatedEffect.Cmd.none
|
||||
|
||||
Effect.SendJsData value ->
|
||||
SimulatedEffect.Ports.send "toJsPort" (value |> Codec.encoder ToJsPayload.toJsCodec)
|
||||
SimulatedEffect.Ports.send "toJsPort" (value |> Codec.encoder (ToJsPayload.toJsCodec canonicalSiteUrl))
|
||||
|
||||
-- toJsPort value |> Cmd.map never
|
||||
Effect.Batch list ->
|
||||
|
@ -338,7 +338,7 @@ all =
|
||||
"This is a raw text file."
|
||||
|> ProgramTest.expectOutgoingPortValues
|
||||
"toJsPort"
|
||||
(Codec.decoder ToJsPayload.toJsCodec)
|
||||
(Codec.decoder (ToJsPayload.toJsCodec canonicalSiteUrl))
|
||||
(expectErrorsPort
|
||||
"""-- STATIC HTTP DECODING ERROR ----------------------------------------------------- elm-pages
|
||||
|
||||
@ -477,7 +477,7 @@ String was not uppercased"""
|
||||
"""{ "stargazer_count": 86 }"""
|
||||
|> ProgramTest.expectOutgoingPortValues
|
||||
"toJsPort"
|
||||
(Codec.decoder ToJsPayload.toJsCodec)
|
||||
(Codec.decoder (ToJsPayload.toJsCodec canonicalSiteUrl))
|
||||
(expectErrorsPort
|
||||
"""-- STATIC HTTP DECODING ERROR ----------------------------------------------------- elm-pages
|
||||
|
||||
@ -522,7 +522,7 @@ I encountered some errors while decoding this JSON:
|
||||
""" "continuation-url" """
|
||||
|> ProgramTest.expectOutgoingPortValues
|
||||
"toJsPort"
|
||||
(Codec.decoder ToJsPayload.toJsCodec)
|
||||
(Codec.decoder (ToJsPayload.toJsCodec canonicalSiteUrl))
|
||||
(expectErrorsPort
|
||||
"""-- MISSING SECRET ----------------------------------------------------- elm-pages
|
||||
|
||||
@ -551,7 +551,7 @@ So maybe MISSING should be API_KEY"""
|
||||
)
|
||||
|> ProgramTest.expectOutgoingPortValues
|
||||
"toJsPort"
|
||||
(Codec.decoder ToJsPayload.toJsCodec)
|
||||
(Codec.decoder (ToJsPayload.toJsCodec canonicalSiteUrl))
|
||||
(expectErrorsPort """-- STATIC HTTP ERROR ----------------------------------------------------- elm-pages
|
||||
|
||||
I got an error making an HTTP request to this URL: https://api.github.com/repos/dillonkearns/elm-pages
|
||||
@ -855,7 +855,7 @@ startLowLevel generateFiles documentBodyResult staticHttpCache pages =
|
||||
, subscriptions = \_ -> Sub.none
|
||||
, document = document
|
||||
, content = []
|
||||
, canonicalSiteUrl = ""
|
||||
, canonicalSiteUrl = canonicalSiteUrl
|
||||
, pathKey = PathKey
|
||||
, onPageChange = Just (\_ -> ())
|
||||
}
|
||||
@ -918,7 +918,7 @@ simulateEffects effect =
|
||||
SimulatedEffect.Cmd.none
|
||||
|
||||
Effect.SendJsData value ->
|
||||
SimulatedEffect.Ports.send "toJsPort" (value |> Codec.encoder ToJsPayload.toJsCodec)
|
||||
SimulatedEffect.Ports.send "toJsPort" (value |> Codec.encoder (ToJsPayload.toJsCodec canonicalSiteUrl))
|
||||
|
||||
-- toJsPort value |> Cmd.map never
|
||||
Effect.Batch list ->
|
||||
@ -1062,7 +1062,7 @@ expectSuccessNew expectedRequests expectations previous =
|
||||
previous
|
||||
|> ProgramTest.expectOutgoingPortValues
|
||||
"toJsPort"
|
||||
(Codec.decoder ToJsPayload.toJsCodec)
|
||||
(Codec.decoder (ToJsPayload.toJsCodec canonicalSiteUrl))
|
||||
(\value ->
|
||||
case value of
|
||||
(ToJsPayload.Success portPayload) :: rest ->
|
||||
@ -1102,7 +1102,7 @@ expectError expectedErrors previous =
|
||||
previous
|
||||
|> ProgramTest.expectOutgoingPortValues
|
||||
"toJsPort"
|
||||
(Codec.decoder ToJsPayload.toJsCodec)
|
||||
(Codec.decoder (ToJsPayload.toJsCodec canonicalSiteUrl))
|
||||
(\value ->
|
||||
case value of
|
||||
[ ToJsPayload.Success portPayload ] ->
|
||||
@ -1117,6 +1117,10 @@ expectError expectedErrors previous =
|
||||
)
|
||||
|
||||
|
||||
canonicalSiteUrl =
|
||||
""
|
||||
|
||||
|
||||
get : String -> Request.Request
|
||||
get url =
|
||||
{ method = "GET"
|
||||
|
Loading…
Reference in New Issue
Block a user