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