sanitize urls and ignore symlinks
This commit is contained in:
parent
be8b7715d3
commit
13cc44fb12
|
@ -55,9 +55,12 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns <String>
|
# Returns <String>
|
||||||
def url
|
def url
|
||||||
return permalink if permalink
|
return @url if @url
|
||||||
|
|
||||||
@url ||= {
|
url = if permalink
|
||||||
|
permalink
|
||||||
|
else
|
||||||
|
{
|
||||||
"basename" => self.basename,
|
"basename" => self.basename,
|
||||||
"output_ext" => self.output_ext,
|
"output_ext" => self.output_ext,
|
||||||
}.inject(template) { |result, token|
|
}.inject(template) { |result, token|
|
||||||
|
@ -65,6 +68,12 @@ module Jekyll
|
||||||
}.gsub(/\/\//, "/")
|
}.gsub(/\/\//, "/")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# sanitize url
|
||||||
|
@url = url.split('/').reject{ |part| part =~ /^\.+$/ }.join('/')
|
||||||
|
@url += "/" if url =~ /\/$/
|
||||||
|
@url
|
||||||
|
end
|
||||||
|
|
||||||
# Extract information from the page filename
|
# Extract information from the page filename
|
||||||
# +name+ is the String filename of the page file
|
# +name+ is the String filename of the page file
|
||||||
#
|
#
|
||||||
|
|
|
@ -117,9 +117,12 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns <String>
|
# Returns <String>
|
||||||
def url
|
def url
|
||||||
return permalink if permalink
|
return @url if @url
|
||||||
|
|
||||||
@url ||= {
|
url = if permalink
|
||||||
|
permalink
|
||||||
|
else
|
||||||
|
{
|
||||||
"year" => date.strftime("%Y"),
|
"year" => date.strftime("%Y"),
|
||||||
"month" => date.strftime("%m"),
|
"month" => date.strftime("%m"),
|
||||||
"day" => date.strftime("%d"),
|
"day" => date.strftime("%d"),
|
||||||
|
@ -133,6 +136,12 @@ module Jekyll
|
||||||
}.gsub(/\/\//, "/")
|
}.gsub(/\/\//, "/")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# sanitize url
|
||||||
|
@url = url.split('/').reject{ |part| part =~ /^\.+$/ }.join('/')
|
||||||
|
@url += "/" if url =~ /\/$/
|
||||||
|
@url
|
||||||
|
end
|
||||||
|
|
||||||
# The UID for this post (useful in feeds)
|
# The UID for this post (useful in feeds)
|
||||||
# e.g. /2008/11/05/my-awesome-post
|
# e.g. /2008/11/05/my-awesome-post
|
||||||
#
|
#
|
||||||
|
|
|
@ -210,7 +210,7 @@ module Jekyll
|
||||||
# Returns nothing
|
# Returns nothing
|
||||||
def read_directories(dir = '')
|
def read_directories(dir = '')
|
||||||
base = File.join(self.source, dir)
|
base = File.join(self.source, dir)
|
||||||
entries = filter_entries(Dir.entries(base))
|
entries = Dir.chdir(base){ filter_entries(Dir['*']) }
|
||||||
|
|
||||||
self.read_posts(dir)
|
self.read_posts(dir)
|
||||||
|
|
||||||
|
@ -268,7 +268,10 @@ module Jekyll
|
||||||
def filter_entries(entries)
|
def filter_entries(entries)
|
||||||
entries = entries.reject do |e|
|
entries = entries.reject do |e|
|
||||||
unless ['.htaccess'].include?(e)
|
unless ['.htaccess'].include?(e)
|
||||||
['.', '_', '#'].include?(e[0..0]) || e[-1..-1] == '~' || self.exclude.include?(e)
|
['.', '_', '#'].include?(e[0..0]) ||
|
||||||
|
e[-1..-1] == '~' ||
|
||||||
|
self.exclude.include?(e) ||
|
||||||
|
File.symlink?(e)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue