Change type of image urls in meta tag helpers to be Pages.Path.

This commit is contained in:
Dillon Kearns 2019-09-07 11:03:43 +05:30
parent 073ec3a4c6
commit 17b03bdcde
3 changed files with 49 additions and 41 deletions

View File

@ -15,6 +15,7 @@ module Head.OpenGraph exposing
import Head
import Head.SocialMeta as Twitter
import Pages.Path
{-| Will be displayed as a large card in twitter
@ -29,12 +30,12 @@ If you want one of those, use `audioPlayer` or `videoPlayer`
summaryLarge :
{ url : String
, siteName : String
, image : Image
, image : Image pathKey
, description : String
, title : String
, locale : Maybe Locale
}
-> Common
-> Common pathKey
summaryLarge config =
buildSummary config Twitter.Large
@ -51,12 +52,12 @@ See: <https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/
summary :
{ url : String
, siteName : String
, image : Image
, image : Image pathKey
, description : String
, title : String
, locale : Maybe Locale
}
-> Common
-> Common pathKey
summary config =
buildSummary config Twitter.Regular
@ -71,13 +72,13 @@ The options will also be used to build up the appropriate OpenGraph `<meta>` tag
audioPlayer :
{ url : String
, siteName : String
, image : Image
, image : Image pathKey
, description : String
, title : String
, audio : Audio
, locale : Maybe Locale
}
-> Common
-> Common pathKey
audioPlayer { title, image, url, description, siteName, audio, locale } =
{ title = title
, image = image
@ -114,13 +115,13 @@ The options will also be used to build up the appropriate OpenGraph `<meta>` tag
videoPlayer :
{ url : String
, siteName : String
, image : Image
, image : Image pathKey
, description : String
, title : String
, video : Video
, locale : Maybe Locale
}
-> Common
-> Common pathKey
videoPlayer { title, image, url, description, siteName, video, locale } =
{ title = title
, image = image
@ -150,13 +151,13 @@ videoPlayer { title, image, url, description, siteName, video, locale } =
buildSummary :
{ url : String
, siteName : String
, image : Image
, image : Image pathKey
, description : String
, title : String
, locale : Maybe Locale
}
-> Twitter.SummarySize
-> Common
-> Common pathKey
buildSummary { title, image, url, description, siteName, locale } summarySize =
{ title = title
, image = image
@ -185,7 +186,7 @@ buildSummary { title, image, url, description, siteName, locale } summarySize =
{-| <https://ogp.me/#type_website>
-}
website :
Common
Common pathKey
-> List (Head.Tag pathKey)
website common =
Website |> Content common |> tags
@ -200,7 +201,7 @@ article :
, modifiedTime : Maybe Iso8601DateTime
, expirationTime : Maybe Iso8601DateTime
}
-> Common
-> Common pathKey
-> List (Head.Tag pathKey)
article details common =
Article details |> Content common |> tags
@ -209,7 +210,7 @@ article details common =
{-| See <https://ogp.me/#type_book>
-}
book :
Common
Common pathKey
->
{ tags : List String
, isbn : Maybe String
@ -221,7 +222,7 @@ book common details =
song :
Common
Common pathKey
->
{ duration : Maybe Int
, album : Maybe Int
@ -241,9 +242,9 @@ Skipping this for now, if there's a use case I can add it in:
- og:determiner - The word that appears before this object's title in a sentence. An enum of (a, an, the, "", auto). If auto is chosen, the consumer of your data should chose between "a" or "an". Default is "" (blank).
-}
type alias Common =
type alias Common pathKey =
{ title : String
, image : Image
, image : Image pathKey
, url : String
, description : String
, siteName : String
@ -251,7 +252,7 @@ type alias Common =
, video : Maybe Video
, locale : Maybe Locale
, alternateLocales : List Locale
, twitterCard : Twitter.TwitterCard
, twitterCard : Twitter.TwitterCard pathKey
}
@ -301,8 +302,8 @@ type alias Locale =
String
type Content
= Content Common ContentDetails
type Content pathKey
= Content (Common pathKey) ContentDetails
type ContentDetails
@ -349,18 +350,18 @@ type alias MimeType =
{-| See <https://ogp.me/#structured>
-}
type alias Image =
{ url : String
type alias Image pathKey =
{ url : Pages.Path.Path pathKey Pages.Path.ToImage
, alt : String
, dimensions : Maybe { width : Int, height : Int }
, mimeType : Maybe MimeType
}
tagsForImage : Image -> List ( String, Maybe String )
tagsForImage : Image pathKey -> List ( String, Maybe String )
tagsForImage image =
[ ( "og:image", Just image.url )
, ( "og:image:secure_url", Just image.url )
[ ( "og:image", Just (Pages.Path.toString image.url) )
, ( "og:image:secure_url", Just (Pages.Path.toString image.url) )
, ( "og:image:alt", Just image.alt )
, ( "og:image:width", image.dimensions |> Maybe.map .width |> Maybe.map String.fromInt )
, ( "og:image:height", image.dimensions |> Maybe.map .height |> Maybe.map String.fromInt )
@ -385,7 +386,7 @@ tagsForVideo video =
]
tags : Content -> List (Head.Tag pathKey)
tags : Content pathKey -> List (Head.Tag pathKey)
tags (Content common details) =
tagsForCommon common
++ (case details of

View File

@ -1,6 +1,7 @@
module Head.SocialMeta exposing (SummarySize(..), TwitterCard(..), rawTags, summaryLarge, summaryRegular)
import Head
import Pages.Path
{-| <https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/summary>
@ -35,7 +36,7 @@ app :
{ title : String
, description : Maybe String
, siteUser : String
, image : Maybe { url : String, alt : String }
, image : Maybe (Image pathKey)
, appIdIphone : Maybe Int
, appIdIpad : Maybe Int
, appIdGooglePlay : Maybe String
@ -67,19 +68,25 @@ type SummarySize
| Large
type TwitterCard
type alias Image pathKey =
{ url : Pages.Path.Path pathKey Pages.Path.ToImage
, alt : String
}
type TwitterCard pathKey
= Summary
{ title : String
, description : Maybe String
, siteUser : Maybe String
, image : Maybe { url : String, alt : String }
, image : Maybe (Image pathKey)
, size : SummarySize
}
| App
{ title : String
, description : Maybe String
, siteUser : String
, image : Maybe { url : String, alt : String }
, image : Maybe (Image pathKey)
, appIdIphone : Maybe Int
, appIdIpad : Maybe Int
, appIdGooglePlay : Maybe String
@ -96,14 +103,14 @@ type TwitterCard
{ title : String
, description : Maybe String
, siteUser : String
, image : { url : String, alt : String }
, image : Image pathKey
, player : String
, width : Int
, height : Int
}
rawTags : TwitterCard -> List ( String, Maybe String )
rawTags : TwitterCard pathKey -> List ( String, Maybe String )
rawTags card =
( "twitter:card", cardValue card |> Just )
:: (case card of
@ -111,7 +118,7 @@ rawTags card =
[ ( "twitter:title", Just details.title )
, ( "twitter:site", details.siteUser )
, ( "twitter:description", details.description )
, ( "twitter:image", details.image |> Maybe.map .url )
, ( "twitter:image", details.image |> Maybe.map .url |> Maybe.map Pages.Path.toString )
, ( "twitter:image:alt", details.image |> Maybe.map .alt )
]
@ -119,7 +126,7 @@ rawTags card =
[ ( "twitter:title", Just details.title )
, ( "twitter:site", Just details.siteUser )
, ( "twitter:description", details.description )
, ( "twitter:image", details.image |> Maybe.map .url )
, ( "twitter:image", details.image |> Maybe.map .url |> Maybe.map Pages.Path.toString )
, ( "twitter:image:alt", details.image |> Maybe.map .alt )
, ( "twitter:app:name:iphone", details.appNameIphone )
, ( "twitter:app:name:ipad", details.appNameIpad )
@ -137,13 +144,13 @@ rawTags card =
[ ( "twitter:title", Just details.title )
, ( "twitter:site", Just details.siteUser )
, ( "twitter:description", details.description )
, ( "twitter:image", Just details.image.url )
, ( "twitter:image", Just (Pages.Path.toString details.image.url) )
, ( "twitter:image:alt", Just details.image.alt )
]
)
tags : TwitterCard -> List (Head.Tag pathKey)
tags : TwitterCard pathKey -> List (Head.Tag pathKey)
tags card =
card
|> rawTags
@ -154,7 +161,7 @@ tags card =
)
cardValue : TwitterCard -> String
cardValue : TwitterCard pathKey -> String
cardValue card =
case card of
Summary details ->

View File

@ -243,7 +243,7 @@ header =
<https://html.spec.whatwg.org/multipage/semantics.html#standard-metadata-names>
<https://ogp.me/>
-}
head : Metadata Msg -> List Head.Tag
head : Metadata Msg -> List (Head.Tag PagesNew.PathKey)
head metadata =
let
themeColor =
@ -265,7 +265,7 @@ siteTagline =
"A statically typed site generator - elm-pages"
pageTags : Metadata Msg -> List Head.Tag
pageTags : Metadata Msg -> List (Head.Tag PagesNew.PathKey)
pageTags metadata =
case metadata of
Metadata.Page _ ->
@ -273,7 +273,7 @@ pageTags metadata =
{ url = canonicalUrl
, siteName = "elm-pages"
, image =
{ url = ""
{ url = PagesNew.images.icon
, alt = ""
, dimensions = Nothing
, mimeType = Nothing
@ -289,7 +289,7 @@ pageTags metadata =
{ url = canonicalUrl
, siteName = "elm-pages"
, image =
{ url = ""
{ url = PagesNew.images.icon
, alt = ""
, dimensions = Nothing
, mimeType = Nothing
@ -317,7 +317,7 @@ pageTags metadata =
{ url = url
, siteName = "elm-pages"
, image =
{ url = imageUrl
{ url = PagesNew.images.icon
, alt = description
, dimensions = Nothing
, mimeType = Nothing