MfGames Writing
MfGames Writing is a JavaScript (well, TypeScript) tool for creating EPUB and PDF documents out of source files. It can be installed via npm
and uses the Node ecosystem to transform the source files.
I have more detailed introductions, reasons for this library, and how to customize it both on the above link or on my blog.
package.json
MfGames Writing uses the package.json
file to provide things like the name of the project and it's version (it has the ability to put the version in the legal page). Below is a basic shell of that file:
{
"name": "allegro",
"version": "0.41.0",
"private": true,
"description": "\"Allegro\" is a novel by D. Moonfire.",
"author": {
"name": "D. Moonfire"
},
"license": "CC-BY-NC-SA-4.0",
"repository": {
"type": "git",
"url": "git+https://src.mfgames.com/fedran-sources/allegro.git"
},
"homepage": "https://fedran.com/allegro/"
}
One that is set up, you have to install the required packages.
npm install @mfgames-writing/format @mfgames-writing/weasyprint-format @mfgames-writing/epub2-format @mfgames-writing/clean-theme
That sets up the PDF and EPUB format and uses a simplistic theme.
publication.json
The publication.json
file is used to control the formats being generated and where everything is:
{
"metadata": {
"title": "Allegro",
"author": "D. Moonfire",
"language": "en",
"theme": "@mfgames-writing/clean-theme",
"outputDirectory": ".",
"outputFilename": "allegro-{{edition.version}}.{{edition.ext}}"
},
"editions": {
"epub": {
"format": "@mfgames-writing/epub2-format",
"ext": "epub"
},
"pdf": {
"format": "@mfgames-writing/weasyprint-format",
"isbn": "",
"images": {
"grayscale": true,
"opaque": true
},
"ext": "pdf"
}
},
"contents": [
{
"element": "chapter",
"number": 1,
"directory": "src/chapters",
"source": "/^chapter-\\d+.md$/",
"start": true,
"page": 1
]
}
]
}
Automation
Here is the a starting point for Just using MfGames Writing:
build: build-epub build-pdf
build-epub:
mfgames-writing build epub
build-pdf:
mfgames-writing build pdf
With the above components, generating the output would just require running just build
to create it. The resulting files are put into the project root as //allegro-*.pdf
and //allegro-*.epub
.