Writing a blog: Organizing of Posts and Bulma-like pagination

Hello all!

I discovered Middleman a couple of weeks, and I’d like to use it for blogging.

My only questions so far are these:

Can posts be their own subdirectory in source/? Inside the activate :blog do |blog| I have

  blog.prefix = "posts"
  blog.permalink = "posts/{year}-{month}-{day}-{title}.html"
  # Matcher for blog source files
  blog.sources = "posts/{year}-{month}-{day}-{title}.html"

and in source I made a posts directory. And on that same note, is it necessary to place a posts.html.erb file inside of that directory?

Second question: Bulma-like pagination, how to? Basing from what their docs say on pagination, I’d imagine it’d be sane to do it like so

<% if paginate && num_pages > 1 %>
    <nav class="pagination">
        <% if prev_page %%>
            <%= link_to 'Previous', prev_page, :class => 'pagination-previous' %>
        <% end %>
        <% if paginate %>
            <ul class="pagination-list">
                <% [1...articles.length].each do |n| %>
                    <li>
                        <a class="pagination-link" href="<%= page_link %>"><%= n %></a>
                    </li>
                <% end %>
            </ul>
        <% end %>
        <% if paginate %>
            <% if next_page %>
                <%= link_to 'Next', next_page, :class => 'pagination-next' %>
            <% end %>
        <% end %>
    </nav>
<% else %>
    <br />
<% end %>

I grabbed articles.length from what was listed here.

And here’s my entire blog section of my config.rb if that helps.

activate :blog do |blog|
  # This will add a prefix to all links, template references and source paths
  blog.prefix = "posts"
  blog.permalink = "posts/{year}-{month}-{day}-{title}.html"
  # Matcher for blog source files
  blog.sources = "posts/{year}-{month}-{day}-{title}.html"
  blog.taglink = "categories/{tag}.html"
  # blog.layout = "layout"
  blog.summary_separator = /(READMORE)/
  blog.summary_length = 250
  # blog.year_link = "{year}.html"
  # blog.month_link = "{year}/{month}.html"
  # blog.day_link = "{year}/{month}/{day}.html"
  # blog.default_extension = ".markdown"

  blog.tag_template = "tag.html"
  blog.calendar_template = "calendar.html"

  # Enable pagination
  blog.paginate = true
  blog.per_page = 5
  blog.page_link = "page/{num}"
end

Thanks for any help/advice/tips you give!

1 Like

Sure, I have my posts in {year} subdirs, so I have: /source/2014/…, /source/2015/…, etc. But I’m pretty sure you don’t need blog.prefix = "posts" for this, since it defines a global prefix for the whole blog, so you will end up with http://mysite.com/posts/posts/… (read this).

Also, as a sidenote, you don’t need secondary checks for pagination (lines 6 and 15 of your template-code), since you are already inside an <% if paginate && num_pages > 1 %> statement, which guarantees pagination active.