Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Tighten up matcher for blog article sources #33

Merged
merged 1 commit into from

2 participants

@bhollis
Owner

Before, the matcher that we generated would match all kinds of paths that had the blog article pattern anywhere within them - this change locks it down so only paths exactly matching the blog_sources setting get matched.

@tdreyno tdreyno merged commit 3f32f21 into middleman:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 25, 2012
  1. @bhollis
This page is out of date. Refresh to see the latest.
View
2  features/article_cli.feature
@@ -4,4 +4,4 @@ Feature: New article CLI command
And I run `middleman article "My New Article" --date 2012-03-17`
Then the exit status should be 0
Then the following files should exist:
- | source/2012-03-17-my-new-article.html.markdown |
+ | source/blog/2012-03-17-my-new-article.html.markdown |
View
2  fixtures/blog-sources-app/config.rb
@@ -1,2 +1,2 @@
activate :blog
-set :blog_sources, ":year-:month-:day-:title.html"
+set :blog_sources, "blog/:year-:month-:day-:title.html"
View
37 lib/middleman-blog/extension.rb
@@ -31,15 +31,18 @@ def registered(app)
set :blog_day_template, blog_calendar_template
end
- matcher = blog_sources.dup
- matcher.sub!(":year", "(\\d{4})")
- matcher.sub!(":month", "(\\d{2})")
- matcher.sub!(":day", "(\\d{2})")
- matcher.sub!(":title", "(.*)")
- BlogData.matcher = /#{matcher}/
+ matcher = Regexp.escape(blog_sources).
+ sub(/^\//, "").
+ sub(":year", "(\\d{4})").
+ sub(":month", "(\\d{2})").
+ sub(":day", "(\\d{2})").
+ sub(":title", "(.*)")
+
+ path_matcher = /^#{matcher}/
+ file_matcher = /^#{source_dir}\/#{matcher}/
sitemap.reroute do |destination, page|
- if page.path =~ BlogData.matcher
+ if page.path =~ path_matcher
# This doesn't allow people to omit one part!
year = $1
month = $2
@@ -49,25 +52,25 @@ def registered(app)
# compute output path:
# substitute date parts to path pattern
# get date from frontmatter, path
- blog_permalink.dup.
- sub!(':year', year).
- sub!(':month', month).
- sub!(':day', day).
- sub!(':title', title)
+ blog_permalink.
+ sub(':year', year).
+ sub(':month', month).
+ sub(':day', day).
+ sub(':title', title)
else
destination
end
end
- frontmatter_changed BlogData.matcher do |file|
+ frontmatter_changed file_matcher do |file|
blog.touch_file(file)
end
- self.files.deleted BlogData.matcher do |file|
+ self.files.deleted file_matcher do |file|
self.blog.remove_file(file)
end
- provides_metadata BlogData.matcher do
+ provides_metadata file_matcher do
{
:options => {
:layout => blog_layout
@@ -131,10 +134,6 @@ def registered(app)
end
class BlogData
- class << self
- attr_accessor :matcher
- end
-
def initialize(app)
@app = app
Something went wrong with that request. Please try again.