middleman / middleman-blog

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

Page Articles with blog name #320

Closed iwarner closed 7 years ago

iwarner commented 7 years ago

Hiya

This does not produce the desired affects in rendering articles from the named blog

= page_articles( "portfolio" )

I have this on the index.html page

I have two blogs both named, it seems the first one is always rendered

Edit // Tried on another page other than index.html and I get the desired results

Using master also : middleman-blog (4.0.1)

Seems when Pageable is true and - page_articles( "portfolio" ) will default to the first blog, in this case it is not portfolio

When Pageable is false then page_articles( "portfolio" ) will show the portfolio blog.

Ok = page_articles( "portfolio" ) does not seem to work with pagination at all.

Viewing : http://localhost:8080/page/11/ and putting a name in page_articles simply renders the first page of the blog set, on each page transition

If I simply put - = page_articles it works if I append brackets at all i.e. = page_articles() then it does not paginate correctly. The brackets are required to call the blog name with this helper. Unless I am calling this helper incorrectly.

http://www.rubydoc.info/github/middleman/middleman-blog/Middleman/Blog/Helpers#page_articles-instance_method

In the helper:

Seems on index the meta is always called so we never get the blog name articles = meta[:locals]["articles"] || blog(blog_name).articles

And this return does not take into account the current page so returns the first X limit ? articles.first(limit) : articles

iwarner commented 7 years ago

Hiya any news on this

You can see this in action here: http://codeblender.net/ Click on the paging on the home page - transitions but brings up same articles!

iwarner commented 7 years ago

ok so the code that is the issue is in helpers.rb of middleman blog

This is called when naming a blog - and not when the name is missing

It will always show the first x blogs because it returns only that - it really should call the paginator class.

limit ? articles.first(limit)

  # Returns the list of articles to display on this particular page (when using pagination).
  # @param [Symbol, String] blog_name Optional name of the blog to use.
  # @return [Array<Middleman::Sitemap::Resource>]
  def page_articles(blog_name=nil)
    meta = current_resource.metadata
    limit = current_resource.data[:per_page]

    # "articles" local variable is populated by Calendar and Tag page generators
    # If it's not set then use the complete list of articles
    articles = meta[:locals]["articles"] || blog(blog_name).articles

    limit ? articles.first(limit) : articles
  end

Hope this helps - my ruby skills are still too new to fix such an issue, but learning.

spazione commented 7 years ago

same problem here

spazione commented 7 years ago

I found a solution: instead of use page_articles( "portfolio" ) I wrote inside the frontmatter blog: portfolio. After this the loop over the portfolio-items it works correctly with a working pagination

Resource: https://forum.middlemanapp.com/t/mulitple-blogs-specify-the-blog-name-blog-name-in-frontmatter-how/1588

iwarner commented 7 years ago

Many thanks I will test this now

iwarner commented 7 years ago

@spazione I can confirm this works closing

andreamoro commented 7 years ago

@iwarner @spazione can you guys confirm this solution still works for you? And if so, with which gem versions? I'm getting crazy as I get results without consistency regardless your suggestions and many other attempts I have done. Really annoyed now!

iwarner commented 7 years ago

@andreamoro Please provide your gem versions :)

I am always on the cutting edge preferring to pull from master rather than a deployed GEM.

i.e.

# Middleman core
# @see https://github.com/middleman
gem 'middleman-core',         git: 'https://github.com/middleman/middleman.git',              branch: 'master'
gem 'middleman-cli',          git: 'https://github.com/middleman/middleman.git',              branch: 'master'
gem 'middleman-blog',         git: 'https://github.com/middleman/middleman-blog.git',         branch: 'master'
gem 'middleman-livereload',   git: 'https://github.com/middleman/middleman-livereload.git',   branch: 'master'
gem 'middleman-syntax',       git: 'https://github.com/middleman/middleman-syntax.git',       branch: 'master'
gem 'middleman-autoprefixer', git: 'https://github.com/middleman/middleman-autoprefixer.git', branch: 'master'
gem 'middleman-minify-html',  git: 'https://github.com/middleman/middleman-minify-html.git',  branch: 'master'
andreamoro commented 7 years ago

Hey @iwarner I thought that without specifying anything in the gemfile, middleman was always pulling out from the master branch? Am I wrong?

BTW, below the "incriminated" gemfile

source 'https://rubygems.org'

gem 'middleman', '~> 4.2'
gem 'middleman-blog'
gem 'middleman-autoprefixer', '~> 2.7' # This is used for adding vendor prefixes to the CSS code
gem 'i18n', '~> 0.7.0'
gem "middleman-livereload"
gem 'nokogiri'
gem 'middleman-minify-html', '~> 3.4.1'
gem 'middleman-deploy', '~> 2.0.0.pre.alpha'
gem 'middleman-robots'
gem 'builder' 
gem "middleman-syntax"