Skip to content

Commit 4269034

Browse files
committed
book2: match ebook release assets by name, not content-type
Since progit2 2.1.309 switched to using a GitHub Action to generate releases, it no longer sets the content-type field of the release assets. And thus we fail to find any ebooks to link, since we are looking for assets with "application/pdf", and so on. Instead, let's do a suffix match against the name of each asset, looking for the appropriate file extension. This works fine, since the names are all obvious ("progit.epub", and so on). And it should be backwards-compatible with older translations that haven't yet picked up the new Actions-based workflow, since they used the same sensible names. We may revert this later if the assets start generating with correct content-types again. But it looks to be non-trivial (there's some discussion in #1498), so this seems like a good solution in the meantime.
1 parent 1b9b54d commit 4269034

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/tasks/book2.rake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,17 @@ task remote_genbook2: :environment do
222222

223223
begin
224224
rel = @octokit.latest_release(repo)
225-
get_url = -> (content_type) do
226-
asset = rel.assets.find { |asset| asset.content_type==content_type }
225+
get_url = -> (name_re) do
226+
asset = rel.assets.find { |asset| name_re.match(asset.name) }
227227
if asset
228228
asset.browser_download_url
229229
else
230230
nil
231231
end
232232
end
233-
book.ebook_pdf = get_url.call("application/pdf")
234-
book.ebook_epub = get_url.call("application/epub+zip")
235-
book.ebook_mobi = get_url.call("application/x-mobipocket-ebook")
233+
book.ebook_pdf = get_url.call(/\.pdf$/)
234+
book.ebook_epub = get_url.call(/\.epub$/)
235+
book.ebook_mobi = get_url.call(/\.mobi$/)
236236
rescue Octokit::NotFound
237237
book.ebook_pdf = nil
238238
book.ebook_epub = nil

0 commit comments

Comments
 (0)