commit
b912fa9cac
3 changed files with 38 additions and 16 deletions
|
@ -24,4 +24,19 @@ Feature: Setting page settings through frontmatter
|
||||||
When I go to "/ignored/index.html"
|
When I go to "/ignored/index.html"
|
||||||
Then I should see "File Not Found"
|
Then I should see "File Not Found"
|
||||||
When I go to "/no_index/index.html"
|
When I go to "/no_index/index.html"
|
||||||
Then I should see "File Not Found"
|
Then I should see "File Not Found"
|
||||||
|
|
||||||
|
Scenario: Changing frontmatter in preview server
|
||||||
|
Given the Server is running at "frontmatter-settings-app"
|
||||||
|
When I go to "/ignored/index.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
And the file "source/ignored.html.erb" has the contents
|
||||||
|
"""
|
||||||
|
---
|
||||||
|
ignored: false
|
||||||
|
---
|
||||||
|
|
||||||
|
This file is no longer ignored.
|
||||||
|
"""
|
||||||
|
When I go to "/ignored/index.html"
|
||||||
|
Then I should see "This file is no longer ignored."
|
||||||
|
|
|
@ -140,6 +140,10 @@ module Middleman
|
||||||
# Setup custom rendering
|
# Setup custom rendering
|
||||||
register Middleman::CoreExtensions::Rendering
|
register Middleman::CoreExtensions::Rendering
|
||||||
|
|
||||||
|
# Parse YAML from templates. Must be before sitemap so sitemap
|
||||||
|
# extensions see updated frontmatter!
|
||||||
|
register Middleman::CoreExtensions::FrontMatter
|
||||||
|
|
||||||
# Sitemap
|
# Sitemap
|
||||||
register Middleman::Sitemap
|
register Middleman::Sitemap
|
||||||
|
|
||||||
|
@ -158,9 +162,6 @@ module Middleman
|
||||||
# i18n
|
# i18n
|
||||||
register Middleman::CoreExtensions::I18n
|
register Middleman::CoreExtensions::I18n
|
||||||
|
|
||||||
# Parse YAML from templates
|
|
||||||
register Middleman::CoreExtensions::FrontMatter
|
|
||||||
|
|
||||||
# Built-in Extensions
|
# Built-in Extensions
|
||||||
|
|
||||||
# Provide Apache-style index.html files for directories
|
# Provide Apache-style index.html files for directories
|
||||||
|
|
|
@ -15,14 +15,16 @@ module Middleman::CoreExtensions
|
||||||
# Parsing JSON frontmatter
|
# Parsing JSON frontmatter
|
||||||
require "active_support/json"
|
require "active_support/json"
|
||||||
|
|
||||||
app.after_configuration do
|
app.send :include, InstanceMethods
|
||||||
::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
|
|
||||||
|
|
||||||
app.send :include, InstanceMethods
|
|
||||||
|
|
||||||
|
app.before_configuration do
|
||||||
files.changed { |file| frontmatter_manager.clear_data(file) }
|
files.changed { |file| frontmatter_manager.clear_data(file) }
|
||||||
files.deleted { |file| frontmatter_manager.clear_data(file) }
|
files.deleted { |file| frontmatter_manager.clear_data(file) }
|
||||||
|
end
|
||||||
|
|
||||||
|
app.after_configuration do
|
||||||
|
::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
|
||||||
|
|
||||||
sitemap.register_resource_list_manipulator(
|
sitemap.register_resource_list_manipulator(
|
||||||
:frontmatter,
|
:frontmatter,
|
||||||
frontmatter_manager
|
frontmatter_manager
|
||||||
|
@ -54,9 +56,15 @@ module Middleman::CoreExtensions
|
||||||
@cache[p] ||= frontmatter_and_content(p)
|
@cache[p] ||= frontmatter_and_content(p)
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_data(path)
|
def clear_data(file)
|
||||||
p = normalize_path(File.expand_path(path, @app.root))
|
# Copied from Sitemap::Store#file_to_path, but without
|
||||||
@cache.delete(p)
|
# removing the file extension
|
||||||
|
file = File.expand_path(file, @app.root)
|
||||||
|
prefix = @app.source_dir.sub(/\/$/, "") + "/"
|
||||||
|
return unless file.include?(prefix)
|
||||||
|
path = file.sub(prefix, "")
|
||||||
|
|
||||||
|
@cache.delete(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse YAML frontmatter out of a string
|
# Parse YAML frontmatter out of a string
|
||||||
|
@ -115,15 +123,13 @@ module Middleman::CoreExtensions
|
||||||
|
|
||||||
if result = parse_yaml_front_matter(content)
|
if result = parse_yaml_front_matter(content)
|
||||||
data, content = result
|
data, content = result
|
||||||
data = ::Middleman::Util.recursively_enhance(data).freeze
|
|
||||||
elsif result = parse_json_front_matter(content)
|
elsif result = parse_json_front_matter(content)
|
||||||
data, content = result
|
data, content = result
|
||||||
data = ::Middleman::Util.recursively_enhance(data).freeze
|
|
||||||
else
|
else
|
||||||
data = {}
|
data = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
[data, content]
|
[::Middleman::Util.recursively_enhance(data).freeze, content]
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_path(path)
|
def normalize_path(path)
|
||||||
|
@ -185,4 +191,4 @@ module Middleman::CoreExtensions
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue