mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
add opengraph meta
This commit is contained in:
parent
50880ba888
commit
d43c9cbcf4
5 changed files with 53 additions and 5 deletions
|
@ -67,6 +67,6 @@ defmodule PhilomenaWeb.Api.Json.OembedController do
|
||||||
defp artist_tags(tags) do
|
defp artist_tags(tags) do
|
||||||
tags
|
tags
|
||||||
|> Enum.filter(& &1.namespace == "artist")
|
|> Enum.filter(& &1.namespace == "artist")
|
||||||
|> Enum.map_join(", ", & &1.name)
|
|> Enum.map_join(", ", & &1.name_in_namespace)
|
||||||
end
|
end
|
||||||
end
|
end
|
41
lib/philomena_web/templates/layout/_opengraph.html.slime
Normal file
41
lib/philomena_web/templates/layout/_opengraph.html.slime
Normal 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"
|
|
@ -19,6 +19,7 @@ html lang="en"
|
||||||
meta name="robots" content="noindex, nofollow"
|
meta name="robots" content="noindex, nofollow"
|
||||||
= csrf_meta_tag()
|
= csrf_meta_tag()
|
||||||
script type="text/javascript" src=Routes.static_path(@conn, "/js/app.js") async="async"
|
script type="text/javascript" src=Routes.static_path(@conn, "/js/app.js") async="async"
|
||||||
|
= render PhilomenaWeb.LayoutView, "_opengraph.html", assigns
|
||||||
body data-theme="default"
|
body data-theme="default"
|
||||||
= render PhilomenaWeb.LayoutView, "_burger.html", assigns
|
= render PhilomenaWeb.LayoutView, "_burger.html", assigns
|
||||||
#container class=container_class(@current_user)
|
#container class=container_class(@current_user)
|
||||||
|
|
|
@ -72,7 +72,7 @@ defmodule PhilomenaWeb.ImageView do
|
||||||
format =
|
format =
|
||||||
image.image_format
|
image.image_format
|
||||||
|> String.downcase()
|
|> String.downcase()
|
||||||
|> thumb_format()
|
|> thumb_format(name)
|
||||||
|
|
||||||
id_fragment =
|
id_fragment =
|
||||||
if deleted and show_hidden do
|
if deleted and show_hidden do
|
||||||
|
@ -93,7 +93,7 @@ defmodule PhilomenaWeb.ImageView do
|
||||||
format =
|
format =
|
||||||
image.image_format
|
image.image_format
|
||||||
|> String.downcase()
|
|> String.downcase()
|
||||||
|> thumb_format()
|
|> thumb_format(nil)
|
||||||
|
|
||||||
"#{root}/#{view}/#{year}/#{month}/#{day}/#{filename}.#{format}"
|
"#{root}/#{view}/#{year}/#{month}/#{day}/#{filename}.#{format}"
|
||||||
end
|
end
|
||||||
|
@ -136,8 +136,9 @@ defmodule PhilomenaWeb.ImageView do
|
||||||
conn.assigns.current_user.anonymous_by_default
|
conn.assigns.current_user.anonymous_by_default
|
||||||
end
|
end
|
||||||
|
|
||||||
defp thumb_format("svg"), do: "png"
|
defp thumb_format("svg", _name), do: "png"
|
||||||
defp thumb_format(format), do: format
|
defp thumb_format(_, :rendered), do: "png"
|
||||||
|
defp thumb_format(format, _name), do: format
|
||||||
|
|
||||||
defp image_filter_data(image) do
|
defp image_filter_data(image) do
|
||||||
%{
|
%{
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
defmodule PhilomenaWeb.LayoutView do
|
defmodule PhilomenaWeb.LayoutView do
|
||||||
use PhilomenaWeb, :view
|
use PhilomenaWeb, :view
|
||||||
|
|
||||||
|
alias PhilomenaWeb.ImageView
|
||||||
|
|
||||||
def layout_class(conn) do
|
def layout_class(conn) do
|
||||||
conn.assigns[:layout_class] || "layout--narrow"
|
conn.assigns[:layout_class] || "layout--narrow"
|
||||||
end
|
end
|
||||||
|
@ -71,4 +73,7 @@ defmodule PhilomenaWeb.LayoutView do
|
||||||
|
|
||||||
def stylesheet_path(conn, _user),
|
def stylesheet_path(conn, _user),
|
||||||
do: Routes.static_path(conn, "/css/default.css")
|
do: Routes.static_path(conn, "/css/default.css")
|
||||||
|
|
||||||
|
def artist_tags(tags),
|
||||||
|
do: Enum.filter(tags, & &1.namespace == "artist")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue