Quantcast
Viewing all articles
Browse latest Browse all 10

Expose github README.md at a path using express middleware

I’ve just published the first version of a new middleware package I’ve written to expose your project’s README.md via express.

To install simply run:

npm i --save express-middleware-readme.md


At its very simplest level the module will expose your project’s README.md at the route /readme.html.  To do this simply do the following in your express configuration:

app.use(require('express-middleware-readme.md').run)

The usefulness of this code can be expanded by setting one or a number of several options. Options can be updated as follows:

require('express-middleware-readme.md').setOptions({})

Firstly you can change which file is parsed for presentation to the user by passing the key ‘filename‘ with the name of a file relative to the project root. By default this is set as ‘./README.md’.

You can also change the end point at which the file is exposed by setting the ‘endpoint‘ key. This can be a simple string e.g. ‘/readme.html’ or an array of required endpoints, e.g. ( [ '/readme.html', '/readme.md' ] ).

Next you can decorate the content with standard HTML scaffolding  (doctype, html, head, body) by setting the ‘htmlWrap‘ key as an empty object.

The HTML wrap can be extended by providing keys of….

  • scripts‘: string or array of URLs for javaScript files to be included
  • styles‘: string or array of URLs for CSS files to be included
  • title‘: A title tag to include
  • meta‘:  Add meta tags. Provide objects with keys … as required
    • content
    • value
    • http-equiv
    • charset

Check it out out on the NPM website: https://npmjs.org/package/express-middleware-readme.md

The code is available on github here: https://github.com/lloydwatkin/express-middleware-readme.md

It can also be seen in action on the xmpp-ftw website using the following options:

var readme = require('express-middleware-readme.md')
readme.setOptions({
    htmlWrap: {
        meta: [
            { charset: 'utf-8' }
        ],
        title: 'Project Github README.md'
    }
})

Viewing all articles
Browse latest Browse all 10

Trending Articles