it's phosphor icons now

This commit is contained in:
2023-02-14 15:16:19 +01:00
parent 3b4aa3b2a6
commit c807cf0b1a
7166 changed files with 57917 additions and 15043 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,35 +0,0 @@
defmodule Mix.Tasks.Heroicons.Build do
# Builds a new lib/heroicons.ex with bundled icon set.
@moduledoc false
@shortdoc false
use Mix.Task
@target_file "lib/heroicons.ex"
def run(_args) do
vsn = Mix.Tasks.Heroicons.Update.vsn()
svgs_path = Mix.Tasks.Heroicons.Update.svgs_path()
outlined = Path.wildcard(Path.join(svgs_path, "outline/**/*.svg"))
solid = Path.wildcard(Path.join(svgs_path, "solid/**/*.svg"))
mini = Path.wildcard(Path.join(svgs_path, "mini/**/*.svg"))
ordered_icons = outlined ++ solid ++ mini
icons =
Enum.group_by(ordered_icons, &function_name(&1), fn file ->
for path <- file |> File.read!() |> String.split("\n"),
path = String.trim(path),
String.starts_with?(path, "<path"),
do: path
end)
Mix.Generator.copy_template("assets/heroicons.exs", @target_file, %{icons: icons, vsn: vsn},
force: true
)
Mix.Task.run("format")
end
defp function_name(file) do
file |> Path.basename() |> Path.rootname() |> String.split("-") |> Enum.join("_")
end
end

View File

@ -0,0 +1,57 @@
defmodule Mix.Tasks.Phosphoricons.Build do
# Builds a new lib/heroicons.ex with bundled icon set.
@moduledoc false
@shortdoc false
use Mix.Task
@target_file "lib/phosphoricons.ex"
def run(_args) do
vsn = Mix.Tasks.Phosphoricons.Update.vsn()
svgs_path = Mix.Tasks.Phosphoricons.Update.svgs_path()
bold = Path.wildcard(Path.join(svgs_path, "Bold/*.svg"))
duotone = Path.wildcard(Path.join(svgs_path, "Duotone/*.svg"))
fill = Path.wildcard(Path.join(svgs_path, "Fill/*.svg"))
light = Path.wildcard(Path.join(svgs_path, "Light/*.svg"))
regular = Path.wildcard(Path.join(svgs_path, "Regular/*.svg"))
thin = Path.wildcard(Path.join(svgs_path, "Thin/*.svg"))
ordered_icons = bold ++ duotone ++ fill ++ light ++ regular ++ thin
icons = Enum.group_by(ordered_icons, &function_name(&1), &parse_svg(&1))
Mix.Generator.copy_template(
"assets/phosphoricons.exs",
@target_file,
%{icons: icons, vsn: vsn},
force: true
)
Mix.Task.run("format")
end
defp function_name(file) do
file
|> Path.basename()
|> Path.rootname()
|> String.split("-")
|> Enum.join("_")
|> String.replace("_bold", "")
|> String.replace("_duotone", "")
|> String.replace("_fill", "")
|> String.replace("_light", "")
|> String.replace("_thin", "")
end
defp parse_svg(file) do
for path <- file |> File.read!() |> String.replace("><", ">\n<") |> String.split("\n"),
path = String.trim(path),
supported_line?(path) do
path |> String.replace(~r/ stroke="#0+"/, "")
end
end
defp supported_line?(path),
do: String.starts_with?(path, "<path") || String.starts_with?(path, "<polyline")
end

View File

@ -1,10 +1,10 @@
defmodule Mix.Tasks.Heroicons.Update do
defmodule Mix.Tasks.Phosphoricons.Update do
# Updates the icon set via download from github.
@moduledoc false
@shortdoc false
@vsn "2.0.13"
@tmp_dir_name "heroicons-elixir"
@vsn "1.4.0"
@tmp_dir_name "phosphoricons-elixir"
# Updates the icons in the assets/icons directory
@ -19,12 +19,14 @@ defmodule Mix.Tasks.Heroicons.Update do
def run(_args) do
version = @vsn
tmp_dir = Path.join(System.tmp_dir!(), @tmp_dir_name)
svgs_dir = Path.join([tmp_dir, "heroicons-#{version}", "optimized"])
svgs_dir = Path.join([tmp_dir, "SVGs"])
File.rm_rf!(tmp_dir)
File.mkdir_p!(tmp_dir)
url = "https://github.com/tailwindlabs/heroicons/archive/refs/tags/v#{version}.zip"
url =
"https://github.com/phosphor-icons/homepage/releases/download/v#{version}/phosphor-icons.zip"
archive = fetch_body!(url)
case unpack_archive(".zip", archive, tmp_dir) do
@ -35,24 +37,11 @@ defmodule Mix.Tasks.Heroicons.Update do
# Copy icon styles, mini, outline and solid, to priv folder
svgs_dir
|> File.ls!()
|> Enum.each(fn size ->
case size do
"20" ->
copy_svg_files(Path.join([svgs_dir, size, "solid"]), "mini")
"24" ->
Path.join(svgs_dir, size)
|> File.ls!()
|> Enum.each(fn style -> copy_svg_files(Path.join([svgs_dir, size, style]), style) end)
_ ->
true
end
end)
|> Enum.each(fn weight -> copy_svg_files(Path.join([svgs_dir, weight]), weight) end)
end
defp copy_svg_files(src_dir, style) do
dest_dir = Path.join(svgs_path(), style)
defp copy_svg_files(src_dir, weight) do
dest_dir = Path.join(svgs_path(), weight)
File.rm_rf!(dest_dir)
File.mkdir_p!(dest_dir)
File.cp_r!(src_dir, dest_dir)
@ -60,7 +49,7 @@ defmodule Mix.Tasks.Heroicons.Update do
defp fetch_body!(url) do
url = String.to_charlist(url)
Logger.debug("Downloading heroicons from #{url}")
Logger.debug("Downloading phosphoricons from #{url}")
{:ok, _} = Application.ensure_all_started(:inets)
{:ok, _} = Application.ensure_all_started(:ssl)

51392
lib/phosphoricons.ex Normal file

File diff suppressed because it is too large Load Diff