jojo
the 10 second blog-engine for hackers (in javascript).
It was built for running as middleware inside an express app as well as a standalone application.
// articles/the-wonderful-wizard-of-oz.md "title": "The Wonderful Wizard of Oz" "author": "Lyman Frank Baum" "date": "1900/05/17" Dorothy lived in the midst of the great Kansas prairies with Uncle Henrywho was a farmer and Aunt Em who was the farmer's wife. // app.jsvar jojo = require('jojo'), app = jojo();app.listen(5000);// Server is listening at http://localhost:5000/// "The Wonderful Wizard of Oz" is being served at `/1900-05-16-the-wonderful-wizard-of-oz`
Getting started
Middleware
jojo
is available via npm: npm install jojo
jojo
is invoked with a configuration and can return a middleware or express app.
var app = ; // express appvar app = ; // vanilla middleware
By default, jojo
reads articles that match articles/*.{txt,md}
(txt
and md
files in articles
directory) but this can be overridden via an option.
If you want more information on pattern options, see node-glob reference.
var app = ; // Read articles from `papers`
By default, all articles are interpretted via marked, a GitHub flavored markdown parser.
More configuration options can be found in the documentation.
Standalone
To run jojo
as a standalone server, install jojo
globally: npm install -g jojo
.
jojo
looks for a jojo.js
/jojo.json
to read in settings. These settings are passed to both a jojo
middleware and express app.
jojo
also accepts arguments for choosing a different config
or port
.
$ jojo --helpUsage: jojo [options]Options: -c, --config [config] Config file to use -p, --port [port] Port to run server on
port
can also be specified injojo.js
/jojo.json
Documentation
jojo
has a wide spectrum of options
jojo
jojo
has an optional options
parameter which modifies its behavior.
;;/** * @param * @returns * a req/res/next function or express 2.x app. */
options.render
options.render
is expected as a Boolean
and true
by default.
When true, an express 2.x app will be returned by jojo
.
Otherwise, a req
/res
/next
middleware will be returned.
options.articles
options.articles
is expected as a String
and articles
by default.
This is the directory to read articles from. It is processed relative to process.cwd()
.
jojo.articles
jojo.articles
is a sorted array of the parsed articles.
Each article has
- Any meta-data listed in the head of the file
rawContent
, unprocessed bodycontent
, formatted bodyrawDate
, unprocessed date (from meta-data)date
,Date
object fromrawDate
moment
,moment
object fromrawDate
(uses timezone fromrawDate
)url
, URL path for article. This can be modified via options.urlFormatter.rawSummary
, ifsummary
is provided, this will be the unprocessedsummary
summary
, ifsummary
is provided, this will be the formattedsummary
req.articles, res.locals.articles
Same as jojo.articles
but located on req
and res
for easy accessibility.
req.article, res.locals.article
On article pages, this will be the corresponding article
.
See urlFormatter for more url
information
req.config, res.locals.config
Configuration passed in to jojo
. If invoked from standalone, this will be the as the config
.
jojo.dataParser
jojo.dataParser
is a Function
to separate meta data from the body of an article.
By default, this is json-content-demux. If you are overriding, return an object containing meta data on json
and body on content
.
jojo.formatter
jojo.formatter
is a Function
to process the body into HTML markup.
By default, marked is used. If you are overriding, return a string of HTML.
jojo.urlFormatter
jojo.urlFormatter
is a Function
that receives an article and returns a URL path.
By default, it returns /YYYY-MM-DD-article-name
. If you are overriding, return a string.
jojo.articleSort
jojo.articleSort
is a Function
that compares articles to determine their order.
By default, it returns articles by most recent. If you are overriding, you will receive two articles and need to return an integer. See Array.prototype.sort documentation for more information.
Donating
Support this project and others by twolfson via donations.
http://twolfson.com/support-me
Attribution
jojo
was initially inspired by toto.
License
Copyright (c) 2013 Todd Wolfson
Licensed under the MIT license.