middleman / middleman-blog

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

article command fails when using --blog option #300

Closed andrewcroce closed 7 years ago

andrewcroce commented 8 years ago

Using middleman 4.1.7 and middleman-blog 4.0.1

When I attempt to generate an article using the --blog option, it fails. For example, I have a blogs named "blog" and "work"

middleman article 'Test' --blog work I get:

/Users/andrewcroce/.rvm/gems/ruby-2.3.1/bundler/gems/middleman-blog-1f154d8846e2/lib/middleman-blog/commands/article.rb:55:in 'throw': uncaught throw "Could not find an active blog instance named work" (UncaughtThrowError)

Similar error for the "blog" blog.

The command works fine without specifying the --blog option, and defaults to the first blog "blog".

Heres the blog activations from my config:

activate :blog do |blog|
  blog.name = 'blog'
  blog.prefix = 'blog'
  blog.sources = "{year}/{month}/{day}-{title}/{title}.html"
  blog.new_article_template = File.expand_path('../source/blog/article.erb', __FILE__)
  blog.default_extension = '.markdown.erb'
  blog.permalink = "{title}.html"
  blog.taglink = 'tags/{tag}.html'
  blog.layout = "article"
  blog.paginate = true
  blog.tag_template = "tag"
  blog.summary_separator = /READMORE/
end

activate :blog do |blog|
  blog.name = 'work'
  blog.prefix = 'work'
  blog.sources = "{title}/{title}.html"
  blog.new_article_template = File.expand_path('../source/work/case_study.erb', __FILE__)
  blog.default_extension = '.markdown.erb'
  blog.permalink = "work/{title}.html"
  blog.layout = "case_study"
end

Thanks!

UPDATE: For the record, I have manually created article files in the "work" blog, and they do appear to be properly queried using blog(work).articles.

andrewcroce commented 8 years ago

Digging into this a bit, in article.rb line 46:

blog_inst = if options[:blog]
   app.extensions[:blog][options[:blog]]
else
   app.extensions[:blog].values.first
end

Its trying to access the blog instance by key, as if the keys were the same as the blog names. But they're not, the keys are instance_0 and instance_1.

kennethkalmer commented 8 years ago

Just to confirm this issue does exist.

danielschmid commented 8 years ago

Same here. I’m using the 4.0.1 middleman-blog gem. Any updates on this ?

andrewcroce commented 8 years ago

I just submitted a PR for this: #307. Note, this is really just a hack to get it working. I'm not a Ruby dev, just a Middleman user who needed this to work. There is certainly a better way to fix this, so the key names DO match the blog names.

amamel commented 7 years ago

Has this moved? Having the same issue.

iwarner commented 7 years ago

Hiya

@mamela The PR was merged into Master - https://github.com/middleman/middleman-blog/pull/307

Please reference this in your Gemfile for now

gem "middleman-blog", git: "https://github.com/middleman/middleman-blog.git", branch: "master"

Closing as PR merged - if still an issue please re-open