diff --git a/lib/ex_doc/formatter/epub.ex b/lib/ex_doc/formatter/epub.ex index 0f9136198..94281d99e 100644 --- a/lib/ex_doc/formatter/epub.ex +++ b/lib/ex_doc/formatter/epub.ex @@ -76,11 +76,10 @@ defmodule ExDoc.Formatter.EPUB do defp generate_content(config, nodes, uuid, datetime, static_files) do static_files = - static_files - |> Enum.filter(fn name -> - String.contains?(name, "OEBPS") and config.output |> Path.join(name) |> File.regular?() - end) - |> Enum.map(&Path.relative_to(&1, "OEBPS")) + for name <- static_files, + String.contains?(name, "OEBPS"), + media_type = Templates.media_type(Path.extname(name)), + do: {Path.relative_to(name, "OEBPS"), media_type} content = Templates.content_template(config, nodes, uuid, datetime, static_files) File.write("#{config.output}/OEBPS/content.opf", content) diff --git a/lib/ex_doc/formatter/epub/templates.ex b/lib/ex_doc/formatter/epub/templates.ex index 93facbfeb..7fd10e2f3 100644 --- a/lib/ex_doc/formatter/epub/templates.ex +++ b/lib/ex_doc/formatter/epub/templates.ex @@ -129,11 +129,10 @@ defmodule ExDoc.Formatter.EPUB.Templates do |> Enum.each(fn line -> [extension, media] = String.split(line, ",") - defp media_type("." <> unquote(extension)) do + def media_type("." <> unquote(extension)) do unquote(media) end end) - defp media_type(arg), - do: raise("asset with extension #{inspect(arg)} is not supported by EPUB format") + def media_type(_arg), do: nil end diff --git a/lib/ex_doc/formatter/epub/templates/content_template.eex b/lib/ex_doc/formatter/epub/templates/content_template.eex index de22444f2..ed7b01939 100644 --- a/lib/ex_doc/formatter/epub/templates/content_template.eex +++ b/lib/ex_doc/formatter/epub/templates/content_template.eex @@ -23,14 +23,14 @@ <%= for filter <- [:modules, :tasks], node <- nodes[filter] do %> <% end %> - <%= for static_file <- static_files do %> - + <%= for {static_file, media_type} <- static_files do %> + <% end %> <%= if config.cover do %> - + <% end %> <%= if config.logo do %> -