Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog date check not taking into account frontmatter offset #143

Closed
mcoms opened this issue Jul 19, 2013 · 8 comments
Closed

Blog date check not taking into account frontmatter offset #143

mcoms opened this issue Jul 19, 2013 · 8 comments

Comments

@mcoms
Copy link

mcoms commented Jul 19, 2013

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
Copy link
Author

mcoms commented Jul 22, 2013

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
Copy link
Contributor

bhollis commented Oct 19, 2013

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

@bhollis
Copy link
Contributor

bhollis commented Nov 25, 2013

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

wongyouth added a commit to wongyouth/middleman-blog that referenced this issue Apr 23, 2014
When use %Z for date formatting, it does not always the same time when parsing that again. That is why it complain 'filename doesn't match the date in its frontmatter', see middleman#143

```
>> Time.zone = 'Beijing'
=> "Beijing"
>> t = Time.zone.now
=> Wed, 23 Apr 2014 14:08:22 CST +08:00
>> t.strftime('%F %R %Z')
=> "2014-04-23 14:08 CST"
>> Time.zone.parse "2014-04-23 14:08 CST"
=> Thu, 24 Apr 2014 04:08:00 CST +08:00
>>
```

We can list all the TimeZone abbreviations below, there are some abbreviations conflicts in different time zones. It shouldn't be used to parse from.

## Time zone abbreviation conflicts

```
CST (GMT+08:00) Beijing",
CST (GMT+08:00) Chongqing",
CST (GMT+08:00) Taipei",
CST (GMT+08:00) Urumqi",
CST (GMT+09:30) Adelaide",
CST (GMT+09:30) Darwin",
CST (GMT-06:00) Central America",
CST (GMT-06:00) Saskatchewan",

WST (GMT+08:00) Perth",
WST (GMT+13:00) Samoa",
```

## To get all time zone abbreviation list

```
ActiveSupport::TimeZone.all.map{|tz| Time.now.in_time_zone(tz).strftime("%Z") + " " + tz.to_s}
[
    [  0] "SST (GMT-11:00) American Samoa",
    [  1] "SST (GMT-11:00) International Date Line West",
    [  2] "SST (GMT-11:00) Midway Island",
    [  3] "HST (GMT-10:00) Hawaii",
    [  4] "AKDT (GMT-09:00) Alaska",
    [  5] "PDT (GMT-08:00) Pacific Time (US & Canada)",
    [  6] "PDT (GMT-08:00) Tijuana",
    [  7] "MST (GMT-07:00) Arizona",
    [  8] "MDT (GMT-07:00) Chihuahua",
    [  9] "MDT (GMT-07:00) Mazatlan",
    [ 10] "MDT (GMT-07:00) Mountain Time (US & Canada)",
    [ 11] "CST (GMT-06:00) Central America",
    [ 12] "CDT (GMT-06:00) Central Time (US & Canada)",
    [ 13] "CDT (GMT-06:00) Guadalajara",
    [ 14] "CDT (GMT-06:00) Mexico City",
    [ 15] "CDT (GMT-06:00) Monterrey",
    [ 16] "CST (GMT-06:00) Saskatchewan",
    [ 17] "COT (GMT-05:00) Bogota",
    [ 18] "EDT (GMT-05:00) Eastern Time (US & Canada)",
    [ 19] "EDT (GMT-05:00) Indiana (East)",
    [ 20] "PET (GMT-05:00) Lima",
    [ 21] "PET (GMT-05:00) Quito",
    [ 22] "VET (GMT-04:30) Caracas",
    [ 23] "ADT (GMT-04:00) Atlantic Time (Canada)",
    [ 24] "GYT (GMT-04:00) Georgetown",
    [ 25] "BOT (GMT-04:00) La Paz",
    [ 26] "CLST (GMT-04:00) Santiago",
    [ 27] "NDT (GMT-03:30) Newfoundland",
    [ 28] "BRT (GMT-03:00) Brasilia",
    [ 29] "ART (GMT-03:00) Buenos Aires",
    [ 30] "WGST (GMT-03:00) Greenland",
    [ 31] "UYT (GMT-03:00) Montevideo",
    [ 32] "GST (GMT-02:00) Mid-Atlantic",
    [ 33] "AZOST (GMT-01:00) Azores",
    [ 34] "CVT (GMT-01:00) Cape Verde Is.",
    [ 35] "WEST (GMT+00:00) Casablanca",
    [ 36] "IST (GMT+00:00) Dublin",
    [ 37] "BST (GMT+00:00) Edinburgh",
    [ 38] "WEST (GMT+00:00) Lisbon",
    [ 39] "BST (GMT+00:00) London",
    [ 40] "GMT (GMT+00:00) Monrovia",
    [ 41] "UTC (GMT+00:00) UTC",
    [ 42] "CEST (GMT+01:00) Amsterdam",
    [ 43] "CEST (GMT+01:00) Belgrade",
    [ 44] "CEST (GMT+01:00) Berlin",
    [ 45] "CEST (GMT+01:00) Bern",
    [ 46] "CEST (GMT+01:00) Bratislava",
    [ 47] "CEST (GMT+01:00) Brussels",
    [ 48] "CEST (GMT+01:00) Budapest",
    [ 49] "CEST (GMT+01:00) Copenhagen",
    [ 50] "CEST (GMT+01:00) Ljubljana",
    [ 51] "CEST (GMT+01:00) Madrid",
    [ 52] "CEST (GMT+01:00) Paris",
    [ 53] "CEST (GMT+01:00) Prague",
    [ 54] "CEST (GMT+01:00) Rome",
    [ 55] "CEST (GMT+01:00) Sarajevo",
    [ 56] "CEST (GMT+01:00) Skopje",
    [ 57] "CEST (GMT+01:00) Stockholm",
    [ 58] "CEST (GMT+01:00) Vienna",
    [ 59] "CEST (GMT+01:00) Warsaw",
    [ 60] "CET (GMT+01:00) West Central Africa",
    [ 61] "CEST (GMT+01:00) Zagreb",
    [ 62] "EEST (GMT+02:00) Athens",
    [ 63] "EEST (GMT+02:00) Bucharest",
    [ 64] "EET (GMT+02:00) Cairo",
    [ 65] "CAT (GMT+02:00) Harare",
    [ 66] "EEST (GMT+02:00) Helsinki",
    [ 67] "EEST (GMT+02:00) Istanbul",
    [ 68] "IDT (GMT+02:00) Jerusalem",
    [ 69] "EEST (GMT+02:00) Kyiv",
    [ 70] "SAST (GMT+02:00) Pretoria",
    [ 71] "EEST (GMT+02:00) Riga",
    [ 72] "EEST (GMT+02:00) Sofia",
    [ 73] "EEST (GMT+02:00) Tallinn",
    [ 74] "EEST (GMT+02:00) Vilnius",
    [ 75] "AST (GMT+03:00) Baghdad",
    [ 76] "AST (GMT+03:00) Kuwait",
    [ 77] "FET (GMT+03:00) Minsk",
    [ 78] "EAT (GMT+03:00) Nairobi",
    [ 79] "AST (GMT+03:00) Riyadh",
    [ 80] "IRDT (GMT+03:30) Tehran",
    [ 81] "GST (GMT+04:00) Abu Dhabi",
    [ 82] "AZST (GMT+04:00) Baku",
    [ 83] "MSK (GMT+04:00) Moscow",
    [ 84] "GST (GMT+04:00) Muscat",
    [ 85] "MSK (GMT+04:00) St. Petersburg",
    [ 86] "GET (GMT+04:00) Tbilisi",
    [ 87] "MSK (GMT+04:00) Volgograd",
    [ 88] "AMT (GMT+04:00) Yerevan",
    [ 89] "AFT (GMT+04:30) Kabul",
    [ 90] "PKT (GMT+05:00) Islamabad",
    [ 91] "PKT (GMT+05:00) Karachi",
    [ 92] "UZT (GMT+05:00) Tashkent",
    [ 93] "IST (GMT+05:30) Chennai",
    [ 94] "IST (GMT+05:30) Kolkata",
    [ 95] "IST (GMT+05:30) Mumbai",
    [ 96] "IST (GMT+05:30) New Delhi",
    [ 97] "IST (GMT+05:30) Sri Jayawardenepura",
    [ 98] "NPT (GMT+05:45) Kathmandu",
    [ 99] "ALMT (GMT+06:00) Almaty",
    [100] "BDT (GMT+06:00) Astana",
    [101] "BDT (GMT+06:00) Dhaka",
    [102] "YEKT (GMT+06:00) Ekaterinburg",
    [103] "MMT (GMT+06:30) Rangoon",
    [104] "ICT (GMT+07:00) Bangkok",
    [105] "ICT (GMT+07:00) Hanoi",
    [106] "WIB (GMT+07:00) Jakarta",
    [107] "NOVT (GMT+07:00) Novosibirsk",
    [108] "CST (GMT+08:00) Beijing",
    [109] "CST (GMT+08:00) Chongqing",
    [110] "HKT (GMT+08:00) Hong Kong",
    [111] "KRAT (GMT+08:00) Krasnoyarsk",
    [112] "MYT (GMT+08:00) Kuala Lumpur",
    [113] "WST (GMT+08:00) Perth",
    [114] "SGT (GMT+08:00) Singapore",
    [115] "CST (GMT+08:00) Taipei",
    [116] "ULAT (GMT+08:00) Ulaanbaatar",
    [117] "CST (GMT+08:00) Urumqi",
    [118] "IRKT (GMT+09:00) Irkutsk",
    [119] "JST (GMT+09:00) Osaka",
    [120] "JST (GMT+09:00) Sapporo",
    [121] "KST (GMT+09:00) Seoul",
    [122] "JST (GMT+09:00) Tokyo",
    [123] "CST (GMT+09:30) Adelaide",
    [124] "CST (GMT+09:30) Darwin",
    [125] "EST (GMT+10:00) Brisbane",
    [126] "EST (GMT+10:00) Canberra",
    [127] "ChST (GMT+10:00) Guam",
    [128] "EST (GMT+10:00) Hobart",
    [129] "EST (GMT+10:00) Melbourne",
    [130] "PGT (GMT+10:00) Port Moresby",
    [131] "EST (GMT+10:00) Sydney",
    [132] "YAKT (GMT+10:00) Yakutsk",
    [133] "NCT (GMT+11:00) New Caledonia",
    [134] "SBT (GMT+11:00) Solomon Is.",
    [135] "VLAT (GMT+11:00) Vladivostok",
    [136] "NZST (GMT+12:00) Auckland",
    [137] "FJT (GMT+12:00) Fiji",
    [138] "PETT (GMT+12:00) Kamchatka",
    [139] "MAGT (GMT+12:00) Magadan",
    [140] "MHT (GMT+12:00) Marshall Is.",
    [141] "NZST (GMT+12:00) Wellington",
    [142] "CHAST (GMT+12:45) Chatham Is.",
    [143] "TOT (GMT+13:00) Nuku'alofa",
    [144] "WST (GMT+13:00) Samoa",
    [145] "TKT (GMT+13:00) Tokelau Is."
]
```
@onenight
Copy link

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
Copy link

@onenight This is because in the latest version, wongyouth@ab91e6d is reverted.

@Novtopro
Copy link

You can use a custom template to solve this problem.

blog.new_article_template = File.expand_path '../your_template.tt', __FILE

@alexrodba
Copy link

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
Copy link
Contributor

iwarner commented Mar 23, 2017

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

eellson added a commit to eellson/middleman-blog that referenced this issue Jan 27, 2018
As of https://github.com/middleman/middleman/pull/1293/files middleman
splits the notion of `:mode` and `:config`. This PR updates
middleman-blog to also handle this distinction.

This allows generation of blogposts using config for a particular
environment using the `--environment` flag. e.g:

`middleman article 'Awesome new post' --environment blog would look for
config within the `configure :blog do ...` block.

The main gotcha I see is that this requires `Time.zone` to be set in
config.rb also. I wonder though if that is related to one of the various
other date-related issues:
middleman#238,
middleman#191,
middleman#143
@markets markets closed this as completed Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants