Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/javiorfo/zig-epub

Minimal Zig library for creating EPUB files
https://github.com/javiorfo/zig-epub

epub epub-library zig zig-library

Last synced: 3 days ago
JSON representation

Minimal Zig library for creating EPUB files

Awesome Lists containing this project

README

        

# zig-epub
*Minimal Zig library for creating EPUB files*

## Caveats
- C libs dependencies: [libzip 1.11.2](https://github.com/nih-at/libzip)
- Required Zig version: **0.13**
- Epub version: `2.0.1`
- This library has been developed on and for `Linux` following open source philosophy.

## Overview
This library will generate an epub with the current compressed files:
- **META-INF/**
- **container.xml**
- **OEBPS/**
- **images/**
- **toc.ncx**
- **content.opf**
- **SomeChapter.xhtml**
- **stylesheet.css**
- **mimetype**

**NOTE:** Only one level of subchapter is available when using Table of Contents at the moment. Ex: Chapter 1 -> Chapter 1.1, Chapter 1.2, etc.

## Usage
- Simple example. More [examples here](https://github.com/javiorfo/zig-epub/tree/master/examples)
```zig
const std = @import("std");
const epub = @import("epub");

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer if (gpa.deinit() != .ok) @panic("leak");
const allocator = gpa.allocator();

var my_epub = epub.Epub.init(allocator, .{
.title = "Flying Circus",
.creator = "Johann Gambolputty",
.identifier = .{
.identifier_type = .UUID,
.value = "d5b2b585-566a-4b9c-9c5d-f99436e3a588",
},
});
defer my_epub.deinit();

var image_paths = [_][]const u8{
"/home/user/Downloads/image.jpg",
"/home/user/Downloads/image2.png",
};

var section = epub.Section.init(allocator, "Chapter 1", .{ .raw = "

Chapter 1

\n

Hello

\n

Chapter 1.1

" });
defer section.deinit();

try my_epub
.setStylesheet(.{ .raw = "body { background-color: #000000 }" })
.setCoverImage(.{ .path = "/home/user/Downloads/cats.jpg", .image_type = .jpg })
.setImages(&image_paths)
.setCover(.{ .raw = "

\"Cover
" })
.addSectionType("Preface", .{ .raw = "

preface

\n" }, .Preface)
.add(section.addToc(.{ .text = "Chapter 1.1", .reference_id = "chapter1.1" }).build())
.addSection("Chapter 2", .{ .raw = "

Chapter 2

\n

Bye

\n" })
.generate("book.epub");
}
```

## Installation
#### In `build.zig.zon`:
```zig
.dependencies = .{
.epub = .{
.url = "https://github.com/javiorfo/zig-epub/archive/refs/heads/master.tar.gz",
// .hash = "hash suggested",
// the hash will be suggested by zig build
},
}
```

#### In `build.zig`:
```zig
const dep = b.dependency("epub", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("epub", dep.module("epub"));

exe.linkLibC();
exe.linkSystemLibrary("zip");
```

---

### Donate
- **Bitcoin** [(QR)](https://raw.githubusercontent.com/javiorfo/img/master/crypto/bitcoin.png) `1GqdJ63RDPE4eJKujHi166FAyigvHu5R7v`
- [Paypal](https://www.paypal.com/donate/?hosted_button_id=FA7SGLSCT2H8G)