Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

epub: fix logo not declared in the OPF manifest #1852

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions lib/ex_doc/formatter/epub/templates/content_template.eex
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,30 @@
<manifest>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav scripted"/>
<item id="cover" href="title.xhtml" media-type="application/xhtml+xml" properties="scripted"/>
<%= for {_title, extras} <- config.extras do %>
<%= for extra <- extras do %>
<item id="<%= URI.encode extra.id %>" href="<%= URI.encode extra.id %>.xhtml" media-type="application/xhtml+xml" properties="scripted"/>
<% end %>
<%= for {_title, extras} <- config.extras, extra <- extras do %>
<item id="<%= URI.encode extra.id %>" href="<%= URI.encode extra.id %>.xhtml" media-type="application/xhtml+xml" properties="scripted"/>
<% end %>
<%= for filter <- [:modules, :tasks] do %>
<%= for node <- nodes[filter] do %>
<item id="<%= URI.encode node.id %>" href="<%= URI.encode node.id %>.xhtml" media-type="application/xhtml+xml" properties="scripted"/>
<% end %>
<%= for filter <- [:modules, :tasks], node <- nodes[filter] do %>
<item id="<%= URI.encode node.id %>" href="<%= URI.encode node.id %>.xhtml" media-type="application/xhtml+xml" properties="scripted"/>
<% end %>
<%= for static_file <- static_files do %>
<item id="<%= static_file_to_id(static_file) %>" href="<%= static_file %>" media-type="<%= media_type(Path.extname(static_file)) %>"/>
<% end %>
<%= if config.cover do %>
<%= if Path.extname(config.cover) == ".png" do %>
<item id="cover-image" href="assets/cover.png" media-type="image/png"/>
<% end %>
<%= if Path.extname(config.cover) == ".jpg" do %>
<item id="cover-image" href="assets/cover.jpg" media-type="image/jpeg"/>
<% end %>
<item id="cover-image" href="assets/cover<%= Path.extname(config.cover) %>" media-type="<%= media_type(Path.extname(config.cover))%>"/>
<% end %>
<%= if config.logo do %>
<item id="logo" href="assets/logo<%= Path.extname(config.logo) %>" media-type="<%= media_type(Path.extname(config.logo))%>"/>
<% end %>
</manifest>
<spine>
<itemref idref="cover"/>
<itemref idref="nav"/>
<%= for {_title, extras} <- config.extras do %>
<%= for extra <- extras do %>
<itemref idref="<%= URI.encode extra.id %>"/>
<% end %>
<% end %>
<%= for filter <- [:modules, :tasks] do %>
<%= for node <- nodes[filter] do %>
<itemref idref="<%= URI.encode node.id %>"/>
<% end %>
<%= for {_title, extras} <- config.extras, extra <- extras do %>
<itemref idref="<%= URI.encode extra.id %>"/>
<% end %>
<%= for filter <- [:modules, :tasks], node <- nodes[filter] do %>
<itemref idref="<%= URI.encode node.id %>"/>
<% end %>
</spine>
</package>
48 changes: 47 additions & 1 deletion test/ex_doc/formatter/epub/templates_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,53 @@ defmodule ExDoc.Formatter.EPUB.TemplatesTest do
:ok
end

describe "module_page" do
describe "content_template/5" do
test "includes logo as a resource if specified in the config" do
nodes = %{modules: [], tasks: []}

content =
[logo: "my_logo.png"]
|> doc_config()
|> Templates.content_template(nodes, "uuid", "datetime", _static_files = [])

assert content =~ ~S|<item id="logo" href="assets/logo.png" media-type="image/png"/>|
end

test "includes cover as a resource if specified in the config" do
nodes = %{modules: [], tasks: []}

content =
[cover: "my_cover.svg"]
|> doc_config()
|> Templates.content_template(nodes, "uuid", "datetime", _static_files = [])

assert content =~ ~S|<meta name="cover" content="cover-image"/>|

assert content =~
~S|<item id="cover-image" href="assets/cover.svg" media-type="image/svg+xml"/>|
end

test "includes modules as a resource" do
module_node = %ExDoc.ModuleNode{
module: XPTOModule,
doc: nil,
id: "XPTOModule",
title: "XPTOModule"
}

nodes = %{modules: [module_node], tasks: []}

content =
Templates.content_template(doc_config(), nodes, "uuid", "datetime", _static_files = [])

assert content =~
~S|<item id="XPTOModule" href="XPTOModule.xhtml" media-type="application/xhtml+xml" properties="scripted"/>|

assert content =~ ~S|<itemref idref="XPTOModule"/>|
end
end

describe "module_page/2" do
test "generates only the module name when there's no more info" do
module_node = %ExDoc.ModuleNode{
module: XPTOModule,
Expand Down
Loading