Guest User

Untitled

a guest
Oct 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. const gulp = require('gulp');
  2. const tap = require('gulp-tap');
  3. const nunjucks = require('gulp-nunjucks-render');
  4. const markdown = require('gulp-markdownit');
  5. const grayMatter = require('gulp-gray-matter');
  6. const data = require('gulp-data');
  7. const path = require('path');
  8. const fs = require('fs');
  9.  
  10. const CONTENT = 'content/**/*.md',
  11. TEMPLATES = 'src/views';
  12.  
  13. // Sets markdown contents to {{ contents }}
  14. function getData(file) {
  15. file.data.contents = file.contents;
  16. return file.data;
  17. }
  18.  
  19. // Writes template to file contents
  20. function useTemplate(file) {
  21. const templatePath = path.resolve(TEMPLATES, file.data.template),
  22. template = fs.readFileSync(templatePath);
  23.  
  24. file.contents = new Buffer(template);
  25. return;
  26. }
  27.  
  28. // Generates static site from markdown
  29. gulp.task('build:content', () => {
  30. return gulp.src(CONTENT)
  31. .pipe(grayMatter())
  32. .pipe(markdown())
  33. .pipe(data(getData))
  34. .pipe(tap(useTemplate))
  35. .pipe(nunjucks({ path: TEMPLATES }))
  36. .pipe(gulp.dest('dist'));
  37. });
Add Comment
Please, Sign In to add comment