Skip to content

Commit

Permalink
added epub support
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Nov 16, 2019
1 parent c04661b commit ca843dd
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class Directory {

const directories: string[] = await glob(directoriesPattern, {
ignore: [
'**/*.{crt,drc,glb,gltf,gz,stl,jpg,jpeg,json,md,mp3,mp4,nii,obj,pdf,ply,png,yml}', // ignore files (must include file extensions explicitly, otherwise directories with a . are matched)
'**/*.{crt,drc,epub,glb,gltf,gz,stl,jpg,jpeg,json,md,mp3,mp4,nii,obj,opf,pdf,ply,png,yml}', // ignore files (must include file extensions explicitly, otherwise directories with a . are matched)
'**/_*' // ignore canvas folders
]
});
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "biiif",
"version": "0.3.23",
"version": "0.3.24",
"description": "A CLI to build IIIF collections",
"main": "index.js",
"repository": {
Expand Down
107 changes: 95 additions & 12 deletions test/tests/epub-collection.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
const common = require("../common");
const assert = common.assert;
const build = common.build;
const urljoin = common.urljoin;
const Utils = common.Utils;

let manifestJson, canvasJson, annotation, annotationPage, annotationBody;
const manifest = '/epub-collection';
const epubCollectionUrl = 'http://test.com/epub-collection';
const collection = '/epub-collection';
const collectionUrl = 'http://test.com/epub-collection';

it('can build epub collection', async () => {
assert(await Utils.fileExists(manifest));
return build(manifest, epubCollectionUrl);
assert(await Utils.fileExists(collection));
return build(collection, collectionUrl);
}).timeout(1000); // should take less than a second

it('can find manifest index.json', async () => {
it('can find collection index.json', async () => {
const file = '/epub-collection/index.json';
assert(await Utils.fileExists(file));
manifestJson = await Utils.readJson(file);
collectionJson = await Utils.readJson(file);
});

describe('painting opf', async () => {

let manifest = '/alice-in-wonderland';
let manifestJson, canvases;

it('can find ' + manifest + ' index.json', async () => {
const file = urljoin(collection, manifest, 'index.json');
assert(await Utils.fileExists(file));
manifestJson = await Utils.readJson(file);
canvases = manifestJson.items;
assert(canvases.length === 1);
});

it('can find canvas', async () => {
canvasJson = manifestJson.items[0];
assert(canvasJson);
});

it('has correct canvas id', async () => {
assert(canvasJson.id === epubCollectionUrl + '/index.json/canvas/0');
assert(canvasJson.id === collectionUrl + manifest + '/index.json/canvas/0');
});

it('has correct canvas label', async () => {
Expand All @@ -40,7 +51,7 @@ describe('painting opf', async () => {

it('has the correct annotation page id', async () => {
annotationPage = canvasJson.items[0];
assert(annotationPage.id === epubCollectionUrl + '/index.json/canvas/0/annotationpage/0');
assert(annotationPage.id === collectionUrl + manifest + '/index.json/canvas/0/annotationpage/0');
});

it('has annotation', async () => {
Expand All @@ -49,15 +60,15 @@ describe('painting opf', async () => {
});

it('has correct annotation id', async () => {
assert(annotation.id === epubCollectionUrl + '/index.json/canvas/0/annotation/0');
assert(annotation.id === collectionUrl + manifest + '/index.json/canvas/0/annotation/0');
});

it('has correct annotation motivation', async () => {
assert(annotation.motivation === 'painting');
});

it('has correct annotation target', async () => {
assert(annotation.target === epubCollectionUrl + '/index.json/canvas/0');
assert(annotation.target === collectionUrl + manifest + '/index.json/canvas/0');
});

it('has an annotation body', async () => {
Expand All @@ -70,11 +81,83 @@ describe('painting opf', async () => {
});

it('has correct annotation body type', async () => {
assert(annotationBody.type === 'EBook');
assert(annotationBody.type === 'Text');
});

it('has correct annotation body format', async () => {
assert(annotationBody.format === 'application/oebps-package+xml');
});

});

describe('painting epub', async () => {

let manifest = '/cc-shared-culture';
let manifestJson, canvases;

it('can find ' + manifest + ' index.json', async () => {
const file = urljoin(collection, manifest, 'index.json');
assert(await Utils.fileExists(file));
manifestJson = await Utils.readJson(file);
canvases = manifestJson.items;
assert(canvases.length === 1);
});

it('can find canvas', async () => {
canvasJson = manifestJson.items[0];
assert(canvasJson);
});

it('has correct canvas id', async () => {
assert(canvasJson.id === collectionUrl + manifest + '/index.json/canvas/0');
});

it('has correct canvas label', async () => {
assert(canvasJson.label['@none'][0] === '_cc-shared-culture');
});

it('has an annotation page', async () => {
annotationPage = canvasJson.items[0];
assert(annotationPage);
});

it('has the correct annotation page id', async () => {
annotationPage = canvasJson.items[0];
assert(annotationPage.id === collectionUrl + manifest + '/index.json/canvas/0/annotationpage/0');
});

it('has annotation', async () => {
annotation = annotationPage.items[0];
assert(annotation);
});

it('has correct annotation id', async () => {
assert(annotation.id === collectionUrl + manifest + '/index.json/canvas/0/annotation/0');
});

it('has correct annotation motivation', async () => {
assert(annotation.motivation === 'painting');
});

it('has correct annotation target', async () => {
assert(annotation.target === collectionUrl + manifest + '/index.json/canvas/0');
});

it('has an annotation body', async () => {
annotationBody = annotation.body;
assert(annotationBody);
});

it('has correct annotation body id', async () => {
assert(annotationBody.id === 'http://test.com/epub-collection/cc-shared-culture/_cc-shared-culture/cc-shared-culture.epub');
});

it('has correct annotation body type', async () => {
assert(annotationBody.type === 'Text');
});

it('has correct annotation body format', async () => {
assert(annotationBody.format === 'application/epub+zip');
});

});

0 comments on commit ca843dd

Please sign in to comment.