Use helper function to build common OpenGraph data.

This commit is contained in:
Dillon Kearns 2019-08-05 13:10:18 -07:00
parent d3480e2a81
commit 4c33914cdc
2 changed files with 44 additions and 34 deletions

View File

@ -179,22 +179,17 @@ pageTags metadata =
case metadata of
Metadata.Page record ->
OpenGraph.website
{ url = canonicalUrl
, siteName = "elm-pages"
, image =
{ url = ""
, alt = ""
, dimensions = Nothing
, secureUrl = Nothing
, mimeType = Nothing
(OpenGraph.buildCommon
{ url = canonicalUrl
, siteName = "elm-pages"
, image =
{ url = ""
, alt = ""
}
, description = siteTagline
, title = "elm-pages"
}
, description = siteTagline
, alternateLocales = []
, audio = Nothing
, locale = Nothing
, title = "elm-pages"
, video = Nothing
}
)
Metadata.Article meta ->
let
@ -204,38 +199,33 @@ pageTags metadata =
title =
meta.title.raw
image =
imageUrl =
""
url =
canonicalUrl
in
[ Head.description description
, Head.metaName "image" image
, Head.metaName "image" imageUrl
]
++ SocialMeta.summaryLarge
{ title = meta.title.raw
, description = Just description
, siteUser = Nothing
, image = Just { url = image, alt = description }
, image = Just { url = imageUrl, alt = description }
}
++ OpenGraph.article
{ image =
{ url = image
, alt = description
, dimensions = Nothing
, secureUrl = Nothing
, mimeType = Nothing
(OpenGraph.buildCommon
{ url = url
, siteName = "elm-pages"
, image =
{ url = imageUrl
, alt = description
}
, description = description
, title = title
}
, title = title
, url = url
, description = ""
, siteName = "elm-pages"
, alternateLocales = []
, audio = Nothing
, locale = Nothing
, video = Nothing
}
)
{ tags = []
, section = Nothing
, publishedTime = Nothing

View File

@ -1,4 +1,4 @@
module OpenGraph exposing (Image, article, website)
module OpenGraph exposing (Image, article, buildCommon, website)
{-| <https://ogp.me/#>
-}
@ -6,6 +6,26 @@ module OpenGraph exposing (Image, article, website)
import Pages.Head as Head
buildCommon : { url : String, siteName : String, image : { url : String, alt : String }, description : String, title : String } -> Common
buildCommon builder =
{ title = builder.title
, image =
{ url = builder.image.url
, alt = builder.image.alt
, dimensions = Nothing
, mimeType = Nothing
, secureUrl = Nothing
}
, url = builder.url
, description = builder.description
, siteName = builder.siteName
, audio = Nothing
, video = Nothing
, locale = Nothing
, alternateLocales = []
}
{-| <https://ogp.me/#type_website>
-}
website :