defmodule Lain.LinkLog do alias Lain.Markdown use Phoenix.Component import Phoenix.LiveViewTest, only: [rendered_to_string: 1] def run(path) do links = links(path) make_feed(links) links |> make_index() |> Lain.write_page() end def links(path) do link_path = Path.join(path, "link-log.yaml") YamlElixir.read_from_file!(link_path) end def make_feed(links) do links = Enum.take(links, 10) assigns = %{links: links} body = EEx.eval_string( """ pre.hn - Links Robert Prehn's Link Log https://pre.hn/link-log/ https://pre.hn/link-log/feed.rss <%= for link <- @links do %> <%= Map.get(link, "emoji", "🔗") %> <%= HtmlSanitizeEx.strip_tags(link["name"]) %> <%= Lain.Markdown.render(link["summary"]) %> ]]> tag:pre.hn,<%= link["url"] %> <%= link["url"] %> <% end %> """, assigns: assigns ) path = Path.join(["priv", "static", "link-log", "feed.rss"]) File.write!(path, body) end def make_index(links) do assigns = %{links: links} body = ~H""" <%= for link <- @links do %>
<%= link["emoji"] || "🔗"%> <%= link["name"] %>
<% end %> """ |> rendered_to_string() %{ title: "Link Log", slug: "link-log", date: "2024-03-07", body: body } end end