Closed dwcramer closed 5 years ago
:+1: would love to use middleman 4 :-D
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.
Thanks @tdreyno, looking forward to using some of the new middleman 4 stuff!
This is still a problem in middleman (4.0.0.beta.2) and middleman-blog (3.6.0.beta.2)
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.
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 = 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
@fgarcia Can you describe the current issue more fully? Where does this occur? What errors are shown?
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!
Thanks for the thorough description, @fgarcia. Did this work on v3?
I've just tested in a fresh new project articles without a date in their filename and yes, it works on v3
Wonder if these are all connected also : #191 #143
@fgarcia Been a while but is this still an issue?
Still an issue for me. did this get resolved?
Oh, i retried by using the cli to create the file, not just doing manually and now works.
This ticket is very old. If you're still having issues on the current release, please open a new ticket.
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>'
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"
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