From 1e4eccdfb2e3c8f30403baaa8f353a4951c71b47 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 5 Aug 2019 11:30:54 -0700 Subject: [PATCH] Update OpenGraph website helper. --- examples/docs/src/Main.elm | 2 +- examples/docs/src/OpenGraph.elm | 40 ++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/examples/docs/src/Main.elm b/examples/docs/src/Main.elm index 62d8d44b..858afd04 100644 --- a/examples/docs/src/Main.elm +++ b/examples/docs/src/Main.elm @@ -181,7 +181,7 @@ pageTags metadata = OpenGraph.website { url = canonicalUrl , name = "elm-pages" - , imageUrl = "" + , image = { url = "", alt = "", dimensions = Nothing, secureUrl = Nothing } , description = Just siteTagline } diff --git a/examples/docs/src/OpenGraph.elm b/examples/docs/src/OpenGraph.elm index aab874e4..a571bca4 100644 --- a/examples/docs/src/OpenGraph.elm +++ b/examples/docs/src/OpenGraph.elm @@ -1,4 +1,4 @@ -module OpenGraph exposing (website) +module OpenGraph exposing (Image, website) {-| -} @@ -11,7 +11,7 @@ import Pages.Head as Head website : { url : String , name : String - , imageUrl : String + , image : Image , description : Maybe String } -> List Head.Tag @@ -24,22 +24,40 @@ type Content = Website { url : String , name : String - , imageUrl : String + , image : Image , description : Maybe String } +{-| See +-} +type alias Image = + { url : String + , alt : String + , dimensions : Maybe { width : Int, height : Int } + , secureUrl : Maybe String + } + + +tagsForImage image = + [ ( "og:image", Just 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 ) + ] + + tags content = case content of Website details -> - [ ( "og:type", Just "website" ) - , ( "og:url", Just details.url ) - , ( "og:locale", Just "en" ) - , ( "og:site_name", Just details.name ) - , ( "og:title", Just details.name ) - , ( "og:image", Just details.imageUrl ) - , ( "og:description", details.description ) - ] + tagsForImage details.image + ++ [ ( "og:type", Just "website" ) + , ( "og:url", Just details.url ) + , ( "og:locale", Just "en" ) + , ( "og:site_name", Just details.name ) + , ( "og:title", Just details.name ) + , ( "og:description", details.description ) + ] |> List.filterMap (\( name, maybeContent ) -> maybeContent