Browse Source

Display topics that have a parent nested in a tree

main
Jeremy Boles 2 weeks ago
parent
commit
ec4804840d
Signed by: jb
GPG Key ID: 7DE0508F61CB57DF
  1. 23
      lib/ann/helpers.ex
  2. 16
      lib/ann/plug.ex
  3. 4
      lib/ann/templates/wiki.html.eex
  4. 12
      priv/static/css/styles.css

23
lib/ann/helpers.ex

@ -1,4 +1,6 @@
defmodule Ann.Helpers do
require EEx
import Geocalc
alias Storala.Journal.Entry
@ -134,12 +136,19 @@ defmodule Ann.Helpers do
|> Enum.reject(&is_nil/1)
end
defp translate_to(%Geo.Point{coordinates: {lng, lat}} = point) do
translate_coords()
|> Enum.find(fn {from, _to} ->
IO.inspect(from, label: "from")
IO.inspect(point, label: "point")
in_area?(from, %{lat: lat, lng: lng})
end)
defp translate_to(%Geo.Point{coordinates: {lng, lat}}) do
translate_coords() |> Enum.find(fn {from, _to} -> in_area?(from, %{lat: lat, lng: lng}) end)
end
@topic_tree """
<%= for {topic, children} <- topics do %>
<li>
<a href="/<%= Storala.Wiki.Topic.get(topic, "slug") %>/"><%= topic.title_html %></a>
<%= if Enum.count(children) > 0 do %>
<ol><%= topic_tree(children) %></ol>
<% end %>
</li>
<% end %>
"""
EEx.function_from_string(:def, :topic_tree, @topic_tree, [:topics])
end

16
lib/ann/plug.ex

@ -44,7 +44,7 @@ defmodule Ann.Plug do
get "/wiki" do
title = "Wiki · Jeremy Boles"
topics = Storala.Wiki.all()
topics = Storala.Wiki.all() |> top_level() |> attach_children()
send_template(conn, Ann.Templates.wiki(%{topics: topics}), %{title: title})
end
@ -57,6 +57,16 @@ defmodule Ann.Plug do
not_found(conn)
end
defp attach_children(topics) do
Enum.map(topics, fn t -> {t, children(t)} end)
end
defp children(%Storala.Wiki.Topic{id: id}) do
Storala.Wiki.all()
|> Enum.filter(fn t -> Storala.Wiki.Topic.get(t, "parent") === id end)
|> attach_children()
end
defp day(%Storala.Journal.Entry{} = entry) do
date = Storala.Journal.Entry.get(entry, "published_at")
location = Storala.Journal.Entry.get(entry, "location")
@ -115,6 +125,10 @@ defmodule Ann.Plug do
send_template(conn, Ann.Templates.topic(%{topic: topic, updates: updates}), %{title: title})
end
defp top_level(topics) do
Enum.filter(topics, fn t -> Storala.Wiki.Topic.get(t, "parent") == nil end)
end
defp truncate(str, length) do
shorter = length - 1

4
lib/ann/templates/wiki.html.eex

@ -3,8 +3,6 @@
<p>Here are all of the topics that I’ve collected information about so far. I thought it would be neat to collect my own thoughts about the things I do and then store them in one place where I can link everything together. Nearly everything on my website is attached to a wiki topic in one way or another.</p>
<ol>
<%= for topic <- local.topics do %>
<li><a href="/<%= Storala.Wiki.Topic.get(topic, "slug") %>/"><%= topic.title_html %></a></li>
<% end %>
<%= topic_tree(local.topics) %>
</ol>
</article>

12
priv/static/css/styles.css

@ -318,11 +318,16 @@ body > main .topic footer > p {
}
/* Wiki */
body > main .wiki ol {
list-style: none;
}
body > main .wiki ol ol {
padding-inline-start: calc(var(--space-x) * 2);
}
body > main .wiki > ol {
column-gap: calc(var(--space-x) * 2);
display: grid;
grid-auto-flow: dense;
grid-template-columns: repeat(auto-fill, 20ch);
/* column-count: 2; */
column-width: 30ch;
list-style: none;
margin-block-start: calc(var(--space-y) * 3);
padding: 0;
@ -336,6 +341,7 @@ body > main .wiki > ol a:hover {
color: var(--color-primary);
}
body > main .wiki > ol li {
break-inside: avoid;
padding: 0;
}

Loading…
Cancel
Save