summaryrefslogtreecommitdiff
path: root/lib/lsg_web/controllers/irc_controller.ex
diff options
context:
space:
mode:
authorhref <href@random.sh>2021-09-02 07:05:42 +0200
committerhref <href@random.sh>2021-09-02 07:05:42 +0200
commitd14408c7e054619f2648eb0480fe55f60397e8c2 (patch)
tree077c0e0ecc33b7a1e4fa00023325db54f3cd40e8 /lib/lsg_web/controllers/irc_controller.ex
parentexirc fork: use git repo (diff)
txt: don't search in files with dot, display them below in web
Diffstat (limited to 'lib/lsg_web/controllers/irc_controller.ex')
-rw-r--r--lib/lsg_web/controllers/irc_controller.ex34
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/lsg_web/controllers/irc_controller.ex b/lib/lsg_web/controllers/irc_controller.ex
index 317bb27..9ddeefc 100644
--- a/lib/lsg_web/controllers/irc_controller.ex
+++ b/lib/lsg_web/controllers/irc_controller.ex
@@ -19,19 +19,19 @@ defmodule LSGWeb.IrcController do
end
def txt(conn, %{"name" => name}) do
- case String.split(name, ".", parts: 2) do
- [name, "txt"] ->
- data = data()
- if Map.has_key?(data, name) do
- lines = Enum.join(data[name], "\n")
- text(conn, lines)
- else
- conn
- |> put_status(404)
- |> text("Not found")
- end
- _ ->
- do_txt(conn, name)
+ if String.contains?(name, ".txt") do
+ name = String.replace(name, ".txt", "")
+ data = data()
+ if Map.has_key?(data, name) do
+ lines = Enum.join(data[name], "\n")
+ text(conn, lines)
+ else
+ conn
+ |> put_status(404)
+ |> text("Not found")
+ end
+ else
+ do_txt(conn, name)
end
end
def txt(conn, _), do: do_txt(conn, nil)
@@ -40,10 +40,12 @@ defmodule LSGWeb.IrcController do
defp do_txt(conn, nil) do
doc = LSG.IRC.TxtPlugin.irc_doc()
data = data()
- lines = Enum.reduce(data, 0, fn({_, lines}, acc) -> acc + Enum.count(lines) end)
+ main = Enum.filter(data, fn({trigger, _}) -> !String.contains?(trigger, ".") end) |> Enum.into(Map.new)
+ system = Enum.filter(data, fn({trigger, _}) -> String.contains?(trigger, ".") end) |> Enum.into(Map.new)
+ lines = Enum.reduce(main, 0, fn({_, lines}, acc) -> acc + Enum.count(lines) end)
conn
|> assign(:title, "txt")
- |> render("txts.html", data: data, doc: doc, files: Enum.count(data), lines: lines)
+ |> render("txts.html", data: main, doc: doc, files: Enum.count(main), lines: lines, system: system)
end
defp do_txt(conn, txt) do
@@ -75,7 +77,7 @@ defmodule LSGWeb.IrcController do
|> Enum.reduce(%{}, fn(path, m) ->
path = String.split(path, "/")
file = List.last(path)
- [key, "txt"] = String.split(file, ".", parts: 2)
+ key = String.replace(file, ".txt", "")
data = dir <> file
|> File.read!
|> String.split("\n")