feat: Add link log
This commit is contained in:
parent
20dcf4f265
commit
3a00fa5487
4 changed files with 102 additions and 1 deletions
|
@ -44,7 +44,7 @@ defmodule PreDotHn do
|
|||
|> Enum.map(&validate/1)
|
||||
|> Enum.filter(fn
|
||||
{:error, error} ->
|
||||
Logger.warn(error)
|
||||
Logger.warning(error)
|
||||
|
||||
false
|
||||
|
||||
|
@ -59,6 +59,8 @@ defmodule PreDotHn do
|
|||
make_sitemap(posts)
|
||||
index = make_index(posts)
|
||||
|
||||
PreDotHn.LinkLog.run()
|
||||
|
||||
Enum.map([index | posts], &write_page/1)
|
||||
end
|
||||
|
||||
|
@ -105,6 +107,7 @@ defmodule PreDotHn do
|
|||
<description>Robert Prehn's personal blog.</description>
|
||||
<link>https://pre.hn</link>
|
||||
<atom:link href="https://pre.hn/feed.rss" rel="self" type="application/rss+xml" />
|
||||
<atom:link href="https://pre.hn/link-log/feed.rss" rel="self" type="application/rss+xml" />
|
||||
|
||||
<%= for post <- @posts do %>
|
||||
<item>
|
||||
|
@ -206,6 +209,7 @@ defmodule PreDotHn do
|
|||
<nav class="block bg-blue text-dark">
|
||||
<a href="/">About Me</a>
|
||||
<a href="/blog">Blog</a>
|
||||
<a href="/link-log">Link Log</a>
|
||||
</nav>
|
||||
"""
|
||||
end
|
||||
|
|
75
lib/pre_dot_hn/link_log.ex
Normal file
75
lib/pre_dot_hn/link_log.ex
Normal file
|
@ -0,0 +1,75 @@
|
|||
defmodule PreDotHn.LinkLog do
|
||||
use Phoenix.Component
|
||||
import Phoenix.LiveViewTest, only: [rendered_to_string: 1]
|
||||
|
||||
def run do
|
||||
links = links()
|
||||
|
||||
make_feed(links)
|
||||
|
||||
links
|
||||
|> make_index()
|
||||
|> PreDotHn.write_page()
|
||||
end
|
||||
|
||||
def links do
|
||||
link_path = Path.join(["site", "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("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
<title>pre.hn - Links</title>
|
||||
<description>Robert Prehn's Link Log</description>
|
||||
<link>https://pre.hn</link>
|
||||
<atom:link href="https://pre.hn/link-log/feed.rss" rel="self" type="application/rss+xml" />
|
||||
|
||||
<%= for link <- @links do %>
|
||||
<item>
|
||||
<title><%= HtmlSanitizeEx.strip_tags(link["name"]) %></title>
|
||||
<description>
|
||||
<%= link["summary"] %>
|
||||
</description>
|
||||
<guid isPermaLink="true"><%= link["url"] %></guid>
|
||||
</item>
|
||||
<% end %>
|
||||
</channel>
|
||||
</rss>
|
||||
""", 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 %>
|
||||
<div style="margin-bottom: 1rem">
|
||||
<a class="text-ellipsis overflow-hidden inline-block" style="max-width: 40ch" href={link["url"]}><%= link["name"] %></a>
|
||||
<%= Earmark.as_html!(link["summary"]) |> Phoenix.HTML.raw() %>
|
||||
</div>
|
||||
<% end %>
|
||||
"""
|
||||
|> rendered_to_string()
|
||||
|
||||
%{
|
||||
title: "Link Log",
|
||||
slug: "link-log",
|
||||
date: "2024-03-07",
|
||||
body: body
|
||||
}
|
||||
end
|
||||
end
|
0
priv/static/link-log/.keep
Normal file
0
priv/static/link-log/.keep
Normal file
22
site/link-log.yaml
Normal file
22
site/link-log.yaml
Normal file
|
@ -0,0 +1,22 @@
|
|||
- url: https://coryd.dev/posts/2024/towards-a-quieter-friendlier-web/
|
||||
name: "Cory Dransfeldt: Towards a quieter, friendlier web"
|
||||
summary: >
|
||||
A series of great principles for a better web! Hear, hear!
|
||||
|
||||
Side note: thanks to Cory for inspiring me to add a link log feed to this site,
|
||||
inspired by his at coryd.dev.
|
||||
- url: https://www.abstractmachines.dev/posts/am013-easy-to-write-code-considered-harmful/
|
||||
name: "Leandro Ostera: AM013 – Easy-to-Write Code Considered Harmful"
|
||||
summary: >
|
||||
Leandro argues that the key to writing readable code is taking implicit context
|
||||
and making it explicit. I agree!
|
||||
|
||||
This is also one reason I love Elixir. Many of the design choices in the language
|
||||
and standard library encourage you to explicitly write what you mean-- even if it
|
||||
is more keystrokes.
|
||||
- url: https://soatok.blog/2024/02/27/the-tech-industry-doesnt-understand-consent/
|
||||
name: "Soatok: The Tech Industry Doesn't Understand Consent"
|
||||
summary: >
|
||||
A brilliant lens for thinking about our relationship with tech products, design,
|
||||
and terms of use. Opt-out "consent" isn't consent at all. "Maybe Later" isn't
|
||||
consent either.
|
Loading…
Reference in a new issue