Packages

Mix tasks and library for converting jpeg, png, etc images to webp

Current section

5 Versions

Jump to

Compare versions

4 files changed
+49 additions
-5 deletions
  @@ -145,7 +145,13 @@ and the following to the layout
145 145 <script type="text/javascript" src="<%= Routes.static_path(@conn, "/js/modernizr_webp.js") %>"></script>
146 146 </html>
147 147 ```
148 + ## Cleanup of old assets
148 149
150 + you can cleanup old webp assets by invoking
151 +
152 + ```elixir
153 + mix webp.delete
154 + ```
149 155 ## Acknowledgements
150 156
151 157 This package is based on the excellent [esbuild](https://github.com/phoenixframework/esbuild) by Wojtek Mach and José Valim.
  @@ -4,9 +4,9 @@
4 4 <<"Mix tasks and library for converting jpeg, png, etc images to webp">>}.
5 5 {<<"elixir">>,<<"~> 1.13">>}.
6 6 {<<"files">>,
7 - [<<"lib">>,<<"lib/tasks">>,<<"lib/tasks/webp.ex">>,<<"lib/priv">>,
8 - <<"lib/priv/webp.bash">>,<<"lib/compresser.ex">>,<<"lib/webp.ex">>,
9 - <<"mix.exs">>,<<"README.md">>]}.
7 + [<<"lib">>,<<"lib/tasks">>,<<"lib/tasks/webp.clean.ex">>,
8 + <<"lib/tasks/webp.ex">>,<<"lib/priv">>,<<"lib/priv/webp.bash">>,
9 + <<"lib/compresser.ex">>,<<"lib/webp.ex">>,<<"mix.exs">>,<<"README.md">>]}.
10 10 {<<"licenses">>,[<<"MIT">>]}.
11 11 {<<"links">>,[{<<"GitHub">>,<<"https://github.com/mithereal/ex_webp">>}]}.
12 12 {<<"name">>,<<"webp">>}.
  @@ -26,4 +26,4 @@
26 26 {<<"optional">>,false},
27 27 {<<"repository">>,<<"hexpm">>},
28 28 {<<"requirement">>,<<"~> 1.0">>}]]}.
29 - {<<"version">>,<<"1.0.0">>}.
29 + {<<"version">>,<<"1.1.0">>}.
  @@ -0,0 +1,38 @@
1 + defmodule Mix.Tasks.Webp.Clean do
2 + @moduledoc """
3 + Cleand webp at path.
4 +
5 + Usage:
6 +
7 + mix webp.delete "/path"
8 + """
9 +
10 + @shortdoc "Cleans webp at path "
11 +
12 + use Mix.Task
13 +
14 + @impl true
15 + def run(path \\ nil) do
16 + images_path =
17 + case is_nil(path) do
18 + true ->
19 + default_phx_path = Path.expand("../priv/static/images", __DIR__)
20 + Application.get_env(:webp, :location, default_phx_path)
21 +
22 + false ->
23 + default_path = Path.expand("../#{path}", __DIR__)
24 + Application.get_env(:webp, :location, default_path)
25 + end
26 +
27 + images_path = images_path <> "/*webp"
28 + System.cmd("rm", [images_path], [])
29 + end
30 +
31 + def run(path, opts) do
32 + default_phx_path = Path.expand("../#{path}", __DIR__)
33 + images_path = Application.get_env(:webp, :location, default_phx_path)
34 +
35 + glob = "#{images_path}/*.webp"
36 + System.cmd("rm", [glob], opts)
37 + end
38 + end
  @@ -1,7 +1,7 @@
1 1 defmodule ExWebp.MixProject do
2 2 use Mix.Project
3 3
4 - @version "1.0.0"
4 + @version "1.1.0"
5 5 @source_url "https://github.com/mithereal/ex_webp"
6 6
7 7 def project do