Compare commits

...

3 commits

Author SHA1 Message Date
5397833935
chore: Update deps
All checks were successful
Build / build (push) Successful in 13m47s
2023-10-05 09:57:37 +02:00
71fb71ddb9
feat: Show basic statistics in subreddit date view 2023-10-05 09:56:47 +02:00
a19c4f6a36
feat: Link directly to comments 2023-10-04 20:59:52 +02:00
8 changed files with 43 additions and 14 deletions

View file

@ -21,11 +21,11 @@
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1693611461,
"narHash": "sha256-aPODl8vAgGQ0ZYFIRisxYG5MOGSkIczvu2Cd8Gb9+1Y=",
"lastModified": 1696343447,
"narHash": "sha256-B2xAZKLkkeRFG5XcHHSXXcP7To9Xzr59KXeZiRf4vdQ=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "7f53fdb7bdc5bb237da7fefef12d099e4fd611ca",
"rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4",
"type": "github"
},
"original": {
@ -89,11 +89,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1696009558,
"narHash": "sha256-/1nNL8lCF0gn38XaFyu2ufpWcBFwCDZyYUxdZkM6GxU=",
"lastModified": 1696419054,
"narHash": "sha256-EdR+dIKCfqL3voZUDYwcvgRDOektQB9KbhBVcE0/3Mo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c182df2e68bd97deb32c7e4765adfbbbcaf75b60",
"rev": "7131f3c223a2d799568e4b278380cd9dac2b8579",
"type": "github"
},
"original": {
@ -106,11 +106,11 @@
"nixpkgs-lib": {
"locked": {
"dir": "lib",
"lastModified": 1693471703,
"narHash": "sha256-0l03ZBL8P1P6z8MaSDS/MvuU8E75rVxe5eE1N6gxeTo=",
"lastModified": 1696019113,
"narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3e52e76b70d5508f3cec70b882a29199f4d1ee85",
"rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a",
"type": "github"
},
"original": {

View file

@ -28,6 +28,7 @@ defmodule BdfrBrowser.Comment do
join: p in assoc(c, :post),
join: s in assoc(p, :subreddit),
select: %{
id: c.id,
body: c.body,
children: [],
posted_at: c.posted_at,
@ -51,6 +52,7 @@ defmodule BdfrBrowser.Comment do
join: p in assoc(c, :post),
join: s in assoc(p, :subreddit),
select: %{
id: c.id,
author: c.author,
body: c.body,
children: [],
@ -73,6 +75,7 @@ defmodule BdfrBrowser.Comment do
join: p in assoc(c, :post),
join: s in assoc(p, :subreddit),
select: %{
id: c.id,
author: c.author,
body: c.body,
children: [],

View file

@ -44,7 +44,8 @@ defmodule BdfrBrowser.HTTP.Plug do
tpl_args = [
subreddit: subreddit,
dates: subreddit_record |> Post.date_listing() |> Repo.all()
dates: subreddit_record |> Post.date_listing() |> Repo.all(),
statistics: subreddit |> Subreddit.statistics() |> Repo.all()
]
content = render_template("subreddit", tpl_args)
@ -94,7 +95,8 @@ defmodule BdfrBrowser.HTTP.Plug do
tpl_args = [
subreddit: subreddit_names,
dates: subreddit_records |> Post.date_listing() |> Repo.all()
dates: subreddit_records |> Post.date_listing() |> Repo.all(),
statistics: subreddit_names |> Subreddit.statistics() |> Repo.all()
]
content = render_template("subreddit", tpl_args)

View file

@ -22,4 +22,16 @@ defmodule BdfrBrowser.Subreddit do
def names_without(hidden) do
from(s in __MODULE__, select: s.name, where: s.name not in ^hidden, order_by: [asc: fragment("lower(?)", s.name)])
end
def statistics(subreddit) when is_binary(subreddit), do: statistics([subreddit])
def statistics(subreddits) when is_list(subreddits) do
from(s in __MODULE__,
join: p in assoc(s, :posts),
left_join: c in assoc(p, :comments),
select: {s.name, count(p.id), count(c.id)},
where: s.name in ^subreddits,
group_by: [s.name]
)
end
end

View file

@ -1,4 +1,4 @@
<div style="padding-left: <%= level * 5 %>px; margin-bottom: 2px;">
<div style="padding-left: <%= level * 5 %>px; margin-bottom: 2px;" id="cmt-<%= comment.id %>">
<div class="card">
<div class="card-body" style="padding: 8px;">
<blockquote class="blockquote mb-0" style="font-size: 1rem;">

View file

@ -54,7 +54,9 @@
<footer class="blockquote-footer">
<%= BdfrBrowser.RenderUtils.link_to_user(comment.author) %>,
<a href="/r/<%= comment.subreddit %>/<%= comment.post_date %>/<%= comment.post_id %>"><%= comment.post_title %></a>,
<a href="/r/<%= comment.subreddit %>/<%= comment.post_date %>/<%= comment.post_id %>#cmt-<%= comment.id %>">
<%= comment.post_title %>
</a>,
<a href="/r/<%= comment.subreddit %>/<%= comment.post_date %>/"><%= comment.subreddit %></a>,
<small><%= DateTime.to_iso8601(comment.posted_at) %></small>
</footer>

View file

@ -49,4 +49,12 @@
<% end %>
<% end %>
</div>
<div class="d-grid gap-2 col-12 mx-auto">
<p class="text-secondary">
<%= for {name, post_count, comment_count} <- statistics do %>
<%= name %>: <%= post_count %> Posts; <%= comment_count %> Comments<br />
<% end %>
</p>
</div>
</div>

View file

@ -59,7 +59,9 @@
<%= BdfrBrowser.RenderUtils.comment(comment.body) %>
<footer class="blockquote-footer">
<a href="/r/<%= comment.subreddit %>/<%= comment.post_date %>/<%= comment.post_id %>"><%= comment.post_title %></a>,
<a href="/r/<%= comment.subreddit %>/<%= comment.post_date %>/<%= comment.post_id %>#cmt-<%= comment.id %>">
<%= comment.post_title %>
</a>,
<a href="/r/<%= comment.subreddit %>/<%= comment.post_date %>/"><%= comment.subreddit %></a>,
<small><%= DateTime.to_iso8601(comment.posted_at) %></small>
</footer>