epub.js icon indicating copy to clipboard operation
epub.js copied to clipboard

book.loaded.metadata returns incomplete metadata when metadata contains multiple of the same element

Open BrianSladek opened this issue 6 years ago • 1 comments

For example, epub metadata can contain multiple creator or language elements, but this library only returns at most one of the creators/languages/subjects/etc. in book.loaded.metadata. parseMetadata in packaging.js currently returns a map of metadata type to string value. It may be better to restructure this to return an array of strings for metadata types that may contain multiple elements.

This epub contains multiple authors and languages, but epubjs only returns one of each -- can be used for testing.

BrianSladek avatar May 15 '19 20:05 BrianSladek

I wasn't able to get the parse method in packaging to work, but here is how I (after a lot of trials and errors) got all of the creators from the package document of the epub. It can of course also be used to get other metadata that book.loaded.metadata doesn't provide.

this.book.archive.getText('/' + this.book.container.packagePath).then((res) => {
        const parser = new DOMParser();
        const opf = parser.parseFromString(res, 'text/xml');
        const creatorElements = opf.getElementsByTagName('dc:creator');
        let creators = [];
        for (let i = 0; i < creatorElements.length; i++) {
          creators.push(creatorElements.item(i).textContent);
        }
        console.log(creators);
 });

SebastianKohler avatar Feb 07 '22 18:02 SebastianKohler