Skip to content
Snippets Groups Projects
Commit 6d362e79 authored by Jorin's avatar Jorin
Browse files

Make emoji_from_file handle missing and empty files

parent ae5beb7b
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -104,24 +104,28 @@ defmodule Pleroma.Formatter do
[]
end)
@emoji_from_file (with {:ok, default} <- File.read("config/emoji.txt") do
custom =
with {:ok, custom} <- File.read("config/custom_emoji.txt") do
custom
else
_e -> ""
end
(default <> "\n" <> custom)
|> String.trim()
|> String.split(~r/\n+/)
|> Enum.map(fn line ->
[name, file] = String.split(line, ~r/,\s*/)
{name, file}
end)
else
_ -> []
end)
@emoji_from_file (graceful_text_extract = fn
{:ok, custom} -> custom
{:error, :enoent} -> ""
# Only handles non-existent files nicely!
end
graceful_file_extract = fn (filename) ->
filename |> File.read |> graceful_text_extract.()
end
default = graceful_file_extract.("config/emoji.txt")
custom = graceful_file_extract.("config/custom_emoji.txt")
default <> "\n" <> custom # Add a newline in between in case default doesn't end with \n
|> String.split("\n")
|> Enum.filter(fn (line) -> line != "" end) # Strip newlines
|> Enum.map(fn (line) ->
# Split each line by commas, then remove whitespace around the resulting strings
line
|> String.split(",")
|> Enum.map(fn (str) -> String.strip str end)
end))
@emoji_from_globs (
static_path = Path.join(:code.priv_dir(:pleroma), "static")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment