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

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

Closed
dwcramer opened this issue Jan 22, 2015 · 16 comments
Closed
Labels

Comments

@dwcramer
Copy link

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

👍 would love to use middleman 4 :-D

@tdreyno
Copy link
Member

tdreyno commented Jan 22, 2015

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

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

@bashaus
Copy link

bashaus commented May 17, 2015

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

@fgarcia
Copy link

fgarcia commented May 25, 2015

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

fgarcia commented May 25, 2015

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:

frontmatter_date = data['date']

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

tdreyno commented May 26, 2015

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

@fgarcia
Copy link

fgarcia commented May 26, 2015

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

tdreyno commented May 26, 2015

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

@fgarcia
Copy link

fgarcia commented May 27, 2015

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

@iwarner
Copy link
Contributor

iwarner commented Mar 23, 2017

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

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

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

Still an issue for me. did this get resolved?

@asecondwill
Copy link

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

@tdreyno
Copy link
Member

tdreyno commented Aug 1, 2019

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

@tdreyno tdreyno closed this as completed Aug 1, 2019
@kergma-lw
Copy link

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

noniq commented Jul 3, 2022

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 ruby/psych#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"

Vin0uz added a commit to Vin0uz/webenvert.fr that referenced this issue Apr 17, 2023
Upgrading was required because bundling wasn't working locally + Ruby v2.7.3 is kinda old 👀

With the upgrade to latest ruby version came a few issues.

First, it required to add `net-ftp` to Gemfile, as it was blocking launch of middleman. I tried but could not really identify why this was needed, if somebody feels like exploring it and
giving feedback, I'd gladly hear it 😄

Second, with latest middleman came an issue with date, it was kinda ignored until we use quotes around them (aka. make them strings that need to be later on translated into dates), as stated in this issue resolving comment [on middleman-blog issue #238](middleman/middleman-blog#238 (comment))
Vin0uz added a commit to Vin0uz/webenvert.fr that referenced this issue Apr 17, 2023
Upgrading was required because bundling wasn't working locally + Ruby v2.7.3 is kinda old 👀

With the upgrade to latest ruby version came a few issues.

First, it required to add `net-ftp` to Gemfile, as it was blocking launch of middleman. I tried but could not really identify why this was needed, if somebody feels like exploring it and
giving feedback, I'd gladly hear it 😄

Second, with latest middleman came an issue with date, it was kinda ignored until we use quotes around them (aka. make them strings that need to be later on translated into dates), as stated in this issue resolving comment [on middleman-blog issue #238](middleman/middleman-blog#238 (comment))
mehlah pushed a commit to webenvert/webenvert.fr that referenced this issue May 2, 2023
Upgrading was required because bundling wasn't working locally + Ruby v2.7.3 is kinda old 👀

With the upgrade to latest ruby version came a few issues.

First, it required to add `net-ftp` to Gemfile, as it was blocking launch of middleman. I tried but could not really identify why this was needed, if somebody feels like exploring it and
giving feedback, I'd gladly hear it 😄

Second, with latest middleman came an issue with date, it was kinda ignored until we use quotes around them (aka. make them strings that need to be later on translated into dates), as stated in this issue resolving comment [on middleman-blog issue #238](middleman/middleman-blog#238 (comment))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants