和平简朴的生活,纳言敏行,随遇而安。

Middleman Timezone CST Error

Middleman Timezone CST Error

when i use middleman to build my personal website, i'd like the simple but powerful site generator, but if i set Time.zone = "Beijing" in config.rb, when I use "middleman article" to create article, there is an error occured:

The date in article/2017-02-07-testing-article.html's filename doesn't match the date in its frontmatter (RuntimeError). 
The date in article/2017-02-07-testing-article.html's filename doesn't match the date in its frontmatter (RuntimeError).
The date in article/2017-02-07-testing-article.html's filename doesn't match the date in its frontmatter (RuntimeError)
The date in article/2017-02-07-testing-article.html's filename doesn't match the date in its frontmatter (RuntimeError)
The date in article/2017-02-07-testing-article.html's filename doesn't match the date in its frontmatter (RuntimeError)

this error occured on when the time of beijing and American Central Standard Time is different.

because the default "middleman article" generator create the article's variables is date: date.strftime('%F %R %Z'), the %Z set the timezone to CST ..etc. But "CST" is also American Central Standard Time. so the middleman server will run an error.

to resolve this, you can create an custom generator article template, add a new method blog.new_article_template in the config.rb file. between activate :blog do |blog|

blog.new_article_template = File.expand_path '../your_template.erb', __FILE__

create a new template file associate with .erb:

---
title: <%= @title %>
date: <%= @date.strftime('%F %R %z') %>
tags:
category:
---

here date.strftime('%F %R %z') %z is stick to timezone to +0800 rather than CST then the middleman article works well.