Merge commit 'fab8442432f473ba647c682608bc8ff9ced6cca2'
This commit is contained in:
commit
54d713b26a
|
@ -49,7 +49,13 @@ module Jekyll
|
|||
if self.data.has_key?('category')
|
||||
self.categories << self.data['category']
|
||||
elsif self.data.has_key?('categories')
|
||||
self.categories = self.data['categories'].split
|
||||
# Look for categories in the YAML-header, either specified as
|
||||
# an array or a string.
|
||||
if self.data['categories'].kind_of? String
|
||||
self.categories = self.data['categories'].split
|
||||
else
|
||||
self.categories = self.data['categories']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,16 +28,14 @@ module Jekyll
|
|||
self.transform_pages
|
||||
self.write_posts
|
||||
end
|
||||
|
||||
# Read all the files in <source>/_layouts except backup files
|
||||
# (end with "~") into memory for later use.
|
||||
|
||||
# Read all the files in <source>/_layouts into memory for later use.
|
||||
#
|
||||
# Returns nothing
|
||||
def read_layouts
|
||||
base = File.join(self.source, "_layouts")
|
||||
entries = Dir.entries(base)
|
||||
entries = entries.reject { |e| e[-1..-1] == '~' }
|
||||
entries = entries.reject { |e| File.directory?(File.join(base, e)) }
|
||||
entries = []
|
||||
Dir.chdir(base) { entries = filter_entries(Dir['*.*']) }
|
||||
|
||||
entries.each do |f|
|
||||
name = f.split(".")[0..-2].join(".")
|
||||
|
@ -47,17 +45,13 @@ module Jekyll
|
|||
# ignore missing layout dir
|
||||
end
|
||||
|
||||
# Read all the files in <base>/_posts except backup files (end with "~")
|
||||
# and create a new Post object with each one.
|
||||
# Read all the files in <base>/_posts and create a new Post object with each one.
|
||||
#
|
||||
# Returns nothing
|
||||
def read_posts(dir)
|
||||
base = File.join(self.source, dir, '_posts')
|
||||
|
||||
entries = []
|
||||
Dir.chdir(base) { entries = Dir['**/*'] }
|
||||
entries = entries.reject { |e| e[-1..-1] == '~' }
|
||||
entries = entries.reject { |e| File.directory?(File.join(base, e)) }
|
||||
Dir.chdir(base) { entries = filter_entries(Dir['**/*']) }
|
||||
|
||||
# first pass processes, but does not yet render post content
|
||||
entries.each do |f|
|
||||
|
@ -93,7 +87,7 @@ module Jekyll
|
|||
|
||||
# Copy all regular files from <source> to <dest>/ ignoring
|
||||
# any files/directories that are hidden or backup files (start
|
||||
# with "." or end with "~") or contain site content (start with "_")
|
||||
# with "." or "#" or end with "~") or contain site content (start with "_")
|
||||
# unless they are "_posts" directories or web server files such as
|
||||
# '.htaccess'
|
||||
# The +dir+ String is a relative path used to call this method
|
||||
|
@ -102,11 +96,7 @@ module Jekyll
|
|||
# Returns nothing
|
||||
def transform_pages(dir = '')
|
||||
base = File.join(self.source, dir)
|
||||
entries = Dir.entries(base)
|
||||
entries = entries.reject { |e| e[-1..-1] == '~' }
|
||||
entries = entries.reject do |e|
|
||||
(e != '_posts') and ['.', '_'].include?(e[0..0]) unless ['.htaccess'].include?(e)
|
||||
end
|
||||
entries = filter_entries(Dir.entries(base))
|
||||
directories = entries.select { |e| File.directory?(File.join(base, e)) }
|
||||
files = entries.reject { |e| File.directory?(File.join(base, e)) }
|
||||
|
||||
|
@ -165,6 +155,19 @@ module Jekyll
|
|||
"topics" => post_attr_hash('topics')
|
||||
}}
|
||||
end
|
||||
end
|
||||
|
||||
# Filter out any files/directories that are hidden or backup files (start
|
||||
# with "." or "#" or end with "~") or contain site content (start with "_")
|
||||
# unless they are "_posts" directories or web server files such as
|
||||
# '.htaccess'
|
||||
def filter_entries(entries)
|
||||
entries = entries.reject do |e|
|
||||
unless ['_posts', '.htaccess'].include?(e)
|
||||
# Reject backup/hidden
|
||||
['.', '_', '#'].include?(e[0..0]) or e[-1..-1] == '~'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
layout: default
|
||||
title: Array categories in YAML
|
||||
categories:
|
||||
- foo
|
||||
- bar
|
||||
- baz
|
||||
---
|
||||
|
||||
Best *post* ever
|
|
@ -87,10 +87,16 @@ class TestPost < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_yaml_categories
|
||||
p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2009-01-27-categories.textile")
|
||||
assert p.categories.include?('foo')
|
||||
assert p.categories.include?('bar')
|
||||
assert p.categories.include?('baz')
|
||||
p1 = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '',
|
||||
"2009-01-27-categories.textile")
|
||||
p2 = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '',
|
||||
"2009-01-27-array-categories.textile")
|
||||
|
||||
[p1, p2].each do |p|
|
||||
assert p.categories.include?('foo')
|
||||
assert p.categories.include?('bar')
|
||||
assert p.categories.include?('baz')
|
||||
end
|
||||
end
|
||||
|
||||
def test_render
|
||||
|
|
|
@ -33,4 +33,13 @@ class TestSite < Test::Unit::TestCase
|
|||
assert_equal categories, @s.categories.keys.sort
|
||||
assert_equal 3, @s.categories['foo'].size
|
||||
end
|
||||
|
||||
def test_filter_entries
|
||||
ent1 = %w[foo.markdown bar.markdown baz.markdown #baz.markdown#
|
||||
.baz.markdow foo.markdown~]
|
||||
ent2 = %w[.htaccess _posts bla.bla]
|
||||
|
||||
assert_equal %w[foo.markdown bar.markdown baz.markdown], @s.filter_entries(ent1)
|
||||
assert_equal ent2, @s.filter_entries(ent2)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue