2021-03-19 19:32:18 +00:00
|
|
|
defmodule Legendary.Content.FeedsView do
|
|
|
|
use Legendary.Content, :view
|
2020-07-22 19:22:44 +00:00
|
|
|
use Phoenix.HTML
|
|
|
|
alias Phoenix.HTML
|
|
|
|
alias Phoenix.HTML.Tag
|
2020-08-18 15:49:36 +00:00
|
|
|
|
2021-03-19 19:32:18 +00:00
|
|
|
import Legendary.Content.LayoutView, only: [title: 3, excerpt: 3]
|
2020-07-22 19:22:44 +00:00
|
|
|
|
|
|
|
def gravatar_url_for_email(email) do
|
|
|
|
email
|
|
|
|
|> Kernel.||("noreply@example.com")
|
|
|
|
|> String.trim()
|
|
|
|
|> String.downcase()
|
|
|
|
|> (&(:crypto.hash(:md5, &1))).()
|
|
|
|
|> Base.encode16()
|
|
|
|
|> String.downcase()
|
|
|
|
|> (&("https://www.gravatar.com/avatar/#{&1}")).()
|
|
|
|
end
|
|
|
|
|
|
|
|
def auto_paragraph_tags(string) do
|
|
|
|
string
|
|
|
|
|> Kernel.||("")
|
|
|
|
|> String.split(["\n\n", "\r\n\r\n"], trim: true)
|
|
|
|
|> Enum.map(fn text ->
|
|
|
|
[Tag.content_tag(:p, text |> HTML.raw(), []), ?\n]
|
|
|
|
end)
|
|
|
|
|> HTML.html_escape()
|
|
|
|
end
|
|
|
|
|
|
|
|
def post_class(post) do
|
|
|
|
sticky =
|
|
|
|
if post.sticky do
|
|
|
|
"sticky"
|
|
|
|
end
|
2020-07-24 22:10:50 +00:00
|
|
|
"post post-#{post.id} #{sticky}"
|
2020-07-22 19:22:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def post_topmatter(conn, post) do
|
|
|
|
author =
|
|
|
|
post.author ||
|
2021-03-19 19:32:18 +00:00
|
|
|
%Legendary.Auth.User{
|
2020-07-22 19:22:44 +00:00
|
|
|
email: "example@example.org",
|
|
|
|
display_name: "Anonymous",
|
|
|
|
homepage_url: "#"
|
|
|
|
}
|
|
|
|
assigns = %{post: post, author: author, conn: conn}
|
|
|
|
~E"""
|
|
|
|
<% _ = assigns # suppress unused assigns warning %>
|
|
|
|
<div class="Comment-topmatter">
|
|
|
|
|
|
|
|
<h4>
|
2020-07-24 22:10:50 +00:00
|
|
|
<%= link to: author.homepage_url || "#", rel: "author", class: "p-author h-card" do %>
|
2020-07-22 19:22:44 +00:00
|
|
|
<%= author.display_name %>
|
|
|
|
<%= img_tag gravatar_url_for_email(author.email), alt: "Photo of #{author.display_name}", class: "Gravatar u-photo" %>
|
|
|
|
<% end %>
|
|
|
|
</h4>
|
|
|
|
<h5>
|
|
|
|
<%= link to: Routes.posts_path(conn, :show, post) do %>
|
2020-07-28 15:54:24 +00:00
|
|
|
<time class="dt-published" datetime="<%= post.post %>">
|
|
|
|
<%= post.post |> Timex.format!("%F", :strftime) %>
|
2020-07-22 19:22:44 +00:00
|
|
|
</time>
|
|
|
|
<% end %>
|
|
|
|
</h5>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
def unauthenticated_post?(_conn, post) do
|
2020-07-28 15:54:24 +00:00
|
|
|
post.password == nil || String.length(post.password) == 0
|
2020-07-22 19:22:44 +00:00
|
|
|
end
|
|
|
|
end
|