wintersmith-categorize
Install
npm install wintersmith-categorize
Options (defaults)
config.json
{
"categorizer": {
"template" : "category.jade",
"articles" : "articles",
"index_filename" : "/archive/index.html",
"filtered_filename" : "/category/%category/index.html
}
}
-
template
- template used to render the articles list -
articles
- articles directory -
index_filename
- filename/url of index (unfiltered) view -
filtered_filename
- filename/url of filtered (by category) view
context variables (accessible in the template)
-
category
(String) category name -
articles
(Array) articles array -
categoriesArticles
(Object) in the form:
{
"all": {
"url": "/archive/index.html",
"articles": [Array]
},
"category 1": {
"url": "/category/category 1/index.html",
"articles": [Array]
},
"another-category": {
"url": "/category/another-category/index.html",
"articles": [Array]
}
}
helper functions
-
env.helpers.getArticlesPerCategory()
- Returns the value ofcategoriesArticles
variable.
Sample:
Article Markdown
---
title: Arch Linux EFI Installation
author: Adones Pitogo
date: 2016-03-14
template: article.jade
categories: category 1, another category, one more category
---
category.jade
section.archive
.container
.row
.col-xs-12.col-sm-8.col-sm-offset-2
h1.text-center Articles in
span.text-primary #{category}
| category.
hr
div
strong Filter by Category :
div
- var articlesByCategory = env.helpers.getArticlesPerCategory()
- var i = 0
each catObj, category in articlesByCategory
if i !== 0
| |
a(href=catObj.url).text-warning #{category}
small.badge #{catObj.articles.length}
|
- i ++
ul.list-unstyled
- var articlesByYear = _.chain(articles).groupBy(function (art) { return art.date.getFullYear();}).value();
each articles, year in articlesByYear
- articles = articles.sort(function (a, b) { return b.date - a.date })
li
h2.year-label= year
each item, art_title in articles
li
.row
.col-xs-4.col-sm-3.col-md-2
span.hidden-xs #{moment.utc(item.date).format('MMMM D')}
span.hidden-sm.hidden-md.hidden-lg #{moment.utc(item.date).format('MMM D')}
.col-xs-8.col-sm-9.col-md-10
a.text-primary(href=item.url) #{item.title}
build output
categories/
all (url: /archive/)
category 1 (url: /category/category%201/)
another category (url: /category/another%20category/)
one more category (url: /category/one%20more%20category/)