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 =
}
cmd =
Ports.setDocumentMetatags
Ports.setDocumentMetadata
{ description = I18n.translate language I18n.CollectionEditDescription
, imageUrl = Constants.logoUrl
, title = I18n.translate language I18n.CollectionEditTitle
......
......@@ -91,7 +91,7 @@ update msg model language =
body.data
cmds =
[ Ports.setDocumentMetatags
[ Ports.setDocumentMetadata
{ description = I18n.translate language I18n.ActivationDescription
, imageUrl = Constants.logoUrl
, title = I18n.translate language I18n.ActivationTitle
......
......@@ -9,7 +9,6 @@ import Ports
import Requests
import Task
import Types exposing (..)
import Urls
import WebData exposing (..)
......@@ -71,13 +70,11 @@ update msg ({ editedProperty } as model) authentication language =
{ model | webData = Data (Loaded body) }
cmd =
Ports.setDocumentMetatags
Ports.setDocumentMetadata
{ description =
getOneString language descriptionKeys card body.data.values
|> Maybe.withDefault (I18n.translate language I18n.MissingDescription)
, imageUrl =
Urls.fullApiUrl <|
getImageUrlOrOgpLogo language body.data.id body.data.cards body.data.values
, imageUrl = getImageUrlOrOgpLogo language body.data.id body.data.cards body.data.values
, title = getName language card body.data.values
}
in
......
......@@ -8,7 +8,6 @@ import Http
import I18n exposing (getImageUrlOrOgpLogo, getName)
import Ports
import Requests
import Urls
import WebData exposing (..)
......@@ -46,11 +45,10 @@ update msg model authentication language =
collection
cmd =
Ports.setDocumentMetatags
Ports.setDocumentMetadata
{ description = collection.description
, imageUrl =
Urls.fullApiUrl <|
(collection.logo |> Maybe.withDefault Constants.logoUrl)
(collection.logo |> Maybe.withDefault Constants.logoUrl)
, title = collection.name
}
in
......
......@@ -36,7 +36,7 @@ update msg model authentication language =
{ model | collections = Data (Loaded body) }
cmd =
Ports.setDocumentMetatags
Ports.setDocumentMetadata
{ description = I18n.translate language I18n.CollectionsDescription
, imageUrl = Constants.logoUrl
, title = I18n.translate language I18n.CollectionsTitle
......
......@@ -14,6 +14,11 @@ appUrl =
"http://localhost:3011/"
twitterName : String
twitterName =
"@OGPToolbox"
useItData : Dict String { frenchGovDeployUrl : String }
useItData =
Dict.fromList
......
......@@ -486,7 +486,7 @@ urlUpdate location model =
in
newModel
! [ Cmd.map translateSearchMsg searchCmd
, Ports.setDocumentMetatags
, Ports.setDocumentMetadata
{ description = I18n.translate language descriptionSymbol
, imageUrl = Constants.logoUrl
, title = I18n.translate language titleSymbol
......@@ -497,7 +497,7 @@ urlUpdate location model =
case localizedRoute of
AboutRoute ->
( model
, Ports.setDocumentMetatags
, Ports.setDocumentMetadata
{ description = I18n.translate language I18n.AboutDescription
, imageUrl = Constants.logoUrl
, title = I18n.translate language I18n.About
......@@ -573,7 +573,7 @@ urlUpdate location model =
FaqRoute ->
( model
, Ports.setDocumentMetatags
, Ports.setDocumentMetadata
{ description = I18n.translate language I18n.FaqDescription
, imageUrl = Constants.logoUrl
, title = I18n.translate language I18n.Faq
......@@ -585,7 +585,7 @@ urlUpdate location model =
NotFoundRoute _ ->
( model
, Ports.setDocumentMetatags
, Ports.setDocumentMetadata
{ description = I18n.translate language I18n.PageNotFoundDescription
, imageUrl = Constants.logoUrl
, title = I18n.translate language I18n.PageNotFound
......@@ -625,7 +625,7 @@ urlUpdate location model =
{ model | addNewModel = newAddNewModel }
cmd =
Ports.setDocumentMetatags
Ports.setDocumentMetadata
{ description =
I18n.translate language I18n.AddNewOrganizationDescription
, imageUrl = Constants.logoUrl
......@@ -667,7 +667,7 @@ urlUpdate location model =
{ model | addNewModel = newAddNewModel }
cmd =
Ports.setDocumentMetatags
Ports.setDocumentMetadata
{ description =
I18n.translate language I18n.AddNewToolDescription
, imageUrl = Constants.logoUrl
......@@ -709,7 +709,7 @@ urlUpdate location model =
{ model | addNewModel = newAddNewModel }
cmd =
Ports.setDocumentMetatags
Ports.setDocumentMetadata
{ description =
I18n.translate language I18n.AddNewUseCaseDescription
, title = I18n.translate language I18n.AddNewUseCase
......
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
......
......@@ -86,7 +86,7 @@ type alias DataIdsBody =
}
type alias DocumentMetatags =
type alias DocumentMetadata =
{ description : String
, imageUrl : String
, title : String
......
......@@ -36,7 +36,7 @@ update msg model authentication language =
{ model | collections = Data (Loaded body) }
cmd =
Ports.setDocumentMetatags
Ports.setDocumentMetadata
{ description = I18n.translate language I18n.UserProfileDescription
, imageUrl = Constants.logoUrl
, title = authentication.name
......
......@@ -17,6 +17,9 @@
<meta property="og:type" content="website">
<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">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<!--<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/retruco.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
navigator.language || // All browsers
......@@ -21,7 +20,7 @@ var rAF = typeof requestAnimationFrame !== 'undefined'
: function(callback) { setTimeout(function() { callback(); }, 0); };
// authentication
// Authentication
var authenticationStr = window.localStorage.getItem('authentication');
var authentication = authenticationStr ? JSON.parse(authenticationStr) : null;
......@@ -37,7 +36,6 @@ var flags = {
var main = Elm.Main.embed(document.getElementById('main'), flags);
// Ports
main.ports.setDocumentMetatags.subscribe(function(metatags) {
......@@ -75,6 +73,13 @@ main.ports.setDocumentMetatags.subscribe(function(metatags) {
if (element) {
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