Skip to content

Instantly share code, notes, and snippets.

@rgchris
Last active December 31, 2021 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgchris/14e4ce92b1830f8295a1824cbe1628a7 to your computer and use it in GitHub Desktop.
Save rgchris/14e4ce92b1830f8295a1824cbe1628a7 to your computer and use it in GitHub Desktop.
Build a minimal EPUB in R3C
#!/usr/local/bin/ren-r3c
Rebol [
Title: "Package a Minimal eBook"
Date: 5-Feb-2019
Author: "Christopher Ross-Gill"
Rights: http://opensource.org/licenses/Apache-2.0
Home: https://gist.github.com/rgchris/14e4ce92b1830f8295a1824cbe1628a7
Notes: [
https://ebooks.stackexchange.com/a/1184
{Source of Minimal eBook}
]
]
target: %Test.epub
minimal-epub: [
%mimetype {application/epub+zip}
%META-INF/container.xml {
<?xml version="1.0"?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
}
%OEBPS/content.opf {
<?xml version="1.0" encoding="UTF-8" ?>
<package xmlns="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/" unique-identifier="db-id" version="3.0">
<metadata>
<dc:title id="t1">Title</dc:title>
<dc:identifier id="db-id">isbn</dc:identifier>
<meta property="dcterms:modified">2014-03-27T09:14:09Z</meta>
<dc:language>en</dc:language>
</metadata>
<manifest>
<item id="toc" properties="nav" href="toc.xhtml" media-type="application/xhtml+xml" />
<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml" />
<item id="template_css" href="template.css" media-type="text/css" />
<item id="hello" href="1_hello.xhtml" media-type="application/xhtml+xml" />
</manifest>
<spine toc="ncx">
<itemref idref="hello" />
</spine>
</package>
}
%OEBPS/toc.xhtml {
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<title>toc.xhtml</title>
<link href="template.css" rel="stylesheet" type="text/css" />
</head>
<body>
<nav id="toc" epub:type="toc">
<h1 class="frontmatter">Table of Contents</h1>
<ol class="contents">
<li><a href="1_hello.xhtml">Hello</a></li>
</ol>
</nav>
</body>
</html>
}
%OEBPS/1_hello.xhtml {
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<title>1_hello.xhtml</title>
<link href="template.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
}
%OEBPS/toc.ncx {
<?xml version="1.0" encoding="UTF-8" ?>
<ncx version="2005-1" xml:lang="en" xmlns="http://www.daisy.org/z3986/2005/ncx/">
<head>
<meta name="dtb:uid" content="isbn"/>
<meta name="dtb:depth" content="1"/>
</head>
<docTitle>
<text></text>
</docTitle>
<navMap>
<navPoint id="hello" playOrder="1">
<navLabel><text>cover</text></navLabel>
<content src="1_hello.xhtml" />
</navPoint>
</navMap>
</ncx>
}
%OEBPS/template.css {
h1 {
text-align: center;
}
}
]
zip target map-each part minimal-epub [
switch type of part [
file! [part]
text! [trim/head/tail trim/auto copy part]
]
]
print "----------------------------------"
call/wait/shell spaced ["zipinfo -l" target]
call/wait/shell spaced ["epubcheck" target]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment