
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
carver is a static site generator with loads of features.
We know, there are loads of static site generators out there in the node world. But for our use case we needed something highly modularizable and adaptable. this static site generator can:
render plain content files with additional use of middleware processors (such as our pebbles concept)
render (db-)objects with a customizable property (here: 'content')
render (db-)objects iterating through an array of objects containing the content attribute (here: 'translations')
plug in any engine that returns something (jade, swig, ejs, you name em)
plug in any writer defining the destination where the result should go to (works without writer as callback result)
... many more
var carver = require('carver');
Simple example rendering markdown content
carver()
.includeMarkdownEngine()
.render( '# Heading\nFloating text' )
.then( function( html ){
// do something with the html
});
Advanced example parsing the given cwd (working directory) for templatefiles and executes
them. Default is index.<engine>, here index.jade. To change this, use .set('template','mytemplate').
carver()
.includeFileWriter()
.registerEngine('jade', require('jade'))
.set('cwd', __dirname+'/layouts')
.write()
.then( function( compiler ){
console.log('Your webpage has been written to', compiler.finalFilename);
});
Even more advanced example with a before.render-hook enabled, precompiling markdown content
of given doc object. If doc.content is available, it will interpreted as markdown and the
result will be provided as markdownContent to the template..
carver()
.includeFileWriter()
.registerEngine('jade', require('jade'))
.set('cwd', __dirname+'/layouts')
.set('doc', webpage)
.registerHook('before.render', require('carver/plugins').markdownCompiler)
.write()
.then( function( compiler ){
console.log('Your webpage has been written to', compiler.finalFilename);
});
For a working example and to clarify a lot of things, it might be useful to have a look at
https://github.com/caminio/carver-example.git
npm install carver
carver is chainable. You just add settings and methods one after other (as demonstrated in the example above).
carver provides 2 different mechanism of rendering:
.render('any string') returning the rendered string.write() which requires a set('cwd','/path/to/my/cwd') to be set and makes use of templates and settings found there. Read more about the workdir (cwd) in the section belowAn engine is responsible for compiling the given content into whatever (usually html). By default, no engine is available and carver would just pass back the same content as entered.
carver()
.registerEngine('ejs', require('ejs'));
As you can see, you simple require the official ejs module and it's native .render method will work. You can
do this with any module supporting that express like behavior.
A writer is - compared to an engine - a little bit more work of customization.
If the config/env.js looks like this:
...
destination: 'file:///my/path/to/public'
...
carver looks up in it's writers registry for a file handler and triggers that one when write() is called.
carver()
.registerWriter('webdav', myWebdavWriter);
Luckily, carver provides the most common writer, the filesystem writer. Enable it with:
carver()
.includeFileWriter();
You can change your final filename within a before hook by setting options.filename to whatever is required. The final absolute path is computed by considering options.destinations as well as options.filename.
You can request a copy of the current computed file to be stored under a different filename. This is quite handy, if you are rendering calendar programmes where the current month is listed as the index.htm or somewhere different wheras the ordinary programme files are located under /programme/02-2014. This can be achieved with the
options.copyFilenames - ArrayThis options allows you to save copies of the current render result. just fill options.copyFilenames with relative paths (relative to the destinations directories).
compiler.options.copyFilenames = ['index'];
Hooks plug in at different stages of the compile process, execute a code and resolve to the next hook. Currently the following hooks are available in the following order
Example:
carver()
.registerHook('before.render', function( compiler, resolve){
// do something and e.g.:
compiler.options.locals.myVar = 123;
resolve();
});
## Working with cwd (working directories)
The default use-case probably is, that you will work with objects somehow created (db?), passed on to carver along with a working directory and letting carver do the rest:
FAQs
static site generator
We found that carver demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.