Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Allow free placement of posts. #579

wants to merge 2 commits into from

3 participants


This patch allows posts files to be placed anywhere, not just in _posts directory. Instead of looking only in _posts, it selects all files with a prefixed date in their name. So things will still work fine for sites that use _posts.

This is helpful in my case b/c my posts are being ported from my Gollum wiki. If I had to put them in _posts I'd have to do additional staging and copying of files. After thinking about it, I realized that there wasn't any real barrier to allowing Jekyll to handle the free placement of posts, and really this simplifies the design a bit in general which is always nice.


I think this steers Jekyll away from the opinionated trajectory it has historically taken. It requires posts to be in _posts and pages elsewhere.

This would also be confusing if I had a post in some directory with a permalink structure in my config file which was /:year/:month/:day/:title. This post would no longer get parsed into the directory in which it was placed, but in the directory which matches its date and title as configured. This lends itself to a messy and unorganized source.

If you're porting over another blog, all posts should go in your posts directory, as specified. Or, they can be pages.

I would recommend against applying this approach to the master gem.


I don't really think so. Just because people can do something doesn't mean they will do something. No one wants things to be messy so that just won't happen. Most people will just go right along using _posts regardless.

However, after some further thought I do think it would be better to add a config option for designating posts. And it can default to ./_posts.

Note that I'm not porting from another blog. I am actually dual purposing my Gollum wiki as a website. Which is really cool --and why I am working so hard on it. It means I can edit my posts and pages online and then with a single command update my website.


So are you suggesting we add a posts config option which defaults to ./_posts but can be switched to any other dir or false?


or a glob. Yes.

Would false mean no posts?


You meant the regex that matches posts? That could work.

false was originally "decentralized", but it was an off-the-cuff idea.


So, after working on this I ended up not going as far as a glob/regexp config setting, but just being able to designate a custom posts directory.


So what does this pull request actually do now, basically make the _posts directory configurable?


Yes, but with one other difference. The posts directory could for instance be set to './' and it should still work, selecting out posts based on date prefix.

Note, I first tried to handle glob/regex but realized it would require more substantial alterations to the code than I felt comfortable attempting.


I think I can live without this now. I have another idea. As I've mentioned before I would like to use a Gollum wiki to edit files and then use Jekyll to transforms it into a static site. So what I can do is clone the wiki to _wiki/ directory and have a Jekyll plug-in that preprocess the _wiki files to copy them into the correct places in _posts/ and _pages/. I think that would work just fine. See any problems with that approach? If it does work, then the only thing left is for Jekyll to support the full gamut of markup formats that Gollum does, and then it would be complete solution.

@trans trans closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 17, 2012
  1. @trans

    Allow free placement of posts.

    trans authored
Commits on Jun 22, 2012
  1. @trans
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 6 deletions.
  1. +1 −0  lib/jekyll.rb
  2. +1 −1  lib/jekyll/post.rb
  3. +8 −5 lib/jekyll/site.rb
1  lib/jekyll.rb
@@ -60,6 +60,7 @@ module Jekyll
'destination' => File.join(Dir.pwd, '_site'),
'plugins' => File.join(Dir.pwd, '_plugins'),
'layouts' => '_layouts',
+ 'posts' => '_posts',
'future' => true,
'lsi' => false,
2  lib/jekyll/post.rb
@@ -33,7 +33,7 @@ def self.valid?(name)
# Returns <Post>
def initialize(site, source, dir, name)
@site = site
- @base = File.join(source, dir, '_posts')
+ @base = File.join(source, dir, site.post_dir)
@name = name
self.categories = dir.split('/').reject { |x| x.empty? }
13 lib/jekyll/site.rb
@@ -5,7 +5,8 @@ module Jekyll
class Site
attr_accessor :config, :layouts, :posts, :pages, :static_files,
:categories, :exclude, :include, :source, :dest, :lsi, :pygments,
- :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts
+ :permalink_style, :tags, :time, :future, :safe, :plugins,
+ :limit_posts, :post_dir
attr_accessor :converters, :generators
@@ -26,6 +27,7 @@ def initialize(config)
self.include = config['include'] || []
self.future = config['future']
self.limit_posts = config['limit_posts'] || nil
+ self.post_dir = config['posts']
@@ -131,6 +133,7 @@ def read_directories(dir = '')
entries.each do |f|
+ next if Post.valid?(f) # exclude posts
f_abs = File.join(base, f)
f_rel = File.join(dir, f)
@@ -149,16 +152,16 @@ def read_directories(dir = '')
- # Read all the files in <source>/<dir>/_posts and create a new Post
- # object with each one.
+ # Read all the files under <source>/<dir>/ that follow post pattern
+ # and create a new Post object with each one.
# dir - The String relative path of the directory to read.
# Returns nothing.
def read_posts(dir)
- base = File.join(self.source, dir, '_posts')
+ base = File.join(self.source, dir, post_dir)
return unless File.exists?(base)
- entries = Dir.chdir(base) { filter_entries(Dir['**/*']) }
+ entries = Dir.chdir(base) { filter_entries(Dir["**/[0-9]*"]) }
# first pass processes, but does not yet render post content
entries.each do |f|
Something went wrong with that request. Please try again.