2020-07-30 16:05:09 +00:00
|
|
|
defmodule AppWeb.LayoutView do
|
|
|
|
use AppWeb, :view
|
2020-09-30 20:10:17 +00:00
|
|
|
|
2021-10-19 19:28:25 +00:00
|
|
|
alias Legendary.ContentWeb.Uploaders.SocialMediaPreview
|
|
|
|
|
2021-09-27 04:19:49 +00:00
|
|
|
def title(conn, assigns), do: title(view_module(conn), view_template(conn), assigns)
|
|
|
|
|
2021-09-17 18:20:44 +00:00
|
|
|
def title(view, template, %{post: post}), do: "#{post.title} | #{title(view, template, nil)}"
|
|
|
|
|
2021-04-09 20:46:10 +00:00
|
|
|
def title(_, _, _) do
|
|
|
|
Legendary.I18n.t!("en", "site.title")
|
2021-09-17 18:20:44 +00:00
|
|
|
end
|
|
|
|
|
2021-09-27 04:19:49 +00:00
|
|
|
def excerpt(conn, assigns), do: excerpt(view_module(conn), view_template(conn), assigns)
|
|
|
|
|
2021-09-17 18:20:44 +00:00
|
|
|
def excerpt(_, _, %{post: post}) do
|
|
|
|
post.excerpt
|
|
|
|
end
|
|
|
|
|
|
|
|
def excerpt(_, _, _) do
|
|
|
|
Legendary.I18n.t!("en", "site.excerpt")
|
|
|
|
end
|
|
|
|
|
2021-09-27 04:19:49 +00:00
|
|
|
def feed_tag(conn, assigns), do: feed_tag(conn, view_module(conn), view_template(conn), assigns)
|
|
|
|
|
2021-09-17 18:20:44 +00:00
|
|
|
def feed_tag(_, _, _, _) do
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2021-09-27 04:19:49 +00:00
|
|
|
def modified_tag(conn, assigns), do: modified_tag(view_module(conn), view_template(conn), assigns)
|
|
|
|
|
2021-09-17 18:20:44 +00:00
|
|
|
def modified_tag(_, _, %{post: post}) do
|
|
|
|
content =
|
|
|
|
post.modified_gmt
|
|
|
|
|> DateTime.from_naive!("Etc/UTC")
|
|
|
|
|> DateTime.to_iso8601()
|
|
|
|
|
|
|
|
tag :meta, property: "article:modified_time", content: content
|
|
|
|
end
|
|
|
|
|
|
|
|
def modified_tag(_, _, _) do
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2021-09-27 04:19:49 +00:00
|
|
|
def published_tag(conn, assigns), do: modified_tag(view_module(conn), view_template(conn), assigns)
|
|
|
|
|
2021-09-17 18:20:44 +00:00
|
|
|
def published_tag(_, _, %{post: post}) do
|
|
|
|
content =
|
|
|
|
post.date_gmt
|
|
|
|
|> DateTime.from_naive!("Etc/UTC")
|
|
|
|
|> DateTime.to_iso8601()
|
2020-09-30 20:10:17 +00:00
|
|
|
|
2021-09-17 18:20:44 +00:00
|
|
|
tag :meta, property: "article:published_time", content: content
|
|
|
|
end
|
2020-09-30 20:10:17 +00:00
|
|
|
|
2021-09-17 18:20:44 +00:00
|
|
|
def published_tag(_, _, _) do
|
|
|
|
nil
|
|
|
|
end
|
2021-10-19 19:28:25 +00:00
|
|
|
|
|
|
|
def preview_image_tags(_conn, %{post: post}) do
|
|
|
|
url = SocialMediaPreview.url({"original.png", post}, :original)
|
|
|
|
|
|
|
|
[
|
|
|
|
tag(:meta, itemprop: "image", content: url),
|
|
|
|
tag(:meta, name: "twitter:image:src", content: url),
|
|
|
|
tag(:meta, property: "og:image", content: url)
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def preview_image_tags(_, _) do
|
|
|
|
nil
|
|
|
|
end
|
2020-07-30 16:05:09 +00:00
|
|
|
end
|