Neil Middleton
Neil Middleton

Reputation: 22238

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?

Upvotes: 6

Views: 2627

Answers (5)

prashantsahni
prashantsahni

Reputation: 2195

I made blog folder inside source directory. Then i make posts directory and moved all my posts there. source/blog/posts/...

and then inside config.rb

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

Upvotes: 0

Mo Morsi
Mo Morsi

Reputation: 111

The solution above worked for me when I made the following changes to the permalink / source config options:

blog.permalink = ":title.html"
blog.sources   = "posts/:year-:month-:day-:title.html"

The permalink is the location which it will appear in the web browser url where the source is the locations of the posts.

Using middleman 3.2.1

Upvotes: 0

cutemachine
cutemachine

Reputation: 6210

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.

Upvotes: 11

Neil Middleton
Neil Middleton

Reputation: 22238

From looking at the code it transpires there is a :sources option which you can use. If you poke around in the source there is an example of this:

https://github.com/middleman/middleman-blog/tree/master/fixtures/article-dirs-app

Upvotes: 0

Ryan Daigle
Ryan Daigle

Reputation: 11667

I messed with the middleman-blog extension, but gave up for its relative opaqueness. In looking at the source, though, it appears the prefix option might do the trick for you? It's somewhat unclear whether the prefix is a URL prefix or a local path prefix:

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

Upvotes: 0

Related Questions