Middleman blog - How to ensure that article.path t

2019-07-21 14:35发布

I hope somebody can help -

In my Middleman project, I want the blog articles to be in a subdirectory inside /source/ (so for instance '/source/webdev/blog/). I've followed the instructions, and muddled through (I'm new to Middleman and a complete Ruby newbie) and got the links to appear when calling: article.path HOWEVER - the links appear as relative urls, regardless of what I set in config.rb.

I've disabled :relative_assets (didn't seem to make any difference anyway), and I'm not using 'directory_indexes'. Any help would be immense!

My config.rb looks like this:

activate :blog do |blog|
  # set options on blog
  blog.permalink = "/webdev/blog/{year}/{title}.html"    # but article.path ends up relative!
  blog.sources = "/webdev/blog/{year}/{title}.html"   
end

So my blog articles get built to /webdev/blog/2014/test-article.html, which is what I want.

In a partial that I'm hoping to use anywhere on the site, not just the homepage:

<ul>
     <% blog.articles.each do |article| %>
       <li>
         <%= link_to article.title, article.path %>
       </li>
     <% end %>
</ul>

This gives me a list of links, as expected, but with relative URLs - which means, yep, when the links list is on a page in /webdev/, they take me to /webdev/webdev/blog/2014/some-article.html grrrr...

What could I be doing wrong? Is there some setting in options I've missed?

Thanks in anticipation

2条回答
▲ chillily
2楼-- · 2019-07-21 15:19

The following configuration needs to be added to your config.rb:

activate :blog do |blog|
 blog.prefix = "webdev/blog"
end

Your blog posts should then be generated in your desired location.

查看更多
虎瘦雄心在
3楼-- · 2019-07-21 15:34

Well, this isn't quite the answer I was looking for, but I've managed to 'fix' the issue for now - not very elegantly, I'll admit (Did I mention I don't speak Ruby?).

After some desperate messing about, I physically added a forward slash to article.path like so:

= link_to article.title, '/'+ article.path

..and it worked.

I'm going with this for now.

I would still love to know if there is a real solution to this little problem out there...

查看更多
登录 后发表回答