Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow options.sources to contain the same date component multiple times #112

Merged
merged 1 commit into from

3 participants

@johndbritton

I organize my blog posts into folders by year, like so:

posts/
├── 2008
│   └── 2008-12-15-title.md
├── 2009
│   └── 2009-10-23-title.md
├── 2010
│   └── 2010-08-26-title.md
├── 2011
│   └── 2011-10-27-title.md
└── 2012
    └── 2012-10-29-title.md

In configuring middleman-blogs sources option, I expected support for file name globbing, but was unable to use the expected globing pattern:

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

Adding globbing support seemed like it might be a fair bit of work based on the ways the sources option is used in the code, so I opted to add the ability to use date keywords multiple times in the sources option, like so:

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

@tdreyno tdreyno merged commit ad67955 into middleman:master
@tdreyno
Owner

Nice! Thanks

@johndbritton johndbritton deleted the unknown repository branch
@bhollis
Owner

Awesome. I like being explicit about the date components better than the globs, anyway.

@johndbritton

I would really like to have glob support, or the ability to add multiple source directories. Another thing I tried was this:

blog.sources = []
(2009..2013).each do |year|
  blog.sources << "/posts/#{year}/:year-:month-:day-:title"
end

If I organize posts by category, there's no easy way to add the different directories as sources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/middleman-blog/blog_data.rb
View
6 lib/middleman-blog/blog_data.rb
@@ -29,9 +29,9 @@ def initialize(app, options={}, controller=nil)
matcher = Regexp.escape(options.sources).
sub(/^\//, "").
- sub(":year", "(\\d{4})").
- sub(":month", "(\\d{2})").
- sub(":day", "(\\d{2})").
+ gsub(":year", "(\\d{4})").
+ gsub(":month", "(\\d{2})").
+ gsub(":day", "(\\d{2})").
sub(":title", "([^/]+)")
subdir_matcher = matcher.sub(/\\\.[^.]+$/, "(/.*)$")
Something went wrong with that request. Please try again.