npm.io
0.0.5 • Published 9 years ago

md-docs-express

Licence
MIT
Version
0.0.5
Deps
2
Vulns
7
Weekly
0
Stars
2

md-docs-express

md document router on express

Usage

var option = {
    mddir: require('path').join(__dirname, 'mddir'),
};

app.use('/docs', require('md-docs-express')(option));

API

md-docs-express(options)
returns
  • express router
options
  • mddir: Directory includes md files
  • hasSetting: if true, read <mddir>/settings.json for various setting like listing order
  • debug: debug flag
  • title: page title
  • swaggerDoc: swagger document (json format)

settings.json

If there are 3 files[A.md, B.md, C.md] are in mddir, you can set their order as following.

{
    "listorder": [
        "C",
        "A",
        "B"
    ]
}

Also you can specify directory name

mkdir subdir
{
    "listorder": [
        "C",
        "A",
        "B",
        "subdir"
    ]
}

Swagger document

If you want to display swagger doc, specify swaggerDoc to option.
The path of the SwaggerDoc will be <path>/swagger.
Swagger json string will be exposed at <path>/swagger/apidoc. Swagger-UI 2.2.10 is used.

var option = {
    mddir: require('path').join(__dirname, 'mddir'),
    swaggerDoc: {Swagger Doc json object}
};

app.use('/docs', require('md-docs-express')(option));

Known Issues

  • Subdirectory is now supported, but has 1-depth limitation

Demo

  1. create directories
mkdir mytest
cd mytest
mkdir documents
mkdir documents/subdir
  1. create example md files
touch documents/A.md
touch documents/B.md
touch documents/C.md
touch documents/subdir/D.md
touch documents/subdir/E.md
  1. Create express project
npm install express -g
express -e ./
npm install
npm install --save md-docs-express
  1. add page to app.js
app.use('/docs', require('md-docs-express')({
    mddir: require('path').join(__dirname, 'documents'),
    title: 'Hello World!'
}));
  1. Start app
node bin/www
  1. Look your page

http://localhost:8080/docs

picture1

picture2

Keywords