3.10.10 • Published 7 years ago

wintersmith-author v3.10.10

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

wintersmith-author

This is a plugin for Wintersmith. It allows you to increase the usefulness of designating authors on posts. This plugin is essentially a global find and replace using 'author' in place of 'tag' of the wintersmith-tag plugin created by weiribao. I found his plugin so useful that I decided to see if I could adapt it to provide the same functionality for the author metadata.

How to use

Step1: install

Install globally or locally using npm

npm install [-g] wintersmith-author

and add wintersmith-author to your project's config.json

{
  "plugins": [
    "wintersmith-author"
  ]
}

Step2: set plugin options

You can specify options in config.json

{
    "author": {
        "template": "author-index.jade",
        "perPage": 4
    }
}

This plugin is based on the built-in paginator plugin, so it uses the paginator's options by default. The only exception is it has its own default for filename. This is can be best understood by looking at the source code

paginatorDefaults =
    template: 'index.jade' # template that renders pages
    articles: 'articles' # directory containing contents to paginate
    first: 'index.html' # filename/url for first page
    filename: 'page/%d/index.html' # filename for rest of pages
    perPage: 2 # number of articles per page

authorDefaults =
    filename: 'author/%s/%d/index.html' # => author/:authorName/:pageNum/index.html

options = _.extend {}, paginatorDefaults, env.config.paginator, authorDefaults, env.config.author

Step3: add authors to articles

Just add authors to the metadata section of the article. Seperate multple authors by comma. Author name can contain space.

---
title: Hello world
date: 2012-10-14 8:31
template: article.jade
author: coryg
---

Step4: modify your template

Several new context variables and helper funtions are available in the template now.

authorName

The authorName variable contains the author name that articles are filtered by.

env.helpers.getAllAuthors()

This function returns all authors in the project. It can be used to create a author cloud on your frontpage, for example.

env.helpers.getArticlesByAuthor(authorName)

Returns all articles that has author authorName

env.helpers.getAuthorHome(authorName)

Returns a page object that reperents the first page of the article list filtered by authorName. You can create a link to this page in template like

a(href=env.helpers.getAuthorHome(authorName).url)= authorName

env.helpers.getAuthorsFromArticle(article)

Returns an array of authors of current article.

- var authors = env.helpers.getAuthorsFromArticle(page)
each author in authors
    a.big-author(href=env.helpers.getAuthorHome(author).url)= author

Step5: build & done!

wintersmith build -v

Lists of articles filtered by authors have been created successfully!

/author/coryg/1/index.html
/author/coryg/2/index.html
...