Commit 5ef5a6fd authored by Emmanuel Raviart's avatar Emmanuel Raviart

Add Twitter name to metadata of HTML pages.

parent 87b9e31c
...@@ -104,7 +104,7 @@ update msg ({ fields } as model) authentication language = ...@@ -104,7 +104,7 @@ update msg ({ fields } as model) authentication language =
} }
cmd = cmd =
Ports.setDocumentMetatags Ports.setDocumentMetadata
{ description = I18n.translate language I18n.CollectionEditDescription { description = I18n.translate language I18n.CollectionEditDescription
, imageUrl = Constants.logoUrl , imageUrl = Constants.logoUrl
, title = I18n.translate language I18n.CollectionEditTitle , title = I18n.translate language I18n.CollectionEditTitle
......
...@@ -91,7 +91,7 @@ update msg model language = ...@@ -91,7 +91,7 @@ update msg model language =
body.data body.data
cmds = cmds =
[ Ports.setDocumentMetatags [ Ports.setDocumentMetadata
{ description = I18n.translate language I18n.ActivationDescription { description = I18n.translate language I18n.ActivationDescription
, imageUrl = Constants.logoUrl , imageUrl = Constants.logoUrl
, title = I18n.translate language I18n.ActivationTitle , title = I18n.translate language I18n.ActivationTitle
......
...@@ -9,7 +9,6 @@ import Ports ...@@ -9,7 +9,6 @@ import Ports
import Requests import Requests
import Task import Task
import Types exposing (..) import Types exposing (..)
import Urls
import WebData exposing (..) import WebData exposing (..)
...@@ -71,13 +70,11 @@ update msg ({ editedProperty } as model) authentication language = ...@@ -71,13 +70,11 @@ update msg ({ editedProperty } as model) authentication language =
{ model | webData = Data (Loaded body) } { model | webData = Data (Loaded body) }
cmd = cmd =
Ports.setDocumentMetatags Ports.setDocumentMetadata
{ description = { description =
getOneString language descriptionKeys card body.data.values getOneString language descriptionKeys card body.data.values
|> Maybe.withDefault (I18n.translate language I18n.MissingDescription) |> Maybe.withDefault (I18n.translate language I18n.MissingDescription)
, imageUrl = , imageUrl = getImageUrlOrOgpLogo language body.data.id body.data.cards body.data.values
Urls.fullApiUrl <|
getImageUrlOrOgpLogo language body.data.id body.data.cards body.data.values
, title = getName language card body.data.values , title = getName language card body.data.values
} }
in in
......
...@@ -8,7 +8,6 @@ import Http ...@@ -8,7 +8,6 @@ import Http
import I18n exposing (getImageUrlOrOgpLogo, getName) import I18n exposing (getImageUrlOrOgpLogo, getName)
import Ports import Ports
import Requests import Requests
import Urls
import WebData exposing (..) import WebData exposing (..)
...@@ -46,11 +45,10 @@ update msg model authentication language = ...@@ -46,11 +45,10 @@ update msg model authentication language =
collection collection
cmd = cmd =
Ports.setDocumentMetatags Ports.setDocumentMetadata
{ description = collection.description { description = collection.description
, imageUrl = , imageUrl =
Urls.fullApiUrl <| (collection.logo |> Maybe.withDefault Constants.logoUrl)
(collection.logo |> Maybe.withDefault Constants.logoUrl)
, title = collection.name , title = collection.name
} }
in in
......
...@@ -36,7 +36,7 @@ update msg model authentication language = ...@@ -36,7 +36,7 @@ update msg model authentication language =
{ model | collections = Data (Loaded body) } { model | collections = Data (Loaded body) }
cmd = cmd =
Ports.setDocumentMetatags Ports.setDocumentMetadata
{ description = I18n.translate language I18n.CollectionsDescription { description = I18n.translate language I18n.CollectionsDescription
, imageUrl = Constants.logoUrl , imageUrl = Constants.logoUrl
, title = I18n.translate language I18n.CollectionsTitle , title = I18n.translate language I18n.CollectionsTitle
......
...@@ -14,6 +14,11 @@ appUrl = ...@@ -14,6 +14,11 @@ appUrl =
"http://localhost:3011/" "http://localhost:3011/"
twitterName : String
twitterName =
"@OGPToolbox"
useItData : Dict String { frenchGovDeployUrl : String } useItData : Dict String { frenchGovDeployUrl : String }
useItData = useItData =
Dict.fromList Dict.fromList
......
...@@ -486,7 +486,7 @@ urlUpdate location model = ...@@ -486,7 +486,7 @@ urlUpdate location model =
in in
newModel newModel
! [ Cmd.map translateSearchMsg searchCmd ! [ Cmd.map translateSearchMsg searchCmd
, Ports.setDocumentMetatags , Ports.setDocumentMetadata
{ description = I18n.translate language descriptionSymbol { description = I18n.translate language descriptionSymbol
, imageUrl = Constants.logoUrl , imageUrl = Constants.logoUrl
, title = I18n.translate language titleSymbol , title = I18n.translate language titleSymbol
...@@ -497,7 +497,7 @@ urlUpdate location model = ...@@ -497,7 +497,7 @@ urlUpdate location model =
case localizedRoute of case localizedRoute of
AboutRoute -> AboutRoute ->
( model ( model
, Ports.setDocumentMetatags , Ports.setDocumentMetadata
{ description = I18n.translate language I18n.AboutDescription { description = I18n.translate language I18n.AboutDescription
, imageUrl = Constants.logoUrl , imageUrl = Constants.logoUrl
, title = I18n.translate language I18n.About , title = I18n.translate language I18n.About
...@@ -573,7 +573,7 @@ urlUpdate location model = ...@@ -573,7 +573,7 @@ urlUpdate location model =
FaqRoute -> FaqRoute ->
( model ( model
, Ports.setDocumentMetatags , Ports.setDocumentMetadata
{ description = I18n.translate language I18n.FaqDescription { description = I18n.translate language I18n.FaqDescription
, imageUrl = Constants.logoUrl , imageUrl = Constants.logoUrl
, title = I18n.translate language I18n.Faq , title = I18n.translate language I18n.Faq
...@@ -585,7 +585,7 @@ urlUpdate location model = ...@@ -585,7 +585,7 @@ urlUpdate location model =
NotFoundRoute _ -> NotFoundRoute _ ->
( model ( model
, Ports.setDocumentMetatags , Ports.setDocumentMetadata
{ description = I18n.translate language I18n.PageNotFoundDescription { description = I18n.translate language I18n.PageNotFoundDescription
, imageUrl = Constants.logoUrl , imageUrl = Constants.logoUrl
, title = I18n.translate language I18n.PageNotFound , title = I18n.translate language I18n.PageNotFound
...@@ -625,7 +625,7 @@ urlUpdate location model = ...@@ -625,7 +625,7 @@ urlUpdate location model =
{ model | addNewModel = newAddNewModel } { model | addNewModel = newAddNewModel }
cmd = cmd =
Ports.setDocumentMetatags Ports.setDocumentMetadata
{ description = { description =
I18n.translate language I18n.AddNewOrganizationDescription I18n.translate language I18n.AddNewOrganizationDescription
, imageUrl = Constants.logoUrl , imageUrl = Constants.logoUrl
...@@ -667,7 +667,7 @@ urlUpdate location model = ...@@ -667,7 +667,7 @@ urlUpdate location model =
{ model | addNewModel = newAddNewModel } { model | addNewModel = newAddNewModel }
cmd = cmd =
Ports.setDocumentMetatags Ports.setDocumentMetadata
{ description = { description =
I18n.translate language I18n.AddNewToolDescription I18n.translate language I18n.AddNewToolDescription
, imageUrl = Constants.logoUrl , imageUrl = Constants.logoUrl
...@@ -709,7 +709,7 @@ urlUpdate location model = ...@@ -709,7 +709,7 @@ urlUpdate location model =
{ model | addNewModel = newAddNewModel } { model | addNewModel = newAddNewModel }
cmd = cmd =
Ports.setDocumentMetatags Ports.setDocumentMetadata
{ description = { description =
I18n.translate language I18n.AddNewUseCaseDescription I18n.translate language I18n.AddNewUseCaseDescription
, title = I18n.translate language I18n.AddNewUseCase , title = I18n.translate language I18n.AddNewUseCase
......
port module Ports exposing (..) port module Ports exposing (..)
import Types exposing (DocumentMetatags, PopularTag, User, UserForPort) import Configuration
import Types exposing (DocumentMetadata, PopularTag, User, UserForPort)
import Urls
-- DOCUMENT METATAGS -- DOCUMENT METADATA
type alias DocumentMetatags =
{ description : String
, imageUrl : String
, title : String
, twitterName : String
}
setDocumentMetadata : DocumentMetadata -> Cmd msg
setDocumentMetadata metadata =
setDocumentMetatags
{ description = metadata.description
, imageUrl = Urls.fullApiUrl metadata.imageUrl
, title = metadata.title
, twitterName = Configuration.twitterName
}
port setDocumentMetatags : DocumentMetatags -> Cmd msg port setDocumentMetatags : DocumentMetatags -> Cmd msg
......
...@@ -86,7 +86,7 @@ type alias DataIdsBody = ...@@ -86,7 +86,7 @@ type alias DataIdsBody =
} }
type alias DocumentMetatags = type alias DocumentMetadata =
{ description : String { description : String
, imageUrl : String , imageUrl : String
, title : String , title : String
......
...@@ -36,7 +36,7 @@ update msg model authentication language = ...@@ -36,7 +36,7 @@ update msg model authentication language =
{ model | collections = Data (Loaded body) } { model | collections = Data (Loaded body) }
cmd = cmd =
Ports.setDocumentMetatags Ports.setDocumentMetadata
{ description = I18n.translate language I18n.UserProfileDescription { description = I18n.translate language I18n.UserProfileDescription
, imageUrl = Constants.logoUrl , imageUrl = Constants.logoUrl
, title = authentication.name , title = authentication.name
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
<meta property="og:type" content="website"> <meta property="og:type" content="website">
<meta property="og:url" content=""> <meta property="og:url" content="">
<meta property="twitter:card" content="summary">
<meta property="twitter:site" content="@OGPToolbox">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<!--<link rel="apple-touch-icon" href="apple-touch-icon.png">--> <!--<link rel="apple-touch-icon" href="apple-touch-icon.png">-->
......
// pull in desired CSS/LESS files // Pull in desired CSS/LESS files.
require('../css/ogp-style.less'); require('../css/ogp-style.less');
// require('../css/retruco.less');
require('../css/bubbles.less'); require('../css/bubbles.less');
// user prefered language (http://stackoverflow.com/a/38150585/3548266) // User prefered language (http://stackoverflow.com/a/38150585/3548266)
var language = navigator.languages && navigator.languages[0] || // Chrome / Firefox var language = navigator.languages && navigator.languages[0] || // Chrome / Firefox
navigator.language || // All browsers navigator.language || // All browsers
...@@ -21,7 +20,7 @@ var rAF = typeof requestAnimationFrame !== 'undefined' ...@@ -21,7 +20,7 @@ var rAF = typeof requestAnimationFrame !== 'undefined'
: function(callback) { setTimeout(function() { callback(); }, 0); }; : function(callback) { setTimeout(function() { callback(); }, 0); };
// authentication // Authentication
var authenticationStr = window.localStorage.getItem('authentication'); var authenticationStr = window.localStorage.getItem('authentication');
var authentication = authenticationStr ? JSON.parse(authenticationStr) : null; var authentication = authenticationStr ? JSON.parse(authenticationStr) : null;
...@@ -37,7 +36,6 @@ var flags = { ...@@ -37,7 +36,6 @@ var flags = {
var main = Elm.Main.embed(document.getElementById('main'), flags); var main = Elm.Main.embed(document.getElementById('main'), flags);
// Ports // Ports
main.ports.setDocumentMetatags.subscribe(function(metatags) { main.ports.setDocumentMetatags.subscribe(function(metatags) {
...@@ -75,6 +73,13 @@ main.ports.setDocumentMetatags.subscribe(function(metatags) { ...@@ -75,6 +73,13 @@ main.ports.setDocumentMetatags.subscribe(function(metatags) {
if (element) { if (element) {
element.setAttribute('content', window.location.href); element.setAttribute('content', window.location.href);
} }
if (metatags.hasOwnProperty('twitterName')) {
var element = document.head.querySelector('meta[property="twitter:site"]');
if (element) {
element.setAttribute('content', metatags.twitterName);
}
}
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment