mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2025-01-01 16:36:19 +03:00
Fix head tag renderer.
This commit is contained in:
parent
7964f90191
commit
dc6c9e9692
@ -23,12 +23,10 @@ function toString(/** @type { SeoTag[] } */ tags) {
|
||||
// tags.concat([generatorTag]);
|
||||
|
||||
return tags
|
||||
.map((rawValue) => {
|
||||
const type = rawValue.tag;
|
||||
const headTag = rawValue.args[0];
|
||||
if (type === "Tag") {
|
||||
.map((headTag) => {
|
||||
if (headTag.type === "head") {
|
||||
return appendTag(headTag);
|
||||
} else if (headTag.type === "StructuredData") {
|
||||
} else if (headTag.type === "json-ld") {
|
||||
return appendJsonLdTag(headTag);
|
||||
} else {
|
||||
throw new Error(`Unknown tag type ${JSON.stringify(headTag)}`);
|
||||
|
64
src/Head.elm
64
src/Head.elm
@ -5,7 +5,6 @@ module Head exposing
|
||||
, AttributeValue
|
||||
, currentPageFullUrl, fullImageUrl, fullPageUrl, raw
|
||||
, toJson, canonicalLink
|
||||
, codec
|
||||
)
|
||||
|
||||
{-| This module contains low-level functions for building up
|
||||
@ -315,69 +314,6 @@ toJson canonicalSiteUrl currentPagePath tag =
|
||||
]
|
||||
|
||||
|
||||
codec : Codec (Tag pathKey)
|
||||
codec =
|
||||
Codec.custom
|
||||
(\fTag fStructuredData v ->
|
||||
case v of
|
||||
Tag err ->
|
||||
fTag err
|
||||
|
||||
StructuredData ok ->
|
||||
fStructuredData ok
|
||||
)
|
||||
|> Codec.variant1 "Tag" Tag tagCodec
|
||||
|> Codec.variant1 "StructuredData" StructuredData codecStructuredData
|
||||
|> Codec.buildCustom
|
||||
|
||||
|
||||
tagCodec : Codec (Details pathKey)
|
||||
tagCodec =
|
||||
--Debug.todo ""
|
||||
Codec.object Details
|
||||
|> Codec.field "name" .name Codec.string
|
||||
|> Codec.field "attributes" .attributes (Codec.list (Codec.tuple Codec.string attributeCodec))
|
||||
|> Codec.buildObject
|
||||
|
||||
|
||||
|
||||
--{ name : String
|
||||
--, attributes : List ( String, AttributeValue pathKey )
|
||||
--}
|
||||
|
||||
|
||||
attributeCodec : Codec (AttributeValue pathKey)
|
||||
attributeCodec =
|
||||
Codec.custom
|
||||
(\fRaw fFull fCurrent v ->
|
||||
case v of
|
||||
Raw string ->
|
||||
fRaw string
|
||||
|
||||
FullUrl string ->
|
||||
fFull string
|
||||
|
||||
FullUrlToCurrentPage ->
|
||||
fCurrent
|
||||
)
|
||||
|> Codec.variant1 "Raw" Raw Codec.string
|
||||
|> Codec.variant1 "FullUrl" FullUrl Codec.string
|
||||
|> Codec.variant0 "FullUrlToCurrentPage" FullUrlToCurrentPage
|
||||
|> Codec.buildCustom
|
||||
|
||||
|
||||
|
||||
--type AttributeValue pathKey
|
||||
-- = Raw String
|
||||
-- | FullUrl String
|
||||
-- | FullUrlToCurrentPage
|
||||
|
||||
|
||||
codecStructuredData : Codec Json.Encode.Value
|
||||
codecStructuredData =
|
||||
Codec.value
|
||||
|
||||
|
||||
encodeProperty : String -> String -> ( String, AttributeValue pathKey ) -> Json.Encode.Value
|
||||
encodeProperty canonicalSiteUrl currentPagePath ( name, value ) =
|
||||
case value of
|
||||
|
@ -252,9 +252,18 @@ perform config cliMsgConstructor toJsPort effect =
|
||||
]
|
||||
|
||||
Effect.SendSinglePage info ->
|
||||
let
|
||||
currentPagePath =
|
||||
case info of
|
||||
ToJsPayload.PageProgress toJsSuccessPayloadNew ->
|
||||
toJsSuccessPayloadNew.route
|
||||
|
||||
_ ->
|
||||
""
|
||||
in
|
||||
Cmd.batch
|
||||
[ info
|
||||
|> Codec.encoder ToJsPayload.successCodecNew2
|
||||
|> Codec.encoder (ToJsPayload.successCodecNew2 config.canonicalSiteUrl currentPagePath)
|
||||
|> toJsPort
|
||||
|> Cmd.map never
|
||||
, Task.succeed ()
|
||||
|
@ -140,8 +140,8 @@ successCodec =
|
||||
|> Codec.buildObject
|
||||
|
||||
|
||||
successCodecNew : Codec (ToJsSuccessPayloadNew pathKey)
|
||||
successCodecNew =
|
||||
successCodecNew : String -> String -> Codec (ToJsSuccessPayloadNew pathKey)
|
||||
successCodecNew canonicalSiteUrl currentPagePath =
|
||||
Codec.object ToJsSuccessPayloadNew
|
||||
|> Codec.field "route"
|
||||
.route
|
||||
@ -153,11 +153,17 @@ successCodecNew =
|
||||
.contentJson
|
||||
(Codec.dict Codec.string)
|
||||
|> Codec.field "errors" .errors (Codec.list Codec.string)
|
||||
|> Codec.field "head" .head (Codec.list Head.codec)
|
||||
|> Codec.field "head" .head (Codec.list (headCodec canonicalSiteUrl currentPagePath))
|
||||
|> Codec.field "body" .body Codec.string
|
||||
|> Codec.buildObject
|
||||
|
||||
|
||||
headCodec : String -> String -> Codec (Head.Tag pathKey)
|
||||
headCodec canonicalSiteUrl currentPagePath =
|
||||
Codec.build (Head.toJson canonicalSiteUrl currentPagePath)
|
||||
(Decode.succeed (Head.canonicalLink Nothing))
|
||||
|
||||
|
||||
type ToJsSuccessPayloadNewCombined pathKey
|
||||
= PageProgress (ToJsSuccessPayloadNew pathKey)
|
||||
| InitialData (InitialDataRecord pathKey)
|
||||
@ -169,8 +175,8 @@ type alias InitialDataRecord pathKey =
|
||||
}
|
||||
|
||||
|
||||
successCodecNew2 : Codec (ToJsSuccessPayloadNewCombined pathKey)
|
||||
successCodecNew2 =
|
||||
successCodecNew2 : String -> String -> Codec (ToJsSuccessPayloadNewCombined pathKey)
|
||||
successCodecNew2 canonicalSiteUrl currentPagePath =
|
||||
Codec.custom
|
||||
(\success initialData value ->
|
||||
case value of
|
||||
@ -180,7 +186,7 @@ successCodecNew2 =
|
||||
InitialData payload ->
|
||||
initialData payload
|
||||
)
|
||||
|> Codec.variant1 "PageProgress" PageProgress successCodecNew
|
||||
|> Codec.variant1 "PageProgress" PageProgress (successCodecNew canonicalSiteUrl currentPagePath)
|
||||
|> Codec.variant1 "InitialData" InitialData initialDataCodec
|
||||
|> Codec.buildCustom
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user