sindresorhus / gulp-nunjucks

Precompile Nunjucks templates
MIT License
152 stars 20 forks source link

Is this plugin compatible with nunjucks-markdown? #41

Open caraya opened 2 years ago

caraya commented 2 years ago

I'm trying to use gulp-nunjucks with nunjucks markdown and I'm getting a weird result. The plugin inserts the string undefined wherever I have the markdown tag, but it works fine with HTML. Is there an example of this plugin working with nunjucks-markdown? I haven't found any and I'm curious if I did it right.

Here is the entire code I'm using as a Gulp task, in case someone can spot any errors.

// Require Gulp first
const gulp = require('gulp');
const extReplace = require('gulp-ext-replace');

// Nunjucks and Markdown
const nunjucks = require('nunjucks');
const markdown = require('nunjucks-markdown');
const gulpnunjucks = require('gulp-nunjucks');
// const nunjucksRender = require('gulp-nunjucks-render');
const grayMatter = require('gulp-gray-matter');
const MarkdownIt = require('markdown-it');
const md = require('markdown-it')();

// Nunjucks consts for file location
const dist = 'docs';
const src = 'src';
const templates = src + '/templates';
const content = src + '/pages';

// Where to pull files from?
const env = new nunjucks.Environment(new nunjucks.FileSystemLoader(templates));

markdown.register(env, (text) => {
  md.render(text);
});

gulp.task('renderContent', function() {
  return gulp.src(content + '/**/*.md')
      .pipe(grayMatter())
      .pipe(gulpnunjucks.compile('', {env: env}))
      .pipe(extReplace('.html'))
      .pipe(gulp.dest(dist));
});