Moving blog articles location in Middleman
Asked Answered
A

5

6

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?

Alby answered 14/1, 2013 at 12:9 Comment(0)
L
11

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.

Laxity answered 8/2, 2013 at 10:28 Comment(1)
This failed for me with latest middleman and rails 4, the feed.xml fails and it still writes to /posts/* the blogpostsCharleton
A
0

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
Annalisaannalise answered 15/1, 2013 at 14:38 Comment(1)
Hmm, odd. The source seems to be loading from a File object which made me think it would suit the purpose here. Oh well.Annalisaannalise
A
0

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

Alby answered 16/1, 2013 at 19:7 Comment(2)
I saw that, but was confused as the default :sources option seems to be more about the filename format: options.sources ||= ":year-:month-:day-:title.html".Annalisaannalise
Same here, it wasn't until I saw the fixture prefixed with a folder did the light bulb go on.Alby
M
0

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

Motorcar answered 1/1, 2014 at 17:21 Comment(0)
G
0

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
Grassgreen answered 23/6, 2014 at 13:45 Comment(1)
Now all the urls are prefixed with /blogGrassgreen

© 2022 - 2024 — McMap. All rights reserved.