defmodule AnnotAtWeb.DocumentComponents do @moduledoc """ Renders a `site.standard.document` record, reading mode. """ use Phoenix.Component import Phoenix.HTML, only: [raw: 1] attr :doc, :map, required: true attr :author, :map, required: true attr :cover_url, :string, default: nil def document(assigns) do ~H"""
{@doc.title}

{@doc.title}

{@author.display_name {@author.display_name || @author.handle}
{tag}
<%= case @doc.content do %> <% {:html, html} -> %> {raw(sanitize(html))} <% _ -> %>

{preview(@doc.text_content)}

<% end %>
""" end defp sanitize(html) do html |> HtmlSanitizeEx.markdown_html() |> String.replace(~r{}, "") end defp preview(nil), do: nil defp preview(text) when byte_size(text) <= 280, do: text defp preview(text), do: String.slice(text, 0, 280) <> "..." defp format_date(%DateTime{} = dt), do: Calendar.strftime(dt, "%B %-d, %Y") end