ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - milmazz/bupe: BUPE is a Elixir ePub generator and parser (supports EPUB v3)
BUPE is a Elixir ePub generator and parser (supports EPUB v3) - milmazz/bupe
Visit Site

GitHub - milmazz/bupe: BUPE is a Elixir ePub generator and parser (supports EPUB v3)

GitHub - milmazz/bupe: BUPE is a Elixir ePub generator and parser (supports EPUB v3)

BUPE

Module Version Hex Docs Total Download License Last Updated

BUPE is an Elixir ePub generator and parser, it supports EPUB v2 and v3.

Installation

First, add :bupe to your list of dependencies in mix.exs:

def deps do
  [
    {:bupe, "~> 0.6"}
  ]
end

To find out the latest release available on Hex, you can run mix hex.info bupe in your shell, or by going to the bupe page on Hex.pm

Then, update your dependencies:

$ mix deps.get

Usage

Builder

If you want to create an EPUB file you can do the following:

iex(1)> pages = "~/book/*.xhtml" |> Path.expand() |> Path.wildcard()
["/Users/dev/book/bacon.xhtml", "/Users/dev/book/egg.xhtml", "/Users/dev/book/ham.xhtml"]
iex(2)> config = %BUPE.Config{
...(2)>  title: "Sample",
...(2)>  language: "en",
...(2)>  creator: "John Doe",
...(2)>  publisher: "Sample",
...(2)>  pages: pages
...(2)> }
%BUPE.Config{
  audio: [],
  contributor: nil,
  cover: true,
  coverage: nil,
  creator: "John Doe",
  date: nil,
  description: nil,
  fonts: [],
  format: nil,
  identifier: nil,
  images: [],
  language: "en",
  logo: nil,
  modified: nil,
  nav: [],
  pages: ["/Users/dev/book/bacon.xhtml",
   "/Users/dev/book/egg.xhtml",
   "/Users/dev/book/ham.xhtml"],
  publisher: "Sample",
  relation: nil,
  rights: nil,
  scripts: [],
  source: nil,
  styles: [],
  subject: nil,
  title: "Sample",
  type: nil,
  unique_identifier: nil,
  version: "3.0"
}
iex(3)> BUPE.build(config, "sample.epub")
{:ok, '/Users/dev/sample.epub'}

If you prefer, you can build the EPUB document in memory doing the following:

iex(4)> BUPE.build(config, "sample.epub", [:memory])
{:ok,
 {'/Users/dev/sample.epub',
  <<80, 75, 3, 4, 20, 0, 0, 0, 0, 0, 61, 123, 119, 78, 111, 97, 171, 44, 20, 0,
    0, 0, 20, 0, 0, 0, 8, 0, 0, 0, 109, 105, 109, 101, 116, 121, 112, 101, 97,
    112, 112, 108, 105, 99, 97, 116, ...>>}}

If you want to have more control over the pages configuration, instead of passing a list of string, you can provide a list of %BUPE.Item{} like this:

iex(1)> pages = [%BUPE.Item{href: "/Users/dev/book/bacon.xhtml", description: "Ode to Bacon"}]
[
  %BUPE.Item{
    description: "Ode to Bacon",
    duration: nil,
    fallback: nil,
    href: "/Users/dev/book/bacon.xhtml",
    id: nil,
    media_overlay: nil,
    media_type: nil,
    properties: ""
  }
]

The given description will be used in the Table of Contents of EPUB document, otherwise BUPE will provide a default description based on the file name.

If your page include JavaScript, is recommended that you use the properties field from %BUPE.Item{} like this:

iex(2)> pages = [%BUPE.Item{href: "/Users/dev/book/bacon.xhtml", description: "Ode to Bacon", properties: "scripted"}]
[
  %BUPE.Item{
    description: "Ode to Bacon",
    duration: nil,
    fallback: nil,
    href: "/Users/dev/book/bacon.xhtml",
    id: nil,
    media_overlay: nil,
    media_type: nil,
    properties: "scripted"
  }
]

Keep in mind that if you put the scripted property on a page that does not have any JavaScript, you will get warnings from validation tools such as EPUBCheck.

See BUPE.Builder, BUPE.Config, and BUPE.Item for more details.

Using the builder via command line

You can build EPUB documents using the command line as follows:

  1. Install BUPE as an escript:
mix escript.install hex bupe
  1. Then you are ready to use it in your projects:
bupe "EPUB_TITLE" -p egg.xhtml -p bacon.xhtml -l path/to/logo.png

For more details about using the command line tool, review the usage guide:

bupe --help

Parser

If you want to parse an EPUB file you can do the following:

iex> BUPE.parse("sample.epub")
%BUPE.Config{
  audio: nil,
  contributor: nil,
  cover: true,
  coverage: nil,
  creator: "John Doe",
  date: nil,
  description: nil,
  fonts: nil,
  format: nil,
  identifier: "urn:uuid:bc864bda-1a0b-4014-a72f-30f6dc60e120",
  images: nil,
  language: "en",
  logo: nil,
  modified: "2019-03-23T20:22:20Z",
  nav: [
    %{idref: 'cover', linear: 'no'},
    %{idref: 'nav'},
    %{idref: 'pages-ecbedca7-f77e-46b6-8fe2-99718d00c903'},
    %{idref: 'pages-59ad8356-e46d-4328-b7cc-e81af2880c3a'},
    %{idref: 'pages-1d3ee5e3-cf45-4e45-bd79-8a931e293584'}
  ],
  pages: [
    %{
      href: 'nav.xhtml',
      id: 'nav',
      "media-type": 'application/xhtml+xml',
      properties: 'nav'
    },
    %{href: 'title.xhtml', id: 'cover', "media-type": 'application/xhtml+xml'},
    %{
      href: 'content/bacon.xhtml',
      id: 'pages-ecbedca7-f77e-46b6-8fe2-99718d00c903',
      "media-type": 'application/xhtml+xml',
      properties: 'scripted'
    },
    %{
      href: 'content/egg.xhtml',
      id: 'pages-59ad8356-e46d-4328-b7cc-e81af2880c3a',
      "media-type": 'application/xhtml+xml',
      properties: 'scripted'
    },
    %{
      href: 'content/ham.xhtml',
      id: 'pages-1d3ee5e3-cf45-4e45-bd79-8a931e293584',
      "media-type": 'application/xhtml+xml',
      properties: 'scripted'
    }
  ],
  publisher: "Sample",
  relation: nil,
  rights: nil,
  scripts: nil,
  source: nil,
  styles: [%{href: 'css/stylesheet.css', id: 'css', "media-type": 'text/css'}],
  subject: nil,
  title: "Sample",
  type: nil,
  unique_identifier: "BUPE",
  version: "3.0"
}

See BUPE.Parser for more details.

Copyright and License

Copyright 2024 Milton Mazzarri

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory