Class: Jekyll::LiveSite
- Inherits:
-
Site
- Object
- Site
- Jekyll::LiveSite
show all
- Defined in:
- lib/jekyll/live_site.rb
Defined Under Namespace
Classes: ContentFile, InvalidPost
Constant Summary
collapse
- FILTER_PREFIXES =
%w[ . _ # ]
- FILTER_SUFFIXES =
%w[ ~ ]
Instance Attribute Summary
Attributes inherited from Site
#categories, #config, #converters, #dest, #exclude, #future, #generators, #include, #layouts, #limit_posts, #lsi, #pages, #permalink_style, #plugins, #posts, #pygments, #safe, #source, #static_files, #tags, #time
Instance Method Summary
collapse
Methods inherited from Site
#cleanup, #generate, #getConverterImpl, #initialize, #post_attr_hash, #process, #read, #read_directories, #read_layouts, #read_posts, #render, #reset, #setup, #site_payload, #write
Constructor Details
This class inherits a constructor from Jekyll::Site
Instance Method Details
#allow_file?(entry) ⇒ Boolean
197
198
199
200
|
# File 'lib/jekyll/live_site.rb', line 197
def allow_file? entry
whitelisted_file? entry or
(allow_file_name? entry and !blacklisted_file? entry)
end
|
#allow_file_name?(entry) ⇒ Boolean
202
203
204
205
|
# File 'lib/jekyll/live_site.rb', line 202
def allow_file_name? entry
!(FILTER_PREFIXES.include? entry[0,1] or
FILTER_SUFFIXES.include? entry[-1,1])
end
|
#blacklisted_file?(entry) ⇒ Boolean
211
212
213
|
# File 'lib/jekyll/live_site.rb', line 211
def blacklisted_file? entry
self.exclude.include? entry
end
|
#create_post(dir, name) ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/jekyll/live_site.rb', line 143
def create_post dir, name
path = File.join dir, name
dir, name = path.split('/_posts/', 2)
if Post.valid? name
post = Post.new(self, self.source, dir, name)
if publish_post? post
self.posts << post
post.categories.each { |c| self.categories[c] << post }
post.tags.each { |c| self.tags[c] << post }
post
else
raise InvalidPost, "post not publishable: #{post.inspect}"
end
else
raise InvalidPost, "not a valid post: #{name.inspect}"
end
end
|
#filter_entries(entries) ⇒ Object
Filter out any files/directories that are hidden or backup files (start with “.”, “_”, or “#”, or end with “~”), or are excluded by the site configuration, unless they are whitelisted by the site configuration.
To be able to check symlinks, this method expects to be run from the directory where entries originate.
entries - The Array of file/directory entries to filter.
Returns the Array of filtered entries.
191
192
193
194
195
|
# File 'lib/jekyll/live_site.rb', line 191
def filter_entries(entries)
entries.select { |entry|
allow_file? entry and !File.symlink? entry
}
end
|
174
175
176
|
# File 'lib/jekyll/live_site.rb', line 174
def file
'---' == File.open(file) { |fd| fd.read(3) }
end
|
#process_files(files) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/jekyll/live_site.rb', line 7
def process_files files
pages = []
Array(files).each do |filename|
resolve_file(filename) { |page| pages << page }
end
return false if pages.empty?
payload = nil
for page in pages
if page.respond_to? :render
payload ||= self.site_payload
page.read_yaml('', page.filename)
page.render(self.layouts, payload)
end
if page.write(self.dest)
yield page.destination(self.dest)
end
end
end
|
#publish_post?(post) ⇒ Boolean
164
165
166
|
# File 'lib/jekyll/live_site.rb', line 164
def publish_post? post
post.published && (self.future || post.date <= self.time)
end
|
#resolve_file(filename) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/jekyll/live_site.rb', line 31
def resolve_file filename
path = File.expand_path filename, self.source
file = ContentFile.new path, self.source, self.dest, self.method(:allow_file?)
unless file.valid?
warn "invalid file: #{file.path}"
return
end
case file.type
when :post
page = self.posts.find { |p| p.filename == file.path }
page ||= create_post(file.relative_dir, file.name)
yield page
when :layout
if pair = self.layouts.find { |_, p| p.filename == file.path }
layout_name = pair[0]
else
layout_name = file.name.sub(/\.[^.]+$/, '')
self.layouts[layout_name] = Layout.new(self, file.dir, file.name)
end
[self.posts, self.pages].each do |group|
group.each { |p| yield p if using_layout?(layout_name, p) }
end
when :file
page = nil
[self.pages, self.static_files].each do |group|
if page = group.find { |p| p.filename == file.path }
break
end
end
page ||= if file.path
new_page = Page.new(self, self.source, file.dir, file.name)
self.pages << new_page
new_page
else
new_file = StaticFile.new(self, self.source, file.dir, file.name)
self.static_files << new_file
new_file
end
yield page
else
raise "unknown file type: #{file.type}"
end
rescue InvalidPost => e
warn e.message
end
|
#using_layout?(name, page, seen = nil) ⇒ Boolean
168
169
170
171
172
|
# File 'lib/jekyll/live_site.rb', line 168
def using_layout? name, page, seen = nil
if using = page.data['layout'] and (seen.nil? or !seen.include?(using))
using == name or using_layout?(name, self.layouts[using], (seen || []) << using)
end
end
|
#whitelisted_file?(entry) ⇒ Boolean
207
208
209
|
# File 'lib/jekyll/live_site.rb', line 207
def whitelisted_file? entry
self.include.include? entry
end
|