Closed judge-red closed 7 years ago
Something like this, I think.
blog = activate :blog
ready do
blog.tags.each do |tag, articles|
proxy "/tags/#{tag}/atom.xml", "/atom.xml", layout: false, locals: { tagname: tag, articles: articles }
end
end
@tdreyno exact same error:
/home/red_trela/git/blog/config.rb:79:in `block in evaluate_configuration!': undefined method `tags' for #<Middleman::BlogExtension:0x005608fead3ec0> (NoMethodError)
from /home/red_trela/.gem/ruby/gems/middleman-core-4.0.0/lib/middleman-core/callback_manager.rb:51:in `instance_exec'
from /home/red_trela/.gem/ruby/gems/middleman-core-4.0.0/lib/middleman-core/callback_manager.rb:51:in `block in execute'
from /home/red_trela/.gem/ruby/gems/hamster-2.0.0/lib/hamster/vector.rb:1316:in `each'
from /home/red_trela/.gem/ruby/gems/hamster-2.0.0/lib/hamster/vector.rb:1316:in `traverse_depth_first'
from /home/red_trela/.gem/ruby/gems/hamster-2.0.0/lib/hamster/vector.rb:431:in `each'
from /home/red_trela/.gem/ruby/gems/middleman-core-4.0.0/lib/middleman-core/callback_manager.rb:51:in `execute'
from /home/red_trela/.gem/ruby/gems/middleman-core-4.0.0/lib/middleman-core/callback_manager.rb:28:in `block in install_methods!'
from /home/red_trela/.gem/ruby/gems/middleman-core-4.0.0/lib/middleman-core/callback_manager.rb:52:in `instance_exec'
from /home/red_trela/.gem/ruby/gems/middleman-core-4.0.0/lib/middleman-core/callback_manager.rb:52:in `block in execute'
from /home/red_trela/.gem/ruby/gems/hamster-2.0.0/lib/hamster/vector.rb:1316:in `each'
from /home/red_trela/.gem/ruby/gems/hamster-2.0.0/lib/hamster/vector.rb:1316:in `traverse_depth_first'
from /home/red_trela/.gem/ruby/gems/hamster-2.0.0/lib/hamster/vector.rb:431:in `each'
from /home/red_trela/.gem/ruby/gems/middleman-core-4.0.0/lib/middleman-core/callback_manager.rb:52:in `execute'
from /home/red_trela/.gem/ruby/gems/middleman-core-4.0.0/lib/middleman-core/callback_manager.rb:28:in `block in install_methods!'
from /home/red_trela/.gem/ruby/gems/middleman-core-4.0.0/lib/middleman-core/application.rb:292:in `start_lifecycle'
from /home/red_trela/.gem/ruby/gems/middleman-core-4.0.0/lib/middleman-core/application.rb:265:in `initialize'
from /home/red_trela/.gem/ruby/gems/middleman-cli-4.0.0/lib/middleman-cli/build.rb:51:in `new'
from /home/red_trela/.gem/ruby/gems/middleman-cli-4.0.0/lib/middleman-cli/build.rb:51:in `build'
from /home/red_trela/.gem/ruby/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from /home/red_trela/.gem/ruby/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /home/red_trela/.gem/ruby/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
from /home/red_trela/.gem/ruby/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
from /home/red_trela/.gem/ruby/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
from /home/red_trela/.gem/ruby/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
from /home/red_trela/.gem/ruby/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
from /home/red_trela/.gem/ruby/gems/thor-0.19.1/lib/thor/invocation.rb:115:in `invoke'
from /home/red_trela/.gem/ruby/gems/thor-0.19.1/lib/thor.rb:40:in `block in register'
from /home/red_trela/.gem/ruby/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from /home/red_trela/.gem/ruby/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /home/red_trela/.gem/ruby/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
from /home/red_trela/.gem/ruby/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from /home/red_trela/.gem/ruby/gems/middleman-cli-4.0.0/bin/middleman:23:in `<top (required)>'
from /home/red_trela/bin/middleman:23:in `load'
from /home/red_trela/bin/middleman:23:in `<main>'
There is an example in the docs of generic tags for MM (outside of blog features): https://middlemanapp.com/basics/upgrade-v4/
I wrestled with this for a few hours last night and ended up here, figured I'd point out how I fixed it in case anyone does the same.
Move your ready
block to after the activate(:blog) do; ...; end
lines and use blog.data
to access articles and tags.
Here's how I'm using it to generate xml and json files for each published article:
blog = activate(:blog) do |blog|
# Config here...
end
ready do
blog.data.articles.each do |article|
proxy article.destination_path.gsub(".html", ".json"), "blog/article.json", locals: { article: article } if environment?(:development) || article.published?
proxy article.destination_path.gsub(".html", ".xml"), "blog/article.xml", locals: { article: article } if environment?(:development) || article.published?
end
ignore "/blog/article.json"
ignore "/blog/article.xml"
end
I would say some note in the documentation and this issue could be closed.
@RyanScottLewis I do not believe you can access the blog articles in this fashion any longe, perhaps using sitemap.reources and checking that the template is a blog article may.
I use this for instance : you can easily manipulate I think to work of the Tag Template - I set a template : true in each templates frontmatter, maybe set tagTemplate : true on the tag one.
##
# Ready hook
# Add options to international template pages
##
ready do
# Get all the french tags
sitemap.resources.select{ | d | d.data.template }.each do | resource |
if resource.path[ 0...5 ] === locale.to_s
# puts "Process #{ resource.path }"
resource.add_metadata options: {
locale: locale,
lang: locale
}
end
end
end
Closing, please re-open if still an issue
It seems that in Middleman v3, it was possible to create rss/atom feeds per tag like described here: https://forum.middlemanapp.com/t/middleman-blog-rss-feeds-per-tag/1478
However, this method seems to be using a state bug that was fixed in v4, according to this issue: https://github.com/middleman/middleman/issues/1831
How else can this be achieved?
Also, as a feature request: could this be implemented as a feature of this extension, so we can simply say
blog.tag_feeds = true
?