Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this plugin compatible with nunjucks-markdown? #41

Open
caraya opened this issue Oct 16, 2021 · 0 comments
Open

Is this plugin compatible with nunjucks-markdown? #41

caraya opened this issue Oct 16, 2021 · 0 comments

Comments

@caraya
Copy link

caraya commented Oct 16, 2021

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));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant