Page Plugin

Will edited this page Nov 1, 2016 · 3 revisions

The page plugin is a base class that the markdown plugin that ships with wintersmith inherits from, it's designed to be subclassed by plugins that creates pages. A page has metadata, html and a template that renders it. Check plugins/page.coffee to see what methods needs to be implemented when subclassing.

The page plugin provides some features useful for managing your content.

Filename Templating

If you specify a filename in your metadata you can redirect where the page is rendered (its url/permalink). Filenames will be resolved from the directory they reside in so for foo/bar.md with a filename of moo.html the output will be foo/moo.html. To create absolute filenames you can use a leading slash (e.g. /moo.html).

You can also create the filenames dynamically using a mini templating language.

Available variables

name description
:year Full year from page.date
:month Zero-padded month from page.date
:day Zero-padded day from page.date
:title Slugified version of page.title
:basename filename from @filepath
:file basename without file extension
:ext file extension

You can also run javascript by wrapping it in double moustaches {{ }}, in that context this page instance is available as page and the environment as env.

Examples

for a page with the filename somedir/myfile.md and date set to 2001-02-03

template: :file.html (default)
output: somedir/myfile.html

template: /:year/:month/:day/index.html
output: 2001/02/03/index.html

template: :year-:title.html
output: somedir/2001-slugified-title.html

template: /otherdir/{{ page.metadata.category }}/:basename
output: otherdir/the-category/myfile.md

The default template is :file.html and can be set using the filenameTemplate config key.