Gathering detailed insights and metrics for gulp-nunjucks-md
Gathering detailed insights and metrics for gulp-nunjucks-md
Gathering detailed insights and metrics for gulp-nunjucks-md
Gathering detailed insights and metrics for gulp-nunjucks-md
npm install gulp-nunjucks-md
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
Render nunjucks templates, with markdown and front-matter.
Install with npm
npm install --save-dev gulp-nunjucks-md
This plugin renders nunjucks to html and performs following tasks additionally –
page
variable.For a CLI tool, see njk. For compiling/precompiling, see gulp-nunjucks
layout
pointing to name of a layout (without extension) in your template directory.page.layout
property which points to the name of the layout without extension.content
block around your page. Your parent layout should have a content
block where processed content will be inserted. You can turn off this behavior by setting useBlock: false
either in plugin options or in front-matter and declaring blocks normally ( for example, multiple block inheritance)..markdown
or .md
extension, You can also pass custom options to marked through marked
option.escape: false
you can unescape markdown before processing nunjucks to make nunjucks tags work.1const gulp = require('gulp') 2const nunjucksMd = require('gulp-nunjucks-md') 3 4gulp.task('default', function() { 5 return gulp 6 .src('src/*.{html,njk,md}') // your pages 7 .pipe( 8 nunjucksMd({ 9 path: ['src/templates/'], // nunjucks templates 10 data: 'src/data.json' // json data 11 }) 12 ) 13 .pipe(gulp.dest('dist')) 14})
Plugin accepts options object, which contain these by default:
1var defaults = { 2 path: '.', 3 ext: '.html', 4 extLayout: '.njk', 5 data: {}, 6 useBlock: true, 7 block: 'content', 8 marked: null, 9 escape: true, 10 inheritExtension: false, 11 envOptions: { 12 watch: false 13 }, 14 manageEnv: null 15}
path
- Relative path to templatesext
- Extension for compiled templates, pass null or empty string if yo don't want any extensionextLayout
- Extension for the layouts to be extendeddata
- Data passed to template, either object or path to the json fileuseBlock
- If true appends a content block. If false only parent template will be extended and no default content block will be wrapped. We can also set it at page level by adding useBlock : false/true
to frontmatter. Please note that page level configuration will be preferred.block
- Name of content block in your parent templatemarked
- Custom options for markedescape
- true
by default. Set it to false
if you want to use nunjucks in markdown.inheritExtension
- If true, uses same extension that is used for templateenvOptions
- These are options provided for nunjucks Environment. More info here.manageEnv
- Hook for managing environment before compilation. Useful for adding custom filters, globals, etc.For more info about nunjucks functionality, check https://mozilla.github.io/nunjucks/api.html.
Here is an example of using gulp-nunjucks md —
Although this example conatains a html with front-matter and nunjucks, you can use markdown as well. Now, suppose we have a file named src/templates/default.njk
for parent template.
1<!DOCTYPE html> 2<html lang="en-US"> 3 <head> 4 <meta charset="utf-8"> 5 <title>{{ site.title }} | {{ page.title }}</title> 6 <meta name="description" content="{{ page.description }}" /> 7 <link rel="stylesheet" href="{{ site.url }}/main.css"> 8 </head> 9 <body> 10 <main> 11 {% block content %}{% endblock %} <!-- Important --> 12 <main> 13 <script async src="{{ site.url }}/main.js"></script> 14 </body> 15</html>
And we have a json file at src/data.json
1{ 2 "site": { 3 "title": "Example Site", 4 "url": "http://example.com" 5 }, 6 "boxes": [ 7 { 8 "title": "red" 9 }, 10 { 11 "title": "green" 12 }, 13 { 14 "title": "blue" 15 } 16 ] 17}
Also we have a html page with some nunjucks and front-matter in it src/index.html
.
1--- 2layout: default 3title: "Page Title" 4description: "Some Awesome Description" 5--- 6 7{% for box in boxes %} 8 9<div class="{{ box.title }}"> 10</div> 11{% endfor %}
Now in our gulpfile.js.
1var gulp = require('gulp') 2var nunjucksMd = require('gulp-nunjucks-md') 3 4gulp.task('default', function() { 5 return gulp 6 .src('src/*.html') 7 .pipe( 8 nunjucksMd({ 9 path: ['src/templates/'], 10 data: 'src/data.json' 11 }) 12 ) 13 .pipe(gulp.dest('dist')) 14})
This will render to
1<!DOCTYPE html> 2<html lang="en-US"> 3 <head> 4 <meta charset="utf-8"> 5 <title>Example Site | Page Title</title> 6 <meta name="description" content="Some Awesome Description" /> 7 <link rel="stylesheet" href="http://example.com/main.css"> 8 </head> 9 <body> 10 <main> 11 <div class="red"> 12 </div> 13 <div class="green"> 14 </div> 15 <div class="blue"> 16 </div> 17 <main> 18 <script async src="http://example.com/main.js"></script> 19 </body> 20</html>
Carlos G. Limardo and Kristijan Husak for gulp-nunjucks-render from which this plugin is derived. Sindre Sorhus for gulp-nunjucks
No vulnerabilities found.
No security vulnerabilities found.