add opengraph meta

This commit is contained in:
byte[] 2019-12-03 20:56:39 -05:00
parent 50880ba888
commit d43c9cbcf4
5 changed files with 53 additions and 5 deletions

View file

@ -67,6 +67,6 @@ defmodule PhilomenaWeb.Api.Json.OembedController do
defp artist_tags(tags) do
tags
|> Enum.filter(& &1.namespace == "artist")
|> Enum.map_join(", ", & &1.name)
|> Enum.map_join(", ", & &1.name_in_namespace)
end
end

View file

@ -0,0 +1,41 @@
meta name="generator" content="philomena"
meta name="theme-color"
meta name="format-detection" content="telephone=no"
meta name="robots" content="noindex, nofollow"
= if !is_nil(@conn.assigns.image) and @conn.assigns.image.__meta__.state == :loaded do
- image = @conn.assigns.image
- filtered = ImageView.filter_or_spoiler_hits?(@conn, image)
meta name="description" content="##{image.id} - Derpibooru"
meta name="keywords" content=image.tag_list_cache
meta name="og:title" content="##{image.id} - Derpibooru"
meta name="og:url" content=Routes.image_url(@conn, :show, image)
= for tag <- artist_tags(image.tags) do
meta property="dc:creator" content=tag.name_in_namespace
= if image.source_url not in [nil, ""] do
meta propery="foaf:primaryTopic" content=image.source_url
link rel="alternate" type="application/json+oembed" href=Routes.api_json_oembed_url(@conn, :index, url: Routes.image_path(@conn, :show, image)) title="oEmbed JSON Profile"
= cond do
- image.image_mime_type == "video/webm" and !filtered ->
meta name="og:type" content="video.other"
meta name="og:image" content=ImageView.thumb_url(image, false, :rendered)
meta name="og:video" content=Imageview.thumb_url(image, false, :full)
- image.image_mime_type == "image/svg+xml" and !filtered ->
meta name="og:type" content="video.other"
meta name="og:image" content=ImageView.thumb_url(image, false, :rendered)
- !filtered ->
meta name="og:type" content="website"
meta name="og:image" content=ImageView.thumb_url(image, false, :full)
- true ->
meta name="og:type" content="website"
- else
meta name="description" content="Derpibooru is a linear imagebooru which lets you share, find and discover new art and media surrounding the show My Little Pony: Friendship is Magic"

View file

@ -19,6 +19,7 @@ html lang="en"
meta name="robots" content="noindex, nofollow"
= csrf_meta_tag()
script type="text/javascript" src=Routes.static_path(@conn, "/js/app.js") async="async"
= render PhilomenaWeb.LayoutView, "_opengraph.html", assigns
body data-theme="default"
= render PhilomenaWeb.LayoutView, "_burger.html", assigns
#container class=container_class(@current_user)

View file

@ -72,7 +72,7 @@ defmodule PhilomenaWeb.ImageView do
format =
image.image_format
|> String.downcase()
|> thumb_format()
|> thumb_format(name)
id_fragment =
if deleted and show_hidden do
@ -93,7 +93,7 @@ defmodule PhilomenaWeb.ImageView do
format =
image.image_format
|> String.downcase()
|> thumb_format()
|> thumb_format(nil)
"#{root}/#{view}/#{year}/#{month}/#{day}/#{filename}.#{format}"
end
@ -136,8 +136,9 @@ defmodule PhilomenaWeb.ImageView do
conn.assigns.current_user.anonymous_by_default
end
defp thumb_format("svg"), do: "png"
defp thumb_format(format), do: format
defp thumb_format("svg", _name), do: "png"
defp thumb_format(_, :rendered), do: "png"
defp thumb_format(format, _name), do: format
defp image_filter_data(image) do
%{

View file

@ -1,6 +1,8 @@
defmodule PhilomenaWeb.LayoutView do
use PhilomenaWeb, :view
alias PhilomenaWeb.ImageView
def layout_class(conn) do
conn.assigns[:layout_class] || "layout--narrow"
end
@ -71,4 +73,7 @@ defmodule PhilomenaWeb.LayoutView do
def stylesheet_path(conn, _user),
do: Routes.static_path(conn, "/css/default.css")
def artist_tags(tags),
do: Enum.filter(tags, & &1.namespace == "artist")
end