Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving blog articles location in Middleman

I'm using the Middleman Blog gem for my site, but by default it appears the blog articles need to be located in /source which isn't particularly nice when looking at the tree in vim and trying to locate one of the other files in there (a template for instance).

From looking at the documentation I can't see if there is any way of moving the blog articles so they are stored somewhere else such as a blog_articles folder or similar.

Is this possible?

like image 539
Neil Middleton Avatar asked Jan 14 '13 12:01

Neil Middleton


1 Answers

Put the following in your config.rb file.

activate :blog do |blog|
  blog.permalink = ":year-:month-:day-:title.html"
  blog.sources = "blog_articles/:title.html"
end

Assuming you have a post 2012-01-01-example-article.html.markdown stored in the folder source/blog_articles.

You should now see the post with this URL: http://localhost:4567/2012-01-01-example-article.html. (You might have to restart middleman when changing the config.rb file.)

Please note that I also had to set blog.permalink, the blog.sources setting alone didn't do the trick.

A bonus tip: I have activate :directory_indexes in my config.rb file. This setting gives you nice looking URLs, without the .html part. If you want the same for your blog posts you can drop the .html from your blog.permalinksetting. Like so:

activate :blog do |blog|
  blog.permalink = ":year-:month-:day-:title"
  blog.sources = "blog_articles/:title.html"
end

Now you can see your post with this URL: http://localhost:4567/2012-01-01-example-article.

like image 170
cutemachine Avatar answered Sep 28 '22 10:09

cutemachine