macoshita / gulp-layout

Gulp plugin to apply a defferent template for each file (like a jekyll)
14 stars 0 forks source link

Passing Engine Options Separately #2

Open dacodekid opened 9 years ago

dacodekid commented 9 years ago

I'm not sure, I am approaching this right, but currently if I need to pass pretty: true option for jade then either I'm adding the values to file.frontMatter like below

  return gulp.src('./src/contents/posts/*.{md,markdown}')
    .pipe(frontmater())
    .pipe(markdown())
    .pipe(layout(function(file) {
        file.frontMatter['pretty'] = true;
        file.frontMatter['layout'] = './src/templates/post.jade';
        return file.frontMatter;
    }))
    .pipe(gulp.dest('./build'))
}

or, I have to pass those via my post.md's frontmatter


---
title: post title
date: 2015-10-08
layout: ./src/templates/post.jade
pretty: true

---

Is it possible to pass those Engine specific options separately as another argument to Layout()?

dacodekid commented 9 years ago

In addition, if we specify those engine specific options on both places (gulpfile & markdown), is it possible for markdown to takeover and override the values?

shamansir commented 8 years ago

+1, I need to pass these options too

shamansir commented 8 years ago

on the other hand, we should have a way to do it like this:

.pipe(layout(function(file) {
    return {
        pretty: true,
        layout: '<whatever>.jade',
        locals: {
            front: file.frontMatter
        }
    }
}))

and then just use front.title instead of just title.

shamansir commented 8 years ago

the previous example works, but locals should be injected directly into the object:

var config = require('./config.json');
// ...
.pipe(layout(function(file) {
    return {
        pretty: true,
        layout: './layout.jade',
        config: config,
        front: file.frontMatter
    }
}))

layout.jade:

html
  head
    title My Page - #{front.title}
  body
    h1 #{front.title} 
    div
      span= config.author
    != contents
    #footer
      p some footer content
macoshita commented 8 years ago

Sorry for ther late reply. This library use consolidate.js. As far as I know, it is necessary to pass the object that merge engine config and locals. So it is difficult to sparate engine config. With such Object.assign(), it would be a little better.

If there is a way to pass separate objects, please tell me.