Declaring a Blog

2015-08-21

CINC.io has settled into a pretty good pattern of regular updates, so I thought I should probably start documenting those updates in more detail than can fit in a Tweet. I've made dozens of blogs, and initially started building the familiar system I've used before: some HTML forms to create posts, some code to save posts to a database, and some more code to pull posts out of that database and format them as HTML. But then I realized this was a good opportunity to test out some of the ideas behind CINC.io. How much of this blog could I make with configuration before code?

The answer, it turns out, is all of it. I was pleasantly surprised to discover I could make this blog writing only declarative code. For input, it uses a mix of declarative languages: JSON, YAML, Markdown, and Twig. And it outputs directly to static (declarative) HTML files. In between is a tool called Metalsmith, which reads instructions from a simple JSON file to run a series of single-purpose plugins:

{
  "destination": "../news",
  "metadata":{
    "site": {
      "title": "CINC.io",
      "url": "http://cinc.io/news"
    }
  },
  "plugins": {
    "metalsmith-drafts": true,
    "metalsmith-collections": {
      "latest": {
        "pattern": "20*/*.md",
        "sortBy": "date",
        "reverse": true,
        "limit": 10
      },
      "all": {
        "pattern": "20*/*.md",
        "sortBy": "date",
        "reverse": true
      }
    },
    "metalsmith-markdown": true,
    "metalsmith-prism": true,
    "metalsmith-excerpts": true,
    "metalsmith-permalinks": {
      "pattern": ":date/:title",
      "date": "YYYY/MM"
    },
    "metalsmith-paginate": {
      "perPage": 2,
      "path": "page/:page/index"
    },
    "metalsmith-feed": {
      "collection": "latest"
    },
    "metalsmith-twig": true
  }
}

Writing the posts in Markdown and YAML means I can easily reuse them in other systems that read the same formats. And because the (JS-based) blog and the (PHP-based) main site are both using Twig for templating, I'm already reusing those templates between two independent systems. This kind of reuse is exactly what I hope CINC.io will further.