Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I tell the version using the publicationParser (e.g. EPUB 2 vs. EPUB 3)? #53

Open
jdempcy opened this issue Sep 29, 2022 · 1 comment

Comments

@jdempcy
Copy link

jdempcy commented Sep 29, 2022

I see that you can get the version from the OPF, but that requires passing in a zip. We are currently using r2-shared-js and already have the publicationParser working (it works great! So thanks for that!). But we would like to be able to tell if it's an EPUB 2 or EPUB 3 or higher, just from the publicationParser.

Here is an excerpt of what we are doing:

        const pub = await publicationParser.PublicationParsePromise(path);

        if (typeof pub.Metadata.Title === "string") {
            bookTitle = pub.Metadata.Title;
            coverUrl = pub.GetCover()?.Href || '';
            manifest = serializable.TaJsonSerialize(pub);

            const zipInternal = pub.findFromInternal("zip");
            if (!zipInternal) {
                throw new Error("There is no publication zip!");
            }

It would be nice if we could check, for instance. pub.Version and be able to tell the EPUB version. Is there another way to do this?

Thanks!
Jonah

@danielweck
Copy link
Member

Hi Jonah, this might be useful to you, but the information would need to be hoisted up into the publication object:

const getEpubVersion = (rootfile: Rootfile, opf: OPF): string | undefined => {
if (rootfile.Version) {
return rootfile.Version;
} else if (opf.Version) {
return opf.Version;
}
return undefined;
};
export const isEpub3OrMore = (rootfile: Rootfile, opf: OPF): boolean => {
const version = getEpubVersion(rootfile, opf);
return (version === epub3 || version === epub301 || version === epub31);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants