Create books from a folder of markdown files
Convert a folder of Markdown files into data ready for a pagemaker book
$ npm install bookmaker
Each markdown file represents a page of the book and can have front-matter. The values can be used in the book template to show images and play sounds.
An example of a single page .md:
---title: Page 2image: images/balloons.pngtemplate: dinosaur---This is some markdownIt will be converted to HTML
Take a folder of these with some images and sounds and you can use the following code:
var BookMaker =// the base folder for the book contentvar book =// a glob pattern for what .json files to merge into the top level book configbook// a glob pattern for what markdown files to load for pagesbook// a combination of getConfig and getPagesbook// a glob pattern for the files to copybook// a glob pattern for the images to resizebook
A simplied version of the above:
var BookMaker =// the base folder for the book contentvar book =book
Create a new book object passing the folder root for where the markdown pages and other files live
Load an object that is the result of merging the files found in the passed file glob.
This object is the top level of the book - the 'pages' property is populated by the markdown files.
Normally a single json file will be used but you can use a glob to merge multiple configs for one book:
var book =book
Process each markdown file found in the glob and return an array of the JSON objects.
A combo of loadConfig and loadPages that returns a single object that is the config with a 'pages' property
Copy a glob of files from the book folder to the targetFolder
Copy and resize the images in the glob. Size can be a string: '100x100' or an object with 'width' and 'height' properties.
You can also install bookmaker globally and use it as a command line script
$ npm install bookmaker -g$ bookmaker --help
usage: bookmaker [options] sourcefolder destfolderoptions:--config, -c - a glob for the config files--pages, -p - a glob for the .md pages--files, -f - a glob for files to copy--images, -i - a glob for images to resize--imagesize, -s - the size for resized images
$ bookmaker --config "*.json" --pages "*.md" --images "*.jpg" --imagesize 600x400 ./input ./output