Skip to content

Commit

Permalink
Record source URL for each item in EPUB.
Browse files Browse the repository at this point in the history
Refer: #14
Use <dc:source> elements in content.opf to record where each item in packed EPUB came from.
Note, because of requirement that "id" attributes must be unique I've prefixed the IDs with "id.".
  • Loading branch information
dteviot committed Nov 7, 2017
1 parent 7f6836c commit 3a8f53d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugin/js/EpubPacker.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ class EpubPacker {
that.appendMetaContent(metadata, opf_ns, "calibre:series", that.metaInfo.seriesName);
that.appendMetaContent(metadata, opf_ns, "calibre:series_index", that.metaInfo.seriesIndex);
}

for(let i of epubItemSupplier.manifestItems()) {
let source = this.createAndAppendChildNS(metadata, dc_ns, "dc:source", i.sourceUrl);
source.setAttributeNS(null, "id", "id." + i.getId());
};
}

addMetaProperty(metadata, element, propName, id, value) {
Expand Down
9 changes: 9 additions & 0 deletions unitTest/UtestEpubPacker.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ test("buildContentOpf", function (assert) {
"<dc:contributor opf:role=\"bkp\">[https://github.com/dteviot/WebToEpub] (ver. unknown)</dc:contributor>"+
"<meta content=\"BakaSeries\" name=\"calibre:series\"/>" +
"<meta content=\"666\" name=\"calibre:series_index\"/>" +
"<dc:source id=\"id.xhtml0000\">http://dummy.com/Title0</dc:source>" +
"<dc:source id=\"id.xhtml0001\">http://dummy.com/Title1</dc:source>" +
"</metadata>"+
"<manifest>"+
"<item href=\"Text/0000_Title0.xhtml\" id=\"xhtml0000\" media-type=\"application/xhtml+xml\"/>" +
Expand Down Expand Up @@ -115,6 +117,8 @@ test("buildEpub3ContentOpf", function (assert) {
"<meta refines=\"#packingTool\" property=\"role\">bkp</meta>" +
"<meta content=\"BakaSeries\" name=\"calibre:series\"/>" +
"<meta content=\"666\" name=\"calibre:series_index\"/>" +
"<dc:source id=\"id.xhtml0000\">http://dummy.com/Title0</dc:source>" +
"<dc:source id=\"id.xhtml0001\">http://dummy.com/Title1</dc:source>" +
"</metadata>"+
"<manifest>"+
"<item href=\"Text/0000_Title0.xhtml\" id=\"xhtml0000\" media-type=\"application/xhtml+xml\"/>" +
Expand Down Expand Up @@ -159,6 +163,9 @@ test("buildContentOpfWithCover", function (assert) {
"<dc:identifier id=\"BookId\" opf:scheme=\"URI\">Dummy UUID</dc:identifier>" +
"<dc:contributor opf:role=\"bkp\">[https://github.com/dteviot/WebToEpub] (ver. unknown)</dc:contributor>"+
"<meta content=\"cover-image\" name=\"cover\"/>" +
"<dc:source id=\"id.cover-image\">http://bp.org/thepic.jpeg</dc:source>" +
"<dc:source id=\"id.xhtml0000\">http://dummy.com/Title0</dc:source>" +
"<dc:source id=\"id.xhtml0001\">http://dummy.com/Title1</dc:source>" +
"</metadata>" +
"<manifest>" +
"<item href=\"Images/0000_thepic.jpeg\" id=\"cover-image\" media-type=\"image/jpeg\"/>" +
Expand Down Expand Up @@ -203,6 +210,8 @@ test("buildContentOpfWithTranslatorAndAuthorFileAs", function (assert) {
"<dc:contributor opf:role=\"bkp\">[https://github.com/dteviot/WebToEpub] (ver. unknown)</dc:contributor>"+
"<meta content=\"BakaSeries\" name=\"calibre:series\"/>" +
"<meta content=\"666\" name=\"calibre:series_index\"/>" +
"<dc:source id=\"id.xhtml0000\">http://dummy.com/Title0</dc:source>" +
"<dc:source id=\"id.xhtml0001\">http://dummy.com/Title1</dc:source>" +
"</metadata>" +
"<manifest>" +
"<item href=\"Text/0000_Title0.xhtml\" id=\"xhtml0000\" media-type=\"application/xhtml+xml\"/>" +
Expand Down

0 comments on commit 3a8f53d

Please sign in to comment.