文章を書くことに特化したブログプラットフォームという触れ込みだった Ghost は私には合わないのでやめました。代わりに採用したのが、最近は流行の静的サイトジェネレータで、その中から Metalsmith を選びました。

公式の examples のうち、2018年 6月 28日時点において、見るべきものは、static-site のみです。他は無視しましょう。理由は簡単で、package.json を見るとすぐ分かるとおり、static-site のみが metalsmith 2.x に対応しており、他は metalsmith 1.x の使用例です。執筆時点の metalsmith の最新版は 2.3.0 ですから、わざわざ古いものを使用する理由はありません。

  • package.json
  • index.js
  • Makefile
  • layouts/
    • posts.html
  • src/
    • posts/
      • article.md
    • css/
    • js/
    • images/
  • build/
  • node_modules/

{
  "name": "My Static Site & Blog",
  "private": true,
  "dependencies": {
    "handlebars": "^4.0.5",
    "metalsmith": "^2.1.0",
    "metalsmith-layouts": "^1.4.1",
    "metalsmith-markdown": "^0.2.1",
    "metalsmith-permalinks": "^0.5.0",
  }
}

Makefile を作ります。


build: node_modules
	node index.js

node_modules: package.json
	npm install

.PHONY: build

index.js を作ります。


const Metalsmith    = require('metalsmith'),
      markdown      = require('metalsmith-markdown'),
      layouts       = require('metalsmith-layouts'),
      permalinks    = require('metalsmith-permalinks');

Metalsmith(__dirname)
  .metadata({
    title: "My Static Site & Blog",
    description: "It's about saying »Hello« to the World.",
    generator: "Metalsmith",
    url: "http://example.com/"
  })
  .source('./src')
  .destination('./build')
  .clean(false)
  .use(markdown())
  .use(permalinks())
  .use(layouts({
    engine: 'handlebars'
  }))
  .build(function(err, files) {
    if (err) { throw err; }
  });

(この記事は書きかけです)