skoji / gepub

a generic EPUB library for Ruby : supports EPUB 3
Other
240 stars 42 forks source link

How to set custom metadata? #138

Open bbugh opened 8 months ago

bbugh commented 8 months ago

Hello, 👋 thanks for the gem, it's been helpful for some projects!

I want to add some series and series index metadata information for calibre, but after some hours pouring over the code and digging around with pry, I've still not found a good way to set custom metadata. It needs to look like this:

    <meta name="calibre:series" content="Book Series" />
    <meta name="calibre:series_index" content="6.0" />

The best I came up with was manually hacking it in, which works but isn't pretty:

  book.metadata.add_metadata("meta", "") do |metadata|
    metadata.instance_variable_set(:@attributes, { name:"calibre:series", content: book_series })
  end

  book.metadata.add_metadata("meta", "") do |metadata|
    metadata.instance_variable_set(:@attributes, { name:"calibre:series_index", content: book_number.to_f.to_s })
  end

I would have thought add_metadata would work, but it seems to be very strictly defined to whatever format the refine and output is.

Is there some nicer way to do this via the publicly exposed API?

Thank you!

hfabre commented 5 months ago

I was wondering the same, but after digging into the tests to see how this lib handle cover to get inspiration for my own tool i stumbled across this

So i bet something like this should work :

book.metadata.add_oldstyle_meta(nil, { name: "calibre:series", content: book_series })

Sorry if i'm wrong, i'm not using this gem for now but i probably will, it looks awesome !