From 29b38064712664c81fdf7735d34879535544728d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 10 Oct 2019 12:25:32 +0200 Subject: [PATCH] Fix preview Signed-off-by: Thomas Citharel --- js/public/index.html | 1 - js/src/views/Event/Event.vue | 8 +++++++- lib/service/metadata/event.ex | 11 +++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/js/public/index.html b/js/public/index.html index 413453152..e5cc633db 100644 --- a/js/public/index.html +++ b/js/public/index.html @@ -6,7 +6,6 @@ - mobilizon diff --git a/js/src/views/Event/Event.vue b/js/src/views/Event/Event.vue index f1d0994d6..70f6aefb8 100644 --- a/js/src/views/Event/Event.vue +++ b/js/src/views/Event/Event.vue @@ -474,7 +474,13 @@ export default class Event extends EventMixin { } get emailShareUrl(): string { - return `mailto:?to=&body=${this.event.url}${encodeURIComponent('\n\n')}${this.event.description}&subject=${this.event.title}`; + return `mailto:?to=&body=${this.event.url}${encodeURIComponent('\n\n')}${this.textDescription}&subject=${this.event.title}`; + } + + get textDescription(): string { + const meta = document.querySelector("meta[property='og:description']"); + if (!meta) return ''; + return meta.getAttribute('content') || ''; } } diff --git a/lib/service/metadata/event.ex b/lib/service/metadata/event.ex index 91c801b45..479dd782c 100644 --- a/lib/service/metadata/event.ex +++ b/lib/service/metadata/event.ex @@ -6,7 +6,11 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do alias MobilizonWeb.MediaProxy def build_tags(%Event{} = event) do + event = Map.put(event, :description, process_description(event.description)) + tags = [ + Tag.content_tag(:title, event.title <> " - Mobilizon"), + Tag.tag(:meta, name: "description", content: event.description), Tag.tag(:meta, property: "og:title", content: event.title), Tag.tag(:meta, property: "og:url", content: event.url), Tag.tag(:meta, property: "og:description", content: event.description), @@ -33,6 +37,13 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do ] end + defp process_description(description) do + description + |> HtmlSanitizeEx.strip_tags() + |> String.slice(0..200) + |> (&"#{&1}…").() + end + # Insert JSON-LD schema by hand because Tag.content_tag wants to escape it defp json(%Event{} = event) do "event.json"