Check that teaser isn't too long before compiling

This commit is contained in:
Jez Cope 2016-03-29 19:50:07 +01:00
parent 3aed8e03c7
commit d73e2f8b0c
3 changed files with 19 additions and 0 deletions

2
Rules
View File

@ -15,6 +15,8 @@ preprocess do
articles.each {|item| item[:page_type] = 'single-post'}
@items.each {|item| item[:page_type] ||= 'static-page'}
validate_items
end
# Compilation ##################################################################

14
lib/validation.rb Normal file
View File

@ -0,0 +1,14 @@
def validate_items
validate_teasers
end
def validate_teasers
@config[:validation] ||= {}
@config[:validation][:teaser_length] ||= 120
@items.each do |i|
if i.key? :teaser and i[:teaser].length > @config[:validation][:teaser_length]
raise "Teaser too long for #{i.identifier}: #{i[:teaser].length} (should be #{@config[:validation][:teaser_length]})"
end
end
end

View File

@ -15,6 +15,9 @@ openid_id: http://www.google.com/profiles/jez.cope
page_size: 10
validation:
teaser_length: 110
# A list of file extensions that nanoc will consider to be textual rather than
# binary. If an item with an extension not in this list is found, the file
# will be considered as binary.