Jekyllをそのまま使うと日付の表記が英語である

標準で用意されているdate_to_long_stringフィルタを使うと、

28 April 2016

こんな表記。

ワシ、日本人。

馴染みの深い表記に変えましょう。

思考順序を追った記事です。

Jekyll初心者です。

結果がほしい人は記事下部の「まとめ」へドウゾ。


そもそもdate_to_long_stringとはどんなのや

適当にぐぐったところ、Jekyllのドキュメントにたどり着きました。

Templates - Jekyll • Simple, blog-aware, static sites

Jekyll uses the Liquid templating language to process templates. All of the standard Liquid tags and filters are supported. Jekyll even adds a few handy filters and tags of its own to make common tasks easier.

適当に翻訳。

JekyllはLiquidっていうテンプレート吐き出すプログラム使ってマース。タグとかフィルターとかサポートしマース。簡単に使うために拡張済みデース。

やるじゃない。

日付の変換フィルタがいくつか紹介されてる。

{{ site.time | date_to_rfc822 }} => Mon, 07 Nov 2008 13:07:54 -0800
{{ site.time | date_to_string }} => 07 Nov 2008
{{ site.time | date_to_long_string }} => 07 November 2008

おう、望むものはないな。

とりあえずフィルタを拡張してみましょうか。

プラグインが追加できると聞きました。調べてみます。


GitHub Pagesではプラグインを追加できない

Plugins - Jekyll • Simple, blog-aware, static sites

Plugins on GitHub Pages GitHub Pages is powered by Jekyll. However, all Pages sites are generated using the –safe option to disable custom plugins for security reasons. Unfortunately, this means your plugins won’t work if you’re deploying to GitHub Pages.

You can still use GitHub Pages to publish your site, but you’ll need to convert the site locally and push the generated static files to your GitHub repository instead of the Jekyll source files.

適当に翻訳。

GitHub PagesはJekyllで動いてるけど、セキュリティ面での理由でアナタが作ったプラグインは動か無いデース。

ローカルでいい具合に静的ファイルを編集してからプッシュしてくだサーイ。

Oh, yea.

Jekyllにプルリクを出してマージ通れば、GitHub Pagesで自分で作ったフィルターを利用できそうですが、流石に待ってられません。通らないし。

別の解決策を探します。

メジャーなツールで利用者が多いので、きっと誰かが解決してくれてるはずです。


いました

まそおさんがズバリ答えを載せててくれました。

まそおぶろぐ: jekyll で、日付を日本語の書式にしたい

日本語の日付にしたい場合は、自身でプラグインを作成する方法もありますが、

{ "2016年04月30日}} => 20160430  

とすると、簡単に日本語表示できます。

やりました。

2016年04月30日の、「04月」の0が気になるなら

{{ page.date | date: }} => 2016430

とフォーマットすればおk.


まとめ

まそおぶろぐ: jekyll で、日付を日本語の書式にしたい

ありがたやー。