epub-maker

1.2.0 • Public • Published

MIT License Build Status Code Climate Codacy Badge

js-epub-maker

js-epub-maker allows you to create and download epubs. It offers an API through which you can set meta info, navigation and content. js-epub-maker works by gutting IDPF's sample epub and refitting it with your content. The source epub this project is working with is The Waste Land (source code).

DEMO

API: Sections

There is some API to set all the meta-data, but the magic is in the way you can add sections. With sections you can add either all content with just one section, or finetune all the content so that it snugly fits the epub spec (with the various epub types described in the spec) and more importantly allows you to indicate exactly what should be included in the TOC and Landmarks section of the epub. You don't need to take care of all that, js-epub-maker will do that for you.

/**
 * @epubType Optional. Allows you to add specific epub type content such as [epub:type="titlepage"]
 * @id Optional, but required if section should be included in toc and / or landmarks
 * @content Optional. Should not be empty if there will be no subsections added to this section. Format: { title, content }
 */
EpubMaker.Section = function(epubType, id, content, includeInToc, includeInLandmarks) {
    ...
}

API example

Taken from the included test page, which is reproduced in the online demo.

new EpubMaker()
    .withUuid('github.com/bbottema/js-epub-maker::it-came-from::example-using-idpf-wasteland')
    .withTemplate('idpf-wasteland')
    .withAuthor('T. Est')
    .withLanguage('en-GB')
    .withModificationDate(new Date(2015, 8, 7))
    .withRights({
     description: 'This work is shared with the public using the Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license.',
     license: 'http://creativecommons.org/licenses/by-sa/3.0/'
    })
    .withAttributionUrl('https://github.com/bbottema/js-epub-maker')
    .withStylesheetUrl('src/test/content-for-epub/extra_styles.css')
    .withCover('src/test/content-for-epub/js-epub-maker-cover.jpg', {
     license: 'http://creativecommons.org/licenses/by-sa/3.0/',
     attributionUrl: 'http://www.webestools.com/web20-title-generator-logo-title-maker-online-web20-effect-reflect-free-photoshop.html'
    })
    .withTitle('It Came From... [Example Using Waste Land Template]')
    .withSection(new EpubMaker.Section('frontmatter', 'frontmatter', { title: 'Title page' }, false, true)
        .withSubSection(new EpubMaker.Section('titlepage', 'manuscript-header', header, false, false))
    )
    .withSection(new EpubMaker.Section('bodymatter', 'bodymatter', { title: 'Start of the story' }, false, true)
        .withSubSection(new EpubMaker.Section('preface', 'preface', preface, true, false))
        .withSubSection(new EpubMaker.Section('part', 'part-1', { title: 'Part 1' }, true, false)
            .withSubSection(new EpubMaker.Section('chapter', 'chapter-1', ch1, true, false))
            .withSubSection(new EpubMaker.Section('chapter', 'chapter-2', ch2, true, false))
        )
        .withSubSection(new EpubMaker.Section('part', 'part-2', { title: 'Part 2' }, true, false)
            .withSubSection(new EpubMaker.Section('chapter', 'chapter-3', ch3, true, false))
            .withSubSection(new EpubMaker.Section('chapter', 'chapter-4', ch4, true, false))
        )
    )
    .withSection(new EpubMaker.Section('backmatter', 'backmatter', { title: 'Notes and rest' }, false, true)
        .withSubSection(new EpubMaker.Section('rearnotes', 'rear-notes', { title: 'Notes on "It Came From"' }, true, false)
            .withSubSection(new EpubMaker.Section('rearnote', 'rearnote-1', rn1, false, false))
            .withSubSection(new EpubMaker.Section('rearnote', 'rearnote-2', rn2, false, false))
        )
    )
    .downloadEpub();

Package Sidebar

Install

npm i epub-maker

Weekly Downloads

1

Version

1.2.0

License

MIT

Last publish

Collaborators

  • bbottema