middleman / middleman-blog

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

Date error when running latest middleman-blog against middleman 4 alpha 6 #238

Closed dwcramer closed 5 years ago

dwcramer commented 9 years ago

I'm seeing the error below when I use middleman-blog (from github) with middleman 4 alpha 6 running ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin13]. A small site that illustrates the bug is here https://github.com/dwcramer/middleman-4-blog-bug

== The Middleman is loading
/Users/davcrame/.bundler/ruby/2.0.0/middleman-blog-a1a34b6ac735/lib/middleman-blog/blog_article.rb:185:in `date': Blog post blog/posts/2014-11-10-internalbeta.html needs a date in its filename or frontmatter (RuntimeError)
    from /Users/davcrame/.bundler/ruby/2.0.0/middleman-blog-a1a34b6ac735/lib/middleman-blog/blog_data.rb:154:in `permalink_options'
    from /Users/davcrame/.bundler/ruby/2.0.0/middleman-blog-a1a34b6ac735/lib/middleman-blog/blog_data.rb:173:in `template_path'
    from /Users/davcrame/.bundler/ruby/2.0.0/middleman-blog-a1a34b6ac735/lib/middleman-blog/blog_data.rb:97:in `block in manipulate_resource_list'
    from /Users/davcrame/.bundler/ruby/2.0.0/middleman-blog-a1a34b6ac735/lib/middleman-blog/blog_data.rb:80:in `each'
    from /Users/davcrame/.bundler/ruby/2.0.0/middleman-blog-a1a34b6ac735/lib/middleman-blog/blog_data.rb:80:in `manipulate_resource_list'
    from /Library/Ruby/Gems/2.0.0/gems/middleman-core-4.0.0.alpha.6/lib/middleman-core/sitemap/store.rb:181:in `block (2 levels) in ensure_resource_list_updated!'
    from /Library/Ruby/Gems/2.0.0/gems/middleman-core-4.0.0.alpha.6/lib/middleman-core/sitemap/store.rb:180:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/middleman-core-4.0.0.alpha.6/lib/middleman-core/sitemap/store.rb:180:in `reduce'
    from /Library/Ruby/Gems/2.0.0/gems/middleman-core-4.0.0.alpha.6/lib/middleman-core/sitemap/store.rb:180:in `block in ensure_resource_list_updated!'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
    from /Library/Ruby/Gems/2.0.0/gems/middleman-core-4.0.0.alpha.6/lib/middleman-core/sitemap/store.rb:174:in `ensure_resource_list_updated!'
    from /Library/Ruby/Gems/2.0.0/gems/middleman-core-4.0.0.alpha.6/lib/middleman-core/sitemap/extensions/on_disk.rb:21:in `block in initialize'
    from /Library/Ruby/Gems/2.0.0/gems/uber-0.0.13/lib/uber/options.rb:80:in `instance_exec'
    from /Library/Ruby/Gems/2.0.0/gems/uber-0.0.13/lib/uber/options.rb:80:in `proc!'
    from /Library/Ruby/Gems/2.0.0/gems/uber-0.0.13/lib/uber/options.rb:69:in `evaluate_for'
    from /Library/Ruby/Gems/2.0.0/gems/uber-0.0.13/lib/uber/options.rb:60:in `evaluate'
    from /Library/Ruby/Gems/2.0.0/gems/hooks-0.4.0/lib/hooks/hook.rb:53:in `execute_callback'
    from /Library/Ruby/Gems/2.0.0/gems/hooks-0.4.0/lib/hooks/hook.rb:40:in `block in run'
    from /Library/Ruby/Gems/2.0.0/gems/hooks-0.4.0/lib/hooks/hook.rb:39:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/hooks-0.4.0/lib/hooks/hook.rb:39:in `inject'
    from /Library/Ruby/Gems/2.0.0/gems/hooks-0.4.0/lib/hooks/hook.rb:39:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/hooks-0.4.0/lib/hooks.rb:55:in `run_hook_for'
    from /Library/Ruby/Gems/2.0.0/gems/hooks-0.4.0/lib/hooks/instance_hooks.rb:6:in `run_hook'
    from /Library/Ruby/Gems/2.0.0/gems/middleman-core-4.0.0.alpha.6/lib/middleman-core/application.rb:264:in `initialize'
    from /Library/Ruby/Gems/2.0.0/gems/middleman-core-4.0.0.alpha.6/lib/middleman-core/preview_server.rb:100:in `new'
    from /Library/Ruby/Gems/2.0.0/gems/middleman-core-4.0.0.alpha.6/lib/middleman-core/preview_server.rb:100:in `new_app'
    from /Library/Ruby/Gems/2.0.0/gems/middleman-core-4.0.0.alpha.6/lib/middleman-core/preview_server.rb:24:in `start'
    from /Library/Ruby/Gems/2.0.0/gems/middleman-cli-4.0.0.alpha.6/lib/middleman-cli/server.rb:69:in `server'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor/invocation.rb:115:in `invoke'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor.rb:40:in `block in register'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /Library/Ruby/Gems/2.0.0/gems/middleman-cli-4.0.0.alpha.6/bin/middleman:23:in `<top (required)>'
    from /Library/Ruby/Gems/2.0.0/bin/middleman:23:in `load'
    from /Library/Ruby/Gems/2.0.0/bin/middleman:23:in `<main>'
jkatsnelson commented 9 years ago

:+1: would love to use middleman 4 :-D

tdreyno commented 9 years ago

Thanks @dwcramer

We're going to prioritize getting the core to beta this month, then will make sure all the core extensions are ready the following month.

dwcramer commented 9 years ago

Thanks @tdreyno, looking forward to using some of the new middleman 4 stuff!

bashaus commented 9 years ago

This is still a problem in middleman (4.0.0.beta.2) and middleman-blog (3.6.0.beta.2)

fgarcia commented 9 years ago

just run into this problem myself. Something strange is happening with the HashWithIndiferentAccess holding the article data. It has no values, and setting them during debugging has no effect either, it remains empty.

fgarcia commented 9 years ago

If this helps finding a solution I found out BlogData is not working properly at the moment the date is retrieved, so I decided to manually parse the template file like this:

https://github.com/middleman/middleman-blog/blob/78190cf890deee309485041abbbe0a6f7ccba8bc/lib/middleman-blog/blog_article.rb#L162

    # frontmatter_date = data['date']
    frontmatter_date = YAML.load_file(source_file.full_path)["date"].to_time

That is a quite dirty hack, but it gets the blog working again. The interesting thing is that later, rendering the template pulls out fine the other front matter variables

tdreyno commented 9 years ago

@fgarcia Can you describe the current issue more fully? Where does this occur? What errors are shown?

fgarcia commented 9 years ago

Sure!

On v4 this error is raised because the date from data['date'] could not be retrieved here (got nil instead)

While debugging I noticed that at this point BlogData was completely empty and although source_file had the right article path, no value from the frontmatter was read.

It seems this error only appears with configurations where the date is not encoded in the filename itself. Therefore the default configuration hides this glitch because the code afterwards parses the filename date. As en example, this is my blog configuration:

activate :blog do |blog|
  blog.permalink = "blog/:year/:title"
  blog.sources = "articles/:year/:title/index.html"
end

As I mentioned before, parsing manually the article yaml date makes everything work perfectly, even the tags are shown!

I am not sure if it is related, but I also had some problems with relative assets

Hope that helps solving the issue!

tdreyno commented 9 years ago

Thanks for the thorough description, @fgarcia. Did this work on v3?

fgarcia commented 9 years ago

I've just tested in a fresh new project articles without a date in their filename and yes, it works on v3

iwarner commented 7 years ago

Wonder if these are all connected also : #191 #143

@fgarcia Been a while but is this still an issue?

asecondwill commented 5 years ago

Still an issue for me. did this get resolved?

asecondwill commented 5 years ago

Oh, i retried by using the cli to create the file, not just doing manually and now works.

tdreyno commented 5 years ago

This ticket is very old. If you're still having issues on the current release, please open a new ticket.

kergma-lw commented 2 years ago

There is date in frontmatter as:

date: 2009-03-01

bundle exec middleman  build 
== Blog Sources: data/verses/{title} (:prefix + :sources)
/home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-blog-4.0.3/lib/middleman-blog/blog_article.rb:229:in `date': Blog post data/verses/verse-086 needs a date in its filename or frontmatter (RuntimeError)
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-blog-4.0.3/lib/middleman-blog/blog_article.rb:86:in `published?'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-blog-4.0.3/lib/middleman-blog/blog_data.rb:193:in `publishable?'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-blog-4.0.3/lib/middleman-blog/blog_data.rb:138:in `block in manipulate_resource_list'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-blog-4.0.3/lib/middleman-blog/blog_data.rb:129:in `each'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-blog-4.0.3/lib/middleman-blog/blog_data.rb:129:in `manipulate_resource_list'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/sitemap/store.rb:234:in `block (4 levels) in ensure_resource_list_updated!'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.4.4/lib/active_support/notifications.rb:205:in `instrument'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/util.rb:21:in `instrument'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/sitemap/store.rb:232:in `block (3 levels) in ensure_resource_list_updated!'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/hamster-3.0.0/lib/hamster/vector.rb:1316:in `each'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/hamster-3.0.0/lib/hamster/vector.rb:1316:in `traverse_depth_first'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/hamster-3.0.0/lib/hamster/vector.rb:431:in `each'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/sitemap/store.rb:231:in `block (2 levels) in ensure_resource_list_updated!'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.4.4/lib/active_support/notifications.rb:205:in `instrument'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/util.rb:21:in `instrument'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/sitemap/store.rb:224:in `block in ensure_resource_list_updated!'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/sitemap/store.rb:221:in `synchronize'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/sitemap/store.rb:221:in `ensure_resource_list_updated!'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/sitemap/extensions/on_disk.rb:21:in `ready'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/callback_manager.rb:57:in `instance_exec'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/callback_manager.rb:57:in `block in execute'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/hamster-3.0.0/lib/hamster/vector.rb:1316:in `each'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/hamster-3.0.0/lib/hamster/vector.rb:1316:in `traverse_depth_first'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/hamster-3.0.0/lib/hamster/vector.rb:431:in `each'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/callback_manager.rb:57:in `execute'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/contracts-0.13.0/lib/contracts/method_reference.rb:43:in `send_to'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/contracts-0.13.0/lib/contracts/call_with.rb:76:in `call_with'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/contracts-0.13.0/lib/contracts/method_handler.rb:138:in `block in redefine_method'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/callback_manager.rb:28:in `block in install_methods!'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/application.rb:309:in `initialize'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-cli-4.4.2/lib/middleman-cli/build.rb:67:in `new'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-cli-4.4.2/lib/middleman-cli/build.rb:67:in `block in build'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.4.4/lib/active_support/notifications.rb:205:in `instrument'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-core-4.4.2/lib/middleman-core/util.rb:21:in `instrument'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-cli-4.4.2/lib/middleman-cli/build.rb:66:in `build'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:134:in `block in invoke_all'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:134:in `each'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:134:in `map'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:134:in `invoke_all'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor/group.rb:232:in `dispatch'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:116:in `invoke'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor.rb:40:in `block in register'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor/base.rb:485:in `start'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/gems/middleman-cli-4.4.2/bin/middleman:70:in `<top (required)>'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/bin/middleman:23:in `load'
    from /home/ww/tmp/test-site/vendor/bundle/ruby/3.0.0/bin/middleman:23:in `<main>'
    from /usr/local/rvm/rubies/ruby-3.0.0/bin/ruby_executable_hooks:22:in `eval'
    from /usr/local/rvm/rubies/ruby-3.0.0/bin/ruby_executable_hooks:22:in `<main>'
noniq commented 2 years ago

I came across this issue right now. For me it seems to have been caused by Psych 4.x, which does no longer support deserializing classes like Time and Date by default (see https://github.com/ruby/psych/pull/487). Psych 4.x is the default in recent Ruby versions, so here you go …

Note that this only happens if the date or time values in the YAML frontmatter are unquoted (and thus not loaded as strings, but interpreted as instances of Date or Time):

date: 2022-02-22 # won't work
date: "2022-02-22" # works

TL;DR: The fix is to make sure the dates / times in the YAML frontmatter are quoted.


More details

To verify that this is indeed the problem run

bundle exec ruby -e "require 'yaml'; YAML.load_file('source/articles/example.md')"

and see if it gives an error like Tried to load unspecified class: Time (Psych::DisallowedClass).

If for any reason you want to keep the bare date / time values in the frontmatter, a possible workaround is to explicitly specify an older version of Psych in the Gemfile:

gem "psych", "< 4"