Add additional options to better support programmatic rendering

This commit is contained in:
Mikito Takada 2015-10-22 21:19:56 -07:00
parent 65da7523a7
commit 3937d4d876
6 changed files with 29 additions and 11 deletions

2
.gitignore vendored
View File

@ -2,4 +2,4 @@ node_modules/
output/*
!output/menu.html
!output/index.html
.DS_Store

View File

@ -7,6 +7,11 @@ var fs = require('fs'),
convertMd = require('./convert-md');
module.exports = function(argv) {
if (!argv.meta) {
// load the metadata file if it exists
argv.meta = fs.existsSync(argv.input + '/meta.json') ? require(argv.input + '/meta.json') : {};
}
return pi.pipeline([
md.parseHeader(),
md.parseMd(),
@ -25,15 +30,12 @@ module.exports = function(argv) {
setOutputPath({
input: argv.input,
output: argv.output,
isSingleFile: argv.isSingleFile
isSingleFile: argv.isSingleFile,
'asset-path': argv['asset-path']
}),
// merge metadata now that relative is set
mergeMeta(
// load the metadata file if it exists
fs.existsSync(argv.input + '/meta.json') ?
require(argv.input + '/meta.json') : {}
),
mergeMeta(argv.meta),
// apply handlebars templates
applyTemplate({

View File

@ -21,7 +21,7 @@ module.exports = function(opts) {
// determine the relative path to ./output/assets
// -- since files can be in subdirs like: sub/sub/dir/index.html
item.assetsRelative = path.relative(outputDir, opts.output + '/assets');
item.assetsRelative = path.relative(outputDir, opts['asset-path'] || opts.output + '/assets');
return item;
});

View File

@ -339,6 +339,9 @@ If any markdown file in `./input/foo/` defines a metadata value called `repoUrl`
- `path` (an absolute path to the input file name),
- `stat` (the fs.stat object associated with the input file),
- `contents` (a string with the content of the input file).
- Since `v3.1.3`, the `pipeline` function supports a couple of arguments that are not exposed on the CLI (in addition to all the CLI args):
- `meta`: a hash of JSON (the contents of a meta.json file if you prefer to set that explicitly)
- `asset-path`: a full path to the `/assets` folder, defaults to `${output}/assets`.
The writable stream returns objects with the same properties, plus any metadata. The pipeline updates `path` to be the output path that generate-md would write the file to, and updates `contents` to be a string of HTML.

View File

@ -177,7 +177,7 @@ describe('integration tests', function() {
setOutputPath({
input: '/fake/input',
output: '/fake/output',
assetDir: '/fake/output/assets/'
'asset-path': '/fake/output/assets/'
}),
applyTemplate(opts),
@ -213,8 +213,8 @@ describe('integration tests', function() {
}, { template: 'a{{> toc}}b' }, function(html) {
assert.equal(html, [
'a<ul class="nav nav-list">',
' <li><a href="#foo">foo</a></li>',
' <li><a href="#bar">bar</a></li>',
' <li class="sidebar-header-1"><a href="#foo">foo</a></li>',
' <li class="sidebar-header-2"><a href="#bar">bar</a></li>',
'</ul>',
'b'
].join('\n'));

13
todo.md
View File

@ -36,3 +36,16 @@
- quiz
- equations
- exercises
- sidebar menu component
- responsive (e.g. top-level hamburger icon on mobile)
- toggleable (e.g. tablet)
- https://dribbble.com/shots/1830513-Tumblr-Free-PSD-Template
- https://dribbble.com/shots/1590417-Portfolio-Review-Page
- scrollable, expanding TOC
- sticky on side
- scrollable on overflow
- expands to match specific targets
- has buttons to expand specific sections
- full site TOC views / helpers ??
- better preview system (e.g. theme switcher, hosted online)