npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bookmaker

v1.2.1

Published

Create books from a folder of markdown files

Downloads

23

Readme

bookmaker

Convert a folder of Markdown files into data ready for a pagemaker book

install

$ npm install bookmaker

usage

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 2
image: images/balloons.png
template: dinosaur
---

This is some markdown

It will be converted to HTML

Take a folder of these with some images and sounds and you can use the following code:

var BookMaker = require('bookmaker')

// the base folder for the book content
var book = BookMaker(__dirname + '/test/book')

// a glob pattern for what .json files to merge into the top level book config
book.loadConfig('*.json', function(err, config){

	// the config is an object containing a merge of the *.json files

})

// a glob pattern for what markdown files to load for pages
book.loadPages('*.md', function(err, pages){

	// pages is an array of objects each representing a page
	pages.forEach(function(page){

		// page has .body .html and .attributes

	})
})

// a combination of getConfig and getPages
book.load('*.json', '*.md', function(err, book){
	// book has a 'pages' property

	// we can write the .json to the dest folder
})

// a glob pattern for the files to copy
book.copyFiles('*.{mp3,ogg}', targetFolder, function(err){
	// the source files have been copied to the target dir
})

// a glob pattern for the images to resize
book.resizeImages('*.{png,jpg,gif}', targetFolder, '600x400', function(err){
	// the source images have been resized and copied to the target dir
})

A simplied version of the above:

var BookMaker = require('bookmaker')

// the base folder for the book content
var book = BookMaker(__dirname + '/test/book')

book.write(__dirname + '/output', {
	config:'*.json',
	pages:'*.md',
	files:'*.{mp3,ogg}',
	images:'*.{png,jpg,gif}',
	imageSize:'600x400'
}, function(){

	// the book has been written to __dirname + '/output'

})

api

var book = BookMaker(src)

Create a new book object passing the folder root for where the markdown pages and other files live

book.loadConfig(glob, callback(err, config){})

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 = BookMaker(src)

book.getConfig('{main,theme}.json', function(err, config){

	// config is main.json and theme.json merged

})

book.loadPages(glob, callback(err, pages){})

Process each markdown file found in the glob and return an array of the JSON objects.

book.load(configGlob, pageGlob, callback(err, book){})

A combo of loadConfig and loadPages that returns a single object that is the config with a 'pages' property

book.copyFiles(glob, targetFolder, done(error){})

Copy a glob of files from the book folder to the targetFolder

book.resizeImages(glob, targetFolder, size, done(error){})

Copy and resize the images in the glob. Size can be a string: '100x100' or an object with 'width' and 'height' properties.

cli

You can also install bookmaker globally and use it as a command line script

$ npm install bookmaker -g
$ bookmaker --help
usage: bookmaker [options] sourcefolder destfolder

options:

  --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

licence

MIT