Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
grunt-pages
Advanced tools
Grunt task to create pages using markdown and templates
If you haven't used grunt before, be sure to check out the Getting Started guide, as it explains how to create a gruntfile as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:
npm install grunt-pages --save-dev
Then add this line to your project's Gruntfile.js
gruntfile:
grunt.loadNpmTasks('grunt-pages');
Here is a sample config to create a blog using grunt-pages
:
pages: {
options: {
pageSrc: 'src/pages',
data: 'src/data/pageData.json'
},
posts: {
src: 'src/posts',
dest: 'dev',
layout: 'src/layouts/post.ejs',
url: 'blog/posts/:title'
}
}
Posts are written in markdown and include a metadata section at the top to provide information about the post. There are two accepted metadata formats, YAML and a JavaScript object. Here is a YAML example:
----
title: The Versace Sofa Thesis Vol. I
date: 2010-10-4
author: Pusha T
----
The YAML data is parsed into a JavaScript object and passed to the post's template to be rendered.
Here is a JavaScript object example:
{
title: "Art Ballin': Explorations in New-Weird-American Expressionism",
date: "2013-2-22",
author: "Highroller, Jody"
}
The only property that is not interpreted literally is the date
. It is used as a dateString
when constructing a Date object in JavaScript, and must be in a parseable format. For both YAML and JavaScript object metadata, the JavaScript Date
object is available in the layout.
For adding code to your posts, grunt-pages has GitHub flavoured markdown syntax highlighting using pygments.
Type: String
The directory where the source posts are located.
Type: String
The directory where pages are generated.
Type: String
The jade or ejs layout template used for each post. The post metadata will be stored in a post
object to be rendered in the layout template. Here is an example post layout template.
Type: String
The url of each post. The string takes variables as parameters using the :variable
syntax. Variable(s) specified in the url are required in each post's metadata.
Type: String
The folder where the ejs or jade source pages of your website are located. These pages have access to the posts' content and metadata in a posts
array. All of the files in this folder are generated in the dest
folder maintaining the same relative path from pageSrc
.
Type: String
The location of a JSON file which is parsed and passed to templates for rendering. This is primarily used for data to be shared across all pages. This data is available in pages' and posts' templates via the data
object.
Type: Object
An object containing config for pagination. This option generates paginated list pages which each containing a specified number of posts. These paginated list pages are generated in the dest
folder relative to the pagination.listPage's location in the format pagination.listPage
/pages/pageNumber
/index.html.
Here is a sample config using pagination:
pages: {
options: {
pagination: {
listPage: 'src/layouts/listPage.jade',
postsPerPage: 3
}
},
posts: {
src: 'src/posts',
dest: 'dev',
layout: 'src/layouts/post.jade',
url: 'posts/:title'
}
}
Type: Number
The number of posts each list page will contain.
Type: String
The location of the layout template which is used for each list page.Here is a sample template that uses pagination. The template has access to the following variables:
Type: Array
of Object
s
An array of page objects which each contain a url
property. The page currently being rendered also has a currentPage
boolean property.
Type: Array
of Object
s
An array of post objects which contains the content
and metadata properties for each post.
0.0.0 - Initial release
0.1.0 - Added data
option, added templateEngine
option, added pagination
option, and changed post data format to be a post
object rather than global variables for each post property.
0.2.0 - Fixed templateEngine
bug, changed pagination
and data
api.
FAQs
Grunt task to create pages using markdown and templates
The npm package grunt-pages receives a total of 34 weekly downloads. As such, grunt-pages popularity was classified as not popular.
We found that grunt-pages demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.