Skip to content

Releases: lyphtec/markdown-serve

v0.8.0

15 Jul 02:03
Compare
Choose a tag to compare
Upstream pkg upgrades to fix security vulnerabilities

Fixed "headers can't be sent" errors when using preParse=true

10 Oct 02:06
Compare
Choose a tag to compare

hbs & express-handlebars view engines were throwing weird headers can't be sent errors - something to do with async processing when calling markdownFile.parseContent(). This has now been resolved by removing the res.render() call within parseContent().

Fixed issue with hbs view engine when using res.end()

09 Oct 11:08
Compare
Choose a tag to compare

Removed all res.end() calls as these were causing issues when using the hbs view engine.

Examples site updated to now work with Express 4.x with full samples using hbs

Middleware preParse and handler functions

09 Oct 11:04
Compare
Choose a tag to compare
  • preParse option now accepts a function allowing customization of view model object passed to view
app.use(mds.middleware({
    rootDirectory: path.resolve(__dirname, 'content'),
    view: 'markdown',
    preParse: function(markdownFile) {
        return {
            title: markdownFile.meta.title,
            content: markdownFile.parseContent(),
            created: moment(markdownFile.created).format('L')
         };
    }
});
  • handler function option for full control of middleware behaviour - do not specify view option if using this
app.use(mds.middleware({
    rootDirectory: path.resolve(__dirname, 'content'),
    handler: function(markdownFile, req, res, next) {
        if (req.method !== 'GET') next();

        // limit access 
        if (markdownFile.meta.draft && !req.user.isAdmin) {
            next();
            return;
        }

        var view = markdownFile.meta.view || 'markdown';

        var vm = {
            title: markdownFile.meta.title,
            content: markdownFile.parseContent(),
            created: moment(markdownFile.created).format('L')
         };         

         res.render(view, vm);
    }
});

preParse option

02 Oct 15:19
Compare
Choose a tag to compare

Added preParse option to middleware - when enabled, module will parse the Markdown content and make it available as markdownFile.parsedContent property to view.

Example,

app.use(markdownServe.middleware({ 
    rootDirectory: path.resolve(__dirname, '../content/markdown/'),
    view: 'markdown',
    preParse: true
}));