feat: Add a way to hide sureddits in the overview

This commit is contained in:
Daniel Kempkens 2023-08-17 15:08:10 +02:00
parent e11e13f913
commit 478a328042
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM
7 changed files with 54 additions and 24 deletions

View file

@ -5,7 +5,8 @@ config :bdfr_browser,
chat_directory: System.get_env("BDFR_BROWSER_CHAT_DIRECTORY", "/nonexistant"),
watch_directories: System.get_env("BDFR_BROWSER_WATCH_DIRECTORIES", "true"),
http_ip: to_charlist(System.get_env("BDFR_BROWSER_HTTP_IP", "127.0.0.1")),
http_port: String.to_integer(System.get_env("BDFR_BROWSER_HTTP_PORT", "4040"))
http_port: String.to_integer(System.get_env("BDFR_BROWSER_HTTP_PORT", "4040")),
config_file: YamlElixir.read_from_file!(System.fetch_env!("BDFR_BROWSER_CONFIG_FILE"))
config :bdfr_browser, BdfrBrowser.Repo,
database: System.get_env("BDFR_BROWSER_REPO_DATABASE", "postgres"),

View file

@ -7,7 +7,10 @@ defmodule BdfrBrowser.HTTP.Plug do
plug :dispatch
get "/" do
tpl_args = [subreddits: Subreddit.names() |> Repo.all()]
config_file = Application.fetch_env!(:bdfr_browser, :config_file)
hidden_subreddits = config_file["hidden_subreddits"]
tpl_args = [subreddits: Subreddit.names_without(hidden_subreddits) |> Repo.all()]
content = render_template("index", tpl_args)
conn

View file

@ -14,4 +14,8 @@ defmodule BdfrBrowser.Subreddit do
def names do
from(s in __MODULE__, select: s.name, order_by: [asc: fragment("lower(?)", s.name)])
end
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
end

View file

@ -24,6 +24,7 @@ defmodule BdfrBrowser.MixProject do
{:ecto_sql, "~> 3.10"},
{:postgrex, "~> 0.17"},
{:jason, "~> 1.4"},
{:yaml_elixir, "~> 2.9"},
{:earmark, "~> 1.4"},
{:file_system, "~> 0.2.10"},
{:typed_struct, "~> 0.3.0", runtime: false}

View file

@ -18,4 +18,6 @@
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
"typed_struct": {:hex, :typed_struct, "0.3.0", "939789e3c1dca39d7170c87f729127469d1315dcf99fee8e152bb774b17e7ff7", [:mix], [], "hexpm", "c50bd5c3a61fe4e198a8504f939be3d3c85903b382bde4865579bc23111d1b6d"},
"yamerl": {:hex, :yamerl, "0.10.0", "4ff81fee2f1f6a46f1700c0d880b24d193ddb74bd14ef42cb0bcf46e81ef2f8e", [:rebar3], [], "hexpm", "346adb2963f1051dc837a2364e4acf6eb7d80097c0f53cbdc3046ec8ec4b4e6e"},
"yaml_elixir": {:hex, :yaml_elixir, "2.9.0", "9a256da867b37b8d2c1ffd5d9de373a4fda77a32a45b452f1708508ba7bbcb53", [:mix], [{:yamerl, "~> 0.10", [hex: :yamerl, repo: "hexpm", optional: false]}], "hexpm", "0cb0e7d4c56f5e99a6253ed1a670ed0e39c13fc45a6da054033928607ac08dfc"},
}

43
mix.nix
View file

@ -1,13 +1,10 @@
{ pkgs, lib, beamPackages, overrides ? (x: y: { }) }:
{ lib, beamPackages, overrides ? (x: y: {}) }:
let
buildRebar3 = lib.makeOverridable beamPackages.buildRebar3;
buildMix = lib.makeOverridable beamPackages.buildMix;
buildErlangMk = lib.makeOverridable beamPackages.buildErlangMk;
inherit (pkgs.stdenv) isDarwin;
inherit (pkgs.stdenv) isLinux;
self = packages // (overrides self packages);
packages = with beamPackages; with self; {
@ -138,13 +135,6 @@ let
sha256 = "1p0myxmnjjds8bbg69dd6fvhk8q3n7lb78zd4qvmjajnzgdmw6a1";
};
buildInputs = [ ] ++ lib.optionals isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
CoreFoundation
CoreServices
]) ++ lib.optionals isLinux (with pkgs; [
inotify-tools
]);
beamDeps = [];
};
@ -264,7 +254,32 @@ let
beamDeps = [];
};
};
in
self
yamerl = buildRebar3 rec {
name = "yamerl";
version = "0.10.0";
src = fetchHex {
pkg = "${name}";
version = "${version}";
sha256 = "0vjf9gnchvh4qfykrxf0jw0didvfrx54wdm26z41s1gicclxnsil";
};
beamDeps = [];
};
yaml_elixir = buildMix rec {
name = "yaml_elixir";
version = "2.9.0";
src = fetchHex {
pkg = "${name}";
version = "${version}";
sha256 = "1z4dq1x60a1r0daa0vasqhzw2f8fxmqadl9y4nk9jpkgqpafgc0c";
};
beamDeps = [ yamerl ];
};
};
in self

4
priv/config.yml Normal file
View file

@ -0,0 +1,4 @@
---
hidden_subreddits:
- foo
- bar