middleman / middleman-blog

Blog Engine Extension for Middleman
https://middlemanapp.com
MIT License
325 stars 179 forks source link

Blog date check not taking into account frontmatter offset #143

Closed mcoms closed 7 months ago

mcoms commented 11 years ago

With config.rb setting Time.zone = 'London' and the file 2010-05-30-and-now-for-something-completely-different.html.erb containing:


---
title: "And now for something completely different..."
date: 2010-05-30 23:05:52 +00:00
tags: Facebookable, General
published: false

---

<p>Hello.</p>

middleman (3.0.14) / middleman-blog (3.1.1) crashes with:

✗ middleman    
== The Middleman is loading
/Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-blog-3.1.1/lib/middleman-blog/blog_article.rb:127:in `date': The date in 2010-05-30-and-now-for-something-completely-different.html's filename doesn't match the date in its frontmatter (RuntimeError)
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-blog-3.1.1/lib/middleman-blog/blog_data.rb:102:in `block in manipulate_resource_list'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-blog-3.1.1/lib/middleman-blog/blog_data.rb:92:in `each'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-blog-3.1.1/lib/middleman-blog/blog_data.rb:92:in `manipulate_resource_list'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/sitemap/store.rb:222:in `block (2 levels) in ensure_resource_list_updated!'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/sitemap/store.rb:221:in `each'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/sitemap/store.rb:221:in `inject'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/sitemap/store.rb:221:in `block in ensure_resource_list_updated!'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/sitemap/store.rb:215:in `ensure_resource_list_updated!'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/sitemap/extensions/on_disk.rb:35:in `block in initialize'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/vendor/hooks-0.2.0/lib/hooks.rb:53:in `instance_exec'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/vendor/hooks-0.2.0/lib/hooks.rb:53:in `block in run_hook_for'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/vendor/hooks-0.2.0/lib/hooks.rb:49:in `each'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/vendor/hooks-0.2.0/lib/hooks.rb:49:in `run_hook_for'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/vendor/hooks-0.2.0/lib/hooks.rb:107:in `run_hook'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/core_extensions/request.rb:57:in `inst'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/preview_server.rb:79:in `new_app'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/preview_server.rb:161:in `mount_instance'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/preview_server.rb:19:in `start'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/cli/server.rb:73:in `server'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/thor-0.15.4/lib/thor/task.rb:27:in `run'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/thor-0.15.4/lib/thor/invocation.rb:120:in `invoke_task'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/thor-0.15.4/lib/thor.rb:275:in `dispatch'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/thor-0.15.4/lib/thor/base.rb:425:in `start'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/cli.rb:77:in `method_missing'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/thor-0.15.4/lib/thor/task.rb:29:in `run'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/thor-0.15.4/lib/thor/task.rb:126:in `run'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/thor-0.15.4/lib/thor/invocation.rb:120:in `invoke_task'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/thor-0.15.4/lib/thor.rb:275:in `dispatch'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/thor-0.15.4/lib/thor/base.rb:425:in `start'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/lib/middleman-core/cli.rb:22:in `start'
    from /Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-core-3.0.14/bin/middleman:18:in `<top (required)>'
    from /Users/nick/.rbenv/versions/2.0.0-p0/bin/middleman:23:in `load'
    from /Users/nick/.rbenv/versions/2.0.0-p0/bin/middleman:23:in `<main>'

I'm currently on holiday in Italy, so my computer's time zone is Rome (GMT+01:00), which due to daylight savings is 2 hours ahead of UTC. So, 5pm here is 4pm in London and 3pm in UTC.

Is it correct that the file naming has to reflect what the rendered time will eventually be?

mcoms commented 11 years ago

Update... The generator doesn't take into account the differences either, so at 00:37 on the 23rd (gone midnight in Italy) but while it's still 23:37 on the 22nd in London, creating an article produces a file with the incorrect name:

➜  ~blog git:(master) ✗ date
Tue 23 Jul 2013 00:37:31 CEST
➜  ~blog git:(master) ✗ middleman article Test
      create  source/2013-07-23-test.html.markdown
➜  ~blog git:(master) ✗ middleman
== The Middleman is loading
/Users/nick/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/middleman-blog-3.1.1/lib/middleman-blog/blog_article.rb:127:in `date': The date in 2013-07-23-test.html's filename doesn't match the date in its frontmatter (RuntimeError)

Happy to try and do some work on this one, but unsure of the correct behaviour. Would it make sense that the file name and frontmatter reflect the timezone they were created in, but, if a different timezone is set in the blog, the page is proxied to the new date?

bhollis commented 10 years ago

It should probably use the timezone set by the blog configuration.

bhollis commented 10 years ago

I checked, and we have tests for this exact case. Could you please try with the latest middleman-blog?

onenight commented 9 years ago

I had this issue when setting Time.zone = "Taipei". So I comment Time.zone, and everything works.

ruby 2.2.1p85 / middleman (3.3.12) / middleman-blog (3.5.3)

Novtopro commented 8 years ago

@onenight This is because in the latest version, https://github.com/wongyouth/middleman-blog/commit/ab91e6d4be8b8ed66cfb54b2039a9bdb0dcd834f is reverted.

Novtopro commented 8 years ago

You can use a custom template to solve this problem.

blog.new_article_template = File.expand_path '../your_template.tt', __FILE
alexrodba commented 7 years ago

I'm still getting problems with this. Currently running these versions: middleman (4.2.1, 3.4.1, 3.3.12) middleman-blog (4.0.1, 3.5.3)

iwarner commented 7 years ago

For reference I always set my Timezone to

Time.zone = "Europe/London"

Which is the correct way I believe

Seems as though their are a hierarchy of issues:

  1. Date in file naming and in frontmatter are clashing - which takes precedence
  2. Time.Zone not overriding time in frontmatter

The feature is here : https://github.com/middleman/middleman-blog/blob/master/features/filename_date.feature

If you can expand on this then that would be great, can you provide a Repo with this please