fix: Handle deprecation of @view_module and @view_template

This commit is contained in:
Robert Prehn 2021-09-26 23:19:49 -05:00
parent 455c6c40c5
commit cd0c307a2d
7 changed files with 33 additions and 17 deletions

View file

@ -6820,7 +6820,7 @@
} }
}, },
"../../../deps/phoenix_html": { "../../../deps/phoenix_html": {
"version": "3.0.0" "version": "3.0.4"
}, },
"node_modules/unicode-match-property-ecmascript": { "node_modules/unicode-match-property-ecmascript": {
"version": "1.0.4", "version": "1.0.4",
@ -8432,7 +8432,7 @@
} }
}, },
"../../../deps/phoenix": { "../../../deps/phoenix": {
"version": "1.5.9", "version": "1.6.0",
"license": "MIT" "license": "MIT"
}, },
"node_modules/esrecurse": { "node_modules/esrecurse": {

View file

@ -1,23 +1,23 @@
<%= live_title_tag title(@view_module, @view_template, assigns) %> <%= live_title_tag title(@conn, assigns) %>
<%= tag :meta, itemprop: "name", content: title(@view_module, @view_template, assigns) %> <%= tag :meta, itemprop: "name", content: title(@conn, assigns) %>
<%= tag :meta, itemprop: "description", content: excerpt(@view_module, @view_template, assigns) %> <%= tag :meta, itemprop: "description", content: excerpt(@conn, assigns) %>
<%= tag :meta, name: "description", content: excerpt(@view_module, @view_template, assigns) %> <%= tag :meta, name: "description", content: excerpt(@conn, assigns) %>
<!-- Twitter Card --> <!-- Twitter Card -->
<%= tag :meta, name: "twitter:card", content: "summary_large_image" %> <%= tag :meta, name: "twitter:card", content: "summary_large_image" %>
<%= tag :meta, name: "twitter:title", content: title(@view_module, @view_template, assigns) %> <%= tag :meta, name: "twitter:title", content: title(@conn, assigns) %>
<%= tag :meta, name: "twitter:description", content: excerpt(@view_module, @view_template, assigns) %> <%= tag :meta, name: "twitter:description", content: excerpt(@conn, assigns) %>
<!-- <meta name="twitter:site" content="@site_handle"> --> <!-- <meta name="twitter:site" content="@site_handle"> -->
<!-- <meta name="twitter:creator" content="@author_handle"> --> <!-- <meta name="twitter:creator" content="@author_handle"> -->
<!-- Facebook / Open Graph --> <!-- Facebook / Open Graph -->
<%= tag :meta, property: "og:title", content: title(@view_module, @view_template, assigns) %> <%= tag :meta, property: "og:title", content: title(@conn, assigns) %>
<%= tag :meta, property: "og:type", content: "article" %> <%= tag :meta, property: "og:type", content: "article" %>
<%= tag :meta, property: "og:description", content: excerpt(@view_module, @view_template, assigns) %> <%= tag :meta, property: "og:description", content: excerpt(@conn, assigns) %>
<%= tag :meta, property: "og:site_name", content: Legendary.I18n.t!("en", "site.title") %> <%= tag :meta, property: "og:site_name", content: Legendary.I18n.t!("en", "site.title") %>
<%= modified_tag(@view_module, @view_template, assigns) %> <%= modified_tag(@conn, assigns) %>
<%= published_tag(@view_module, @view_template, assigns) %> <%= published_tag(@conn, assigns) %>
<!-- <meta property="article:section" content="Article Section" /> --> <!-- <meta property="article:section" content="Article Section" /> -->
<!-- <meta property="article:tag" content="Article Tag" /> --> <!-- <meta property="article:tag" content="Article Tag" /> -->
<!-- <meta property="fb:admins" content="Facebook numberic ID" /> --> <!-- <meta property="fb:admins" content="Facebook numberic ID" /> -->

View file

@ -1,12 +1,16 @@
defmodule AppWeb.LayoutView do defmodule AppWeb.LayoutView do
use AppWeb, :view use AppWeb, :view
def title(conn, assigns), do: title(view_module(conn), view_template(conn), assigns)
def title(view, template, %{post: post}), do: "#{post.title} | #{title(view, template, nil)}" def title(view, template, %{post: post}), do: "#{post.title} | #{title(view, template, nil)}"
def title(_, _, _) do def title(_, _, _) do
Legendary.I18n.t!("en", "site.title") Legendary.I18n.t!("en", "site.title")
end end
def excerpt(conn, assigns), do: excerpt(view_module(conn), view_template(conn), assigns)
def excerpt(_, _, %{post: post}) do def excerpt(_, _, %{post: post}) do
post.excerpt post.excerpt
end end
@ -15,10 +19,14 @@ defmodule AppWeb.LayoutView do
Legendary.I18n.t!("en", "site.excerpt") Legendary.I18n.t!("en", "site.excerpt")
end end
def feed_tag(conn, assigns), do: feed_tag(conn, view_module(conn), view_template(conn), assigns)
def feed_tag(_, _, _, _) do def feed_tag(_, _, _, _) do
nil nil
end end
def modified_tag(conn, assigns), do: modified_tag(view_module(conn), view_template(conn), assigns)
def modified_tag(_, _, %{post: post}) do def modified_tag(_, _, %{post: post}) do
content = content =
post.modified_gmt post.modified_gmt
@ -32,6 +40,8 @@ defmodule AppWeb.LayoutView do
nil nil
end end
def published_tag(conn, assigns), do: modified_tag(view_module(conn), view_template(conn), assigns)
def published_tag(_, _, %{post: post}) do def published_tag(_, _, %{post: post}) do
content = content =
post.date_gmt post.date_gmt

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel> <channel>
<title><%= title(@view_module, @view_template, assigns) %></title> <title><%= title(@conn, assigns) %></title>
<description><%= excerpt(@view_module, @view_template, assigns) %></description> <description><%= excerpt(@conn, assigns) %></description>
<link><%= Legendary.Content.Router.Helpers.url(Legendary.CoreWeb.Endpoint) %></link> <link><%= Legendary.Content.Router.Helpers.url(Legendary.CoreWeb.Endpoint) %></link>
<atom:link href="<%= Legendary.Content.Router.Helpers.url(Legendary.CoreWeb.Endpoint) %><%= @feed_url %>" rel="self" type="application/rss+xml" /> <atom:link href="<%= Legendary.Content.Router.Helpers.url(Legendary.CoreWeb.Endpoint) %><%= @feed_url %>" rel="self" type="application/rss+xml" />

View file

@ -4,9 +4,9 @@
<meta charset="utf-8"/> <meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title><%= title(@view_module, @view_template, assigns) %></title> <title><%= title(@conn, assigns) %></title>
<link phx-track-static rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/> <link phx-track-static rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
<%= feed_tag(@conn, @view_module, @view_template, assigns) %> <%= feed_tag(@conn, assigns) %>
<script phx-track-static defer type="text/javascript" src="<%= Routes.static_path(@conn, "/js/app.js") %>"></script> <script phx-track-static defer type="text/javascript" src="<%= Routes.static_path(@conn, "/js/app.js") %>"></script>
</head> </head>
<body class="text-gray-800 antialiased"> <body class="text-gray-800 antialiased">

View file

@ -2,7 +2,7 @@ defmodule Legendary.Content.FeedsView do
use Legendary.Content, :view use Legendary.Content, :view
use Phoenix.HTML use Phoenix.HTML
import Legendary.Content.LayoutView, only: [title: 3, excerpt: 3] import Legendary.Content.LayoutView, only: [title: 2, excerpt: 2]
def unauthenticated_post?(post) do def unauthenticated_post?(post) do
post.password == nil || String.length(post.password) == 0 post.password == nil || String.length(post.password) == 0

View file

@ -1,6 +1,8 @@
defmodule Legendary.Content.LayoutView do defmodule Legendary.Content.LayoutView do
use Legendary.Content, :view use Legendary.Content, :view
def feed_tag(conn, assigns), do: feed_tag(conn, view_module(conn), view_template(conn), assigns)
def feed_tag(conn, view_module, view_template, assigns) do def feed_tag(conn, view_module, view_template, assigns) do
~E""" ~E"""
<link <link
@ -12,6 +14,8 @@ defmodule Legendary.Content.LayoutView do
""" """
end end
def title(conn, assigns), do: title(view_module(conn), view_template(conn), assigns)
def title(Legendary.Content.PostsView, "index.html", assigns) do def title(Legendary.Content.PostsView, "index.html", assigns) do
"Page #{assigns.page} | #{title(nil, nil, nil)}" "Page #{assigns.page} | #{title(nil, nil, nil)}"
end end
@ -26,6 +30,8 @@ defmodule Legendary.Content.LayoutView do
def title(_, _, _), do: Legendary.I18n.t! "en", "site.title" def title(_, _, _), do: Legendary.I18n.t! "en", "site.title"
def excerpt(conn, assigns), do: excerpt(view_module(conn), view_template(conn), assigns)
def excerpt(Legendary.Content.PostsView, "show.html", assigns) do def excerpt(Legendary.Content.PostsView, "show.html", assigns) do
assigns.post.excerpt assigns.post.excerpt
|> HtmlSanitizeEx.strip_tags() |> HtmlSanitizeEx.strip_tags()