canner-core
Description
Core components of the Canner, including init, build, watch, allin and read API.
About Canner
A static webpage generator based on template engines, which aimed to deal with the maintenance difficulties between data and webpages.
We isolate all the text from files so people can maintain their websites more easily, we also work hard on lower the barriers for different fields of people to collaborate with ease.
API
Env
if you want to send request to localhost, run export CANNER_ENV='dev'
require
var canner= ;
Init
Create initial files and folders, under a directory.
return a promise
canner;
parameters
- {string} dir - directory install canner
- {string} generator - Inital generate the generator that you are finding
Build
Build a canner from a canner.json
return a promise
canner;;
parameters
- {string} dir - source to canner.json, default ./canner.json
- {object} options
- output- output dir
- engine- Your template engine
- data- if you want to put your own object intead of data in canner.json, and return html back, instead of write to file
watch
Watching any changes in a canner and recompiled
return a promise
usage
canner
parameters
serve
the directory you want to watch
watchCallback
everytime we call build
in watch
, we'll call watchCallback
after build
finish
reloader
if you give us object in canner.watch
parameters, we'll need a reloader
to reload the object
reloader example
{var obj = JSON;var posts = objposts;var post_layout = objpost_settingslayout;var post_root_path = objpost_settingspath;if!_posts = posts;posts = _return posts}
file operation filters
file operation filters are called after we reload the settings, and we'll filter the datas using the filter. we keep the data row if filter return true, else we delete the row
how filter work
for example, this function first see if the extenstion of changed file is .md
if true, it will compare changed file path with the markdown file in row.data
{// if md equals, return trueifpath=='.md'return f==path}
createFilter(row, f, stat)
called when a file is created
parameters
row
means the data row you currenly compared withf
is the filename of file createdstat
is stat of file created
changeFilter(row, f, curr, prev)
called when a file is created
parameters
curr
is the current file statprev
is the previous file stat
removeFilter(row, f, stat)
called when a file is removed
allin
Make html include files all warp allin
canner;
parameters
- {string} htmlfile - source to your html, default ./index.html
- {object} options
- filename {String} Output html file name, default to output.html
- output {String} Path to output directory, defaults to current directory
- minifyall {Boolean}- minify css, html, js, images or not
Create
Create a canner.json from hbs_file
return a promise
usage
canner;;
parameters
- {string} dir - source to hbs_file, default ./index.hbs
- {object} options