Assume packs without emoji.txt only have emoji pictures, unhardcode

unhardcode: remove hardcoded /instance/static and actually use the config option
as it is used in other places.

packs without emoji.txt: these are now assumed to have .png files that
are all emojis, their names are used as shortcodes
This commit is contained in:
Ekaterina Vaartis 2019-04-18 18:04:02 +03:00
commit a141f0807b
3 changed files with 59 additions and 30 deletions

View file

@ -115,11 +115,14 @@ defmodule Mix.Tasks.Pleroma.Emoji do
IO.puts(IO.ANSI.format(["Writing emoji.txt for ", :bright, pack_name]))
common_pack_path = Path.join([
"/", Pleroma.Config.get!([:instance, :static_dir]), "emoji", pack_name
])
emoji_txt_str =
Enum.map(
files,
fn {shortcode, path} ->
"#{shortcode}, /instance/static/emoji/#{pack_name}/#{path}"
"#{shortcode}, #{Path.join(common_pack_path, path)}"
end
)
|> Enum.join("\n")
@ -182,11 +185,8 @@ defmodule Mix.Tasks.Pleroma.Emoji do
cwd: tmp_pack_dir
)
emoji_map =
find_all_emoji(tmp_pack_dir, exts) |>
Enum.map(&Path.relative_to(&1, tmp_pack_dir)) |>
Enum.map(fn f -> {f |> Path.basename() |> Path.rootname(), f} end) |>
Enum.into(%{})
emoji_map = Pleroma.Emoji.make_shortcode_to_file_map(tmp_pack_dir, exts)
File.write!(files_name, Poison.encode!(emoji_map, pretty: true))
@ -219,21 +219,6 @@ defmodule Mix.Tasks.Pleroma.Emoji do
end
defp find_all_emoji(dir, exts) do
Enum.reduce(
File.ls!(dir),
[],
fn f, acc ->
filepath = Path.join(dir, f)
if File.dir?(filepath) do
acc ++ find_all_emoji(filepath, exts)
else
acc ++ [filepath]
end
end
) |> Enum.filter(fn f -> Path.extname(f) in exts end)
end
defp fetch_manifest(from) do
Tesla.get!(from).body |> Poison.decode!()
end