Skip to content

Commit

Permalink
resolves #307 add series metadata (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
slonopotamus committed Mar 4, 2020
1 parent 09b7b76 commit 1861d96
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
* add xref ids to paragraphs (#317)
* support syntax highlighting with CodeRay and Rouge (#262)
* pygments.rb is no longer auto-activated
* add series metadata (#307)

== 1.5.0.alpha.14 (2020-02-29) - @slonopotamus

Expand Down
4 changes: 4 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ The recommended practice is to identify the referenced resource by means of a st
|An optional override of the properties attribute for this document's item in the manifest.
_Only applies to a chapter document._

|series-name, series-volume, series-id
|Populates the series statements (`belongs-to-collection`) in the package metadata.
Volume is a number, ID probably a UUID that is constant for all volumes in the series.

|epub3-frontmatterdir
|The path to a directory that contains frontmatter files. The file names must match `front-matter*.html` and will be included in alphabetic order. The files are expected to be valid EPUB HTML files. _If only one front matter page is
required, the default 'front-matter.html' file can be used instead._
Expand Down
2 changes: 2 additions & 0 deletions data/samples/sample-book.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
= Asciidoctor Playground: Sample Content
Sarah White <https://github.com/graphitefriction[@graphitefriction]>
v1.0, 2014-04-15
:series-name: Asciidoctor EPUB3 Series
:series-volume: 2
:doctype: book
:producer: Asciidoctor
:keywords: Asciidoctor, samples, e-book, EPUB3, KF8, MOBI, Asciidoctor.js
Expand Down
14 changes: 13 additions & 1 deletion lib/asciidoctor-epub3/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@ def convert_document node
@book.metadata.add_metadata 'subject', s
end

if node.attr? 'series-name'
series_name = node.attr 'series-name'
series_volume = node.attr 'series-volume', 1
series_id = node.attr 'series-id'

series_meta = @book.metadata.add_metadata 'meta', series_name, id: 'pub-collection', group_position: series_volume
series_meta['property'] = 'belongs-to-collection'
series_meta.refine 'dcterms:identifier', series_id unless series_id.nil?
# Calibre only understands 'series'
series_meta.refine 'collection-type', 'series'
end

add_cover_image node
add_front_matter_page node

Expand Down Expand Up @@ -373,7 +385,7 @@ def add_chapter node
<body>
<section class="chapter" title="#{doctitle_sanitized.gsub '"', '&quot;'}" epub:type="chapter" id="#{docid}">
#{header}
#{content})
#{content})

unless (fns = node.document.footnotes - @footnotes).empty?
@footnotes += fns
Expand Down
15 changes: 15 additions & 0 deletions spec/converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,20 @@
expect(book.publisher).not_to be_nil
expect(book.publisher.content).to eq('MyProducer')
end

it 'adds book series metadata' do
book = to_epub <<~EOS
= Article
:series-name: My Series
:series-volume: 42
:series-id: bla
EOS
meta = book.metadata.meta_list[1]
expect(meta).not_to be_nil
expect(meta['property']).to eq('belongs-to-collection')
expect(meta.content).to eq('My Series')
expect(meta.refiner('group-position').content).to eq('42')
expect(meta.refiner('dcterms:identifier').content).to eq('bla')
end
end
end

0 comments on commit 1861d96

Please sign in to comment.