jekyll 4.2.0 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +350 -347
- data/LICENSE +21 -21
- data/README.markdown +86 -86
- data/exe/jekyll +57 -57
- data/lib/blank_template/_config.yml +3 -3
- data/lib/blank_template/_layouts/default.html +12 -12
- data/lib/blank_template/_sass/main.scss +9 -9
- data/lib/blank_template/assets/css/main.scss +4 -4
- data/lib/blank_template/index.md +8 -8
- data/lib/jekyll/cache.rb +190 -190
- data/lib/jekyll/cleaner.rb +111 -111
- data/lib/jekyll/collection.rb +309 -309
- data/lib/jekyll/command.rb +105 -105
- data/lib/jekyll/commands/build.rb +93 -93
- data/lib/jekyll/commands/clean.rb +45 -45
- data/lib/jekyll/commands/doctor.rb +177 -177
- data/lib/jekyll/commands/help.rb +34 -34
- data/lib/jekyll/commands/new.rb +169 -169
- data/lib/jekyll/commands/new_theme.rb +40 -40
- data/lib/jekyll/commands/serve/live_reload_reactor.rb +122 -122
- data/lib/jekyll/commands/serve/livereload_assets/livereload.js +1183 -1183
- data/lib/jekyll/commands/serve/servlet.rb +202 -202
- data/lib/jekyll/commands/serve/websockets.rb +81 -81
- data/lib/jekyll/commands/serve.rb +362 -365
- data/lib/jekyll/configuration.rb +313 -313
- data/lib/jekyll/converter.rb +54 -54
- data/lib/jekyll/converters/identity.rb +41 -41
- data/lib/jekyll/converters/markdown/kramdown_parser.rb +199 -199
- data/lib/jekyll/converters/markdown.rb +113 -113
- data/lib/jekyll/converters/smartypants.rb +70 -70
- data/lib/jekyll/convertible.rb +257 -260
- data/lib/jekyll/deprecator.rb +50 -50
- data/lib/jekyll/document.rb +544 -544
- data/lib/jekyll/drops/collection_drop.rb +20 -20
- data/lib/jekyll/drops/document_drop.rb +70 -70
- data/lib/jekyll/drops/drop.rb +293 -293
- data/lib/jekyll/drops/excerpt_drop.rb +19 -19
- data/lib/jekyll/drops/jekyll_drop.rb +32 -32
- data/lib/jekyll/drops/site_drop.rb +66 -66
- data/lib/jekyll/drops/static_file_drop.rb +14 -14
- data/lib/jekyll/drops/unified_payload_drop.rb +26 -26
- data/lib/jekyll/drops/url_drop.rb +140 -140
- data/lib/jekyll/entry_filter.rb +121 -121
- data/lib/jekyll/errors.rb +20 -20
- data/lib/jekyll/excerpt.rb +201 -201
- data/lib/jekyll/external.rb +79 -79
- data/lib/jekyll/filters/date_filters.rb +110 -110
- data/lib/jekyll/filters/grouping_filters.rb +64 -64
- data/lib/jekyll/filters/url_filters.rb +98 -98
- data/lib/jekyll/filters.rb +535 -535
- data/lib/jekyll/frontmatter_defaults.rb +240 -240
- data/lib/jekyll/generator.rb +5 -5
- data/lib/jekyll/hooks.rb +107 -107
- data/lib/jekyll/inclusion.rb +32 -32
- data/lib/jekyll/layout.rb +67 -67
- data/lib/jekyll/liquid_extensions.rb +22 -22
- data/lib/jekyll/liquid_renderer/file.rb +77 -77
- data/lib/jekyll/liquid_renderer/table.rb +55 -55
- data/lib/jekyll/liquid_renderer.rb +80 -80
- data/lib/jekyll/log_adapter.rb +151 -151
- data/lib/jekyll/mime.types +866 -866
- data/lib/jekyll/page.rb +217 -217
- data/lib/jekyll/page_excerpt.rb +25 -25
- data/lib/jekyll/page_without_a_file.rb +14 -14
- data/lib/jekyll/path_manager.rb +74 -74
- data/lib/jekyll/plugin.rb +92 -92
- data/lib/jekyll/plugin_manager.rb +115 -115
- data/lib/jekyll/profiler.rb +58 -58
- data/lib/jekyll/publisher.rb +23 -23
- data/lib/jekyll/reader.rb +192 -192
- data/lib/jekyll/readers/collection_reader.rb +23 -23
- data/lib/jekyll/readers/data_reader.rb +79 -79
- data/lib/jekyll/readers/layout_reader.rb +62 -62
- data/lib/jekyll/readers/page_reader.rb +25 -25
- data/lib/jekyll/readers/post_reader.rb +85 -85
- data/lib/jekyll/readers/static_file_reader.rb +25 -25
- data/lib/jekyll/readers/theme_assets_reader.rb +52 -52
- data/lib/jekyll/regenerator.rb +195 -195
- data/lib/jekyll/related_posts.rb +52 -52
- data/lib/jekyll/renderer.rb +265 -265
- data/lib/jekyll/site.rb +551 -551
- data/lib/jekyll/static_file.rb +208 -208
- data/lib/jekyll/stevenson.rb +60 -60
- data/lib/jekyll/tags/highlight.rb +110 -110
- data/lib/jekyll/tags/include.rb +275 -270
- data/lib/jekyll/tags/link.rb +42 -42
- data/lib/jekyll/tags/post_url.rb +106 -106
- data/lib/jekyll/theme.rb +86 -86
- data/lib/jekyll/theme_builder.rb +121 -121
- data/lib/jekyll/url.rb +167 -167
- data/lib/jekyll/utils/ansi.rb +57 -57
- data/lib/jekyll/utils/exec.rb +26 -26
- data/lib/jekyll/utils/internet.rb +37 -37
- data/lib/jekyll/utils/platforms.rb +67 -67
- data/lib/jekyll/utils/thread_event.rb +31 -31
- data/lib/jekyll/utils/win_tz.rb +75 -75
- data/lib/jekyll/utils.rb +367 -367
- data/lib/jekyll/version.rb +5 -5
- data/lib/jekyll.rb +195 -195
- data/lib/site_template/.gitignore +5 -5
- data/lib/site_template/404.html +25 -25
- data/lib/site_template/_config.yml +55 -55
- data/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb +29 -29
- data/lib/site_template/about.markdown +18 -18
- data/lib/site_template/index.markdown +6 -6
- data/lib/theme_template/CODE_OF_CONDUCT.md.erb +74 -74
- data/lib/theme_template/Gemfile +4 -4
- data/lib/theme_template/LICENSE.txt.erb +21 -21
- data/lib/theme_template/README.md.erb +52 -52
- data/lib/theme_template/_layouts/default.html +1 -1
- data/lib/theme_template/_layouts/page.html +5 -5
- data/lib/theme_template/_layouts/post.html +5 -5
- data/lib/theme_template/example/_config.yml.erb +1 -1
- data/lib/theme_template/example/_post.md +12 -12
- data/lib/theme_template/example/index.html +14 -14
- data/lib/theme_template/example/style.scss +7 -7
- data/lib/theme_template/gitignore.erb +6 -6
- data/lib/theme_template/theme.gemspec.erb +16 -16
- data/rubocop/jekyll/assert_equal_literal_actual.rb +149 -149
- data/rubocop/jekyll/no_p_allowed.rb +23 -23
- data/rubocop/jekyll/no_puts_allowed.rb +23 -23
- data/rubocop/jekyll.rb +5 -5
- metadata +3 -3
data/lib/jekyll/regenerator.rb
CHANGED
@@ -1,195 +1,195 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
class Regenerator
|
5
|
-
attr_reader :site, :metadata, :cache
|
6
|
-
attr_accessor :disabled
|
7
|
-
private :disabled, :disabled=
|
8
|
-
|
9
|
-
def initialize(site)
|
10
|
-
@site = site
|
11
|
-
|
12
|
-
# Read metadata from file
|
13
|
-
read_metadata
|
14
|
-
|
15
|
-
# Initialize cache to an empty hash
|
16
|
-
clear_cache
|
17
|
-
end
|
18
|
-
|
19
|
-
# Checks if a renderable object needs to be regenerated
|
20
|
-
#
|
21
|
-
# Returns a boolean.
|
22
|
-
def regenerate?(document)
|
23
|
-
return true if disabled
|
24
|
-
|
25
|
-
case document
|
26
|
-
when Page
|
27
|
-
regenerate_page?(document)
|
28
|
-
when Document
|
29
|
-
regenerate_document?(document)
|
30
|
-
else
|
31
|
-
source_path = document.respond_to?(:path) ? document.path : nil
|
32
|
-
dest_path = document.destination(@site.dest) if document.respond_to?(:destination)
|
33
|
-
source_modified_or_dest_missing?(source_path, dest_path)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Add a path to the metadata
|
38
|
-
#
|
39
|
-
# Returns true, also on failure.
|
40
|
-
def add(path)
|
41
|
-
return true unless File.exist?(path)
|
42
|
-
|
43
|
-
metadata[path] = {
|
44
|
-
"mtime" => File.mtime(path),
|
45
|
-
"deps" => [],
|
46
|
-
}
|
47
|
-
cache[path] = true
|
48
|
-
end
|
49
|
-
|
50
|
-
# Force a path to regenerate
|
51
|
-
#
|
52
|
-
# Returns true.
|
53
|
-
def force(path)
|
54
|
-
cache[path] = true
|
55
|
-
end
|
56
|
-
|
57
|
-
# Clear the metadata and cache
|
58
|
-
#
|
59
|
-
# Returns nothing
|
60
|
-
def clear
|
61
|
-
@metadata = {}
|
62
|
-
clear_cache
|
63
|
-
end
|
64
|
-
|
65
|
-
# Clear just the cache
|
66
|
-
#
|
67
|
-
# Returns nothing
|
68
|
-
def clear_cache
|
69
|
-
@cache = {}
|
70
|
-
end
|
71
|
-
|
72
|
-
# Checks if the source has been modified or the
|
73
|
-
# destination is missing
|
74
|
-
#
|
75
|
-
# returns a boolean
|
76
|
-
def source_modified_or_dest_missing?(source_path, dest_path)
|
77
|
-
modified?(source_path) || (dest_path && !File.exist?(dest_path))
|
78
|
-
end
|
79
|
-
|
80
|
-
# Checks if a path's (or one of its dependencies)
|
81
|
-
# mtime has changed
|
82
|
-
#
|
83
|
-
# Returns a boolean.
|
84
|
-
def modified?(path)
|
85
|
-
return true if disabled?
|
86
|
-
|
87
|
-
# objects that don't have a path are always regenerated
|
88
|
-
return true if path.nil?
|
89
|
-
|
90
|
-
# Check for path in cache
|
91
|
-
return cache[path] if cache.key? path
|
92
|
-
|
93
|
-
if metadata[path]
|
94
|
-
# If we have seen this file before,
|
95
|
-
# check if it or one of its dependencies has been modified
|
96
|
-
existing_file_modified?(path)
|
97
|
-
else
|
98
|
-
# If we have not seen this file before, add it to the metadata and regenerate it
|
99
|
-
add(path)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# Add a dependency of a path
|
104
|
-
#
|
105
|
-
# Returns nothing.
|
106
|
-
def add_dependency(path, dependency)
|
107
|
-
return if metadata[path].nil? || disabled
|
108
|
-
|
109
|
-
unless metadata[path]["deps"].include? dependency
|
110
|
-
metadata[path]["deps"] << dependency
|
111
|
-
add(dependency) unless metadata.include?(dependency)
|
112
|
-
end
|
113
|
-
regenerate? dependency
|
114
|
-
end
|
115
|
-
|
116
|
-
# Write the metadata to disk
|
117
|
-
#
|
118
|
-
# Returns nothing.
|
119
|
-
def write_metadata
|
120
|
-
unless disabled?
|
121
|
-
Jekyll.logger.debug "Writing Metadata:", ".jekyll-metadata"
|
122
|
-
File.binwrite(metadata_file, Marshal.dump(metadata))
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
# Produce the absolute path of the metadata file
|
127
|
-
#
|
128
|
-
# Returns the String path of the file.
|
129
|
-
def metadata_file
|
130
|
-
@metadata_file ||= site.in_source_dir(".jekyll-metadata")
|
131
|
-
end
|
132
|
-
|
133
|
-
# Check if metadata has been disabled
|
134
|
-
#
|
135
|
-
# Returns a Boolean (true for disabled, false for enabled).
|
136
|
-
def disabled?
|
137
|
-
self.disabled = !site.incremental? if disabled.nil?
|
138
|
-
disabled
|
139
|
-
end
|
140
|
-
|
141
|
-
private
|
142
|
-
|
143
|
-
# Read metadata from the metadata file, if no file is found,
|
144
|
-
# initialize with an empty hash
|
145
|
-
#
|
146
|
-
# Returns the read metadata.
|
147
|
-
def read_metadata
|
148
|
-
@metadata =
|
149
|
-
if !disabled? && File.file?(metadata_file)
|
150
|
-
content = File.binread(metadata_file)
|
151
|
-
|
152
|
-
begin
|
153
|
-
Marshal.load(content)
|
154
|
-
rescue TypeError
|
155
|
-
SafeYAML.load(content)
|
156
|
-
rescue ArgumentError => e
|
157
|
-
Jekyll.logger.warn("Failed to load #{metadata_file}: #{e}")
|
158
|
-
{}
|
159
|
-
end
|
160
|
-
else
|
161
|
-
{}
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
def regenerate_page?(document)
|
166
|
-
document.asset_file? || document.data["regenerate"] ||
|
167
|
-
source_modified_or_dest_missing?(
|
168
|
-
site.in_source_dir(document.relative_path), document.destination(@site.dest)
|
169
|
-
)
|
170
|
-
end
|
171
|
-
|
172
|
-
def regenerate_document?(document)
|
173
|
-
!document.write? || document.data["regenerate"] ||
|
174
|
-
source_modified_or_dest_missing?(
|
175
|
-
document.path, document.destination(@site.dest)
|
176
|
-
)
|
177
|
-
end
|
178
|
-
|
179
|
-
def existing_file_modified?(path)
|
180
|
-
# If one of this file dependencies have been modified,
|
181
|
-
# set the regeneration bit for both the dependency and the file to true
|
182
|
-
metadata[path]["deps"].each do |dependency|
|
183
|
-
return cache[dependency] = cache[path] = true if modified?(dependency)
|
184
|
-
end
|
185
|
-
|
186
|
-
if File.exist?(path) && metadata[path]["mtime"].eql?(File.mtime(path))
|
187
|
-
# If this file has not been modified, set the regeneration bit to false
|
188
|
-
cache[path] = false
|
189
|
-
else
|
190
|
-
# If it has been modified, set it to true
|
191
|
-
add(path)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Regenerator
|
5
|
+
attr_reader :site, :metadata, :cache
|
6
|
+
attr_accessor :disabled
|
7
|
+
private :disabled, :disabled=
|
8
|
+
|
9
|
+
def initialize(site)
|
10
|
+
@site = site
|
11
|
+
|
12
|
+
# Read metadata from file
|
13
|
+
read_metadata
|
14
|
+
|
15
|
+
# Initialize cache to an empty hash
|
16
|
+
clear_cache
|
17
|
+
end
|
18
|
+
|
19
|
+
# Checks if a renderable object needs to be regenerated
|
20
|
+
#
|
21
|
+
# Returns a boolean.
|
22
|
+
def regenerate?(document)
|
23
|
+
return true if disabled
|
24
|
+
|
25
|
+
case document
|
26
|
+
when Page
|
27
|
+
regenerate_page?(document)
|
28
|
+
when Document
|
29
|
+
regenerate_document?(document)
|
30
|
+
else
|
31
|
+
source_path = document.respond_to?(:path) ? document.path : nil
|
32
|
+
dest_path = document.destination(@site.dest) if document.respond_to?(:destination)
|
33
|
+
source_modified_or_dest_missing?(source_path, dest_path)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Add a path to the metadata
|
38
|
+
#
|
39
|
+
# Returns true, also on failure.
|
40
|
+
def add(path)
|
41
|
+
return true unless File.exist?(path)
|
42
|
+
|
43
|
+
metadata[path] = {
|
44
|
+
"mtime" => File.mtime(path),
|
45
|
+
"deps" => [],
|
46
|
+
}
|
47
|
+
cache[path] = true
|
48
|
+
end
|
49
|
+
|
50
|
+
# Force a path to regenerate
|
51
|
+
#
|
52
|
+
# Returns true.
|
53
|
+
def force(path)
|
54
|
+
cache[path] = true
|
55
|
+
end
|
56
|
+
|
57
|
+
# Clear the metadata and cache
|
58
|
+
#
|
59
|
+
# Returns nothing
|
60
|
+
def clear
|
61
|
+
@metadata = {}
|
62
|
+
clear_cache
|
63
|
+
end
|
64
|
+
|
65
|
+
# Clear just the cache
|
66
|
+
#
|
67
|
+
# Returns nothing
|
68
|
+
def clear_cache
|
69
|
+
@cache = {}
|
70
|
+
end
|
71
|
+
|
72
|
+
# Checks if the source has been modified or the
|
73
|
+
# destination is missing
|
74
|
+
#
|
75
|
+
# returns a boolean
|
76
|
+
def source_modified_or_dest_missing?(source_path, dest_path)
|
77
|
+
modified?(source_path) || (dest_path && !File.exist?(dest_path))
|
78
|
+
end
|
79
|
+
|
80
|
+
# Checks if a path's (or one of its dependencies)
|
81
|
+
# mtime has changed
|
82
|
+
#
|
83
|
+
# Returns a boolean.
|
84
|
+
def modified?(path)
|
85
|
+
return true if disabled?
|
86
|
+
|
87
|
+
# objects that don't have a path are always regenerated
|
88
|
+
return true if path.nil?
|
89
|
+
|
90
|
+
# Check for path in cache
|
91
|
+
return cache[path] if cache.key? path
|
92
|
+
|
93
|
+
if metadata[path]
|
94
|
+
# If we have seen this file before,
|
95
|
+
# check if it or one of its dependencies has been modified
|
96
|
+
existing_file_modified?(path)
|
97
|
+
else
|
98
|
+
# If we have not seen this file before, add it to the metadata and regenerate it
|
99
|
+
add(path)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Add a dependency of a path
|
104
|
+
#
|
105
|
+
# Returns nothing.
|
106
|
+
def add_dependency(path, dependency)
|
107
|
+
return if metadata[path].nil? || disabled
|
108
|
+
|
109
|
+
unless metadata[path]["deps"].include? dependency
|
110
|
+
metadata[path]["deps"] << dependency
|
111
|
+
add(dependency) unless metadata.include?(dependency)
|
112
|
+
end
|
113
|
+
regenerate? dependency
|
114
|
+
end
|
115
|
+
|
116
|
+
# Write the metadata to disk
|
117
|
+
#
|
118
|
+
# Returns nothing.
|
119
|
+
def write_metadata
|
120
|
+
unless disabled?
|
121
|
+
Jekyll.logger.debug "Writing Metadata:", ".jekyll-metadata"
|
122
|
+
File.binwrite(metadata_file, Marshal.dump(metadata))
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Produce the absolute path of the metadata file
|
127
|
+
#
|
128
|
+
# Returns the String path of the file.
|
129
|
+
def metadata_file
|
130
|
+
@metadata_file ||= site.in_source_dir(".jekyll-metadata")
|
131
|
+
end
|
132
|
+
|
133
|
+
# Check if metadata has been disabled
|
134
|
+
#
|
135
|
+
# Returns a Boolean (true for disabled, false for enabled).
|
136
|
+
def disabled?
|
137
|
+
self.disabled = !site.incremental? if disabled.nil?
|
138
|
+
disabled
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
# Read metadata from the metadata file, if no file is found,
|
144
|
+
# initialize with an empty hash
|
145
|
+
#
|
146
|
+
# Returns the read metadata.
|
147
|
+
def read_metadata
|
148
|
+
@metadata =
|
149
|
+
if !disabled? && File.file?(metadata_file)
|
150
|
+
content = File.binread(metadata_file)
|
151
|
+
|
152
|
+
begin
|
153
|
+
Marshal.load(content)
|
154
|
+
rescue TypeError
|
155
|
+
SafeYAML.load(content)
|
156
|
+
rescue ArgumentError => e
|
157
|
+
Jekyll.logger.warn("Failed to load #{metadata_file}: #{e}")
|
158
|
+
{}
|
159
|
+
end
|
160
|
+
else
|
161
|
+
{}
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def regenerate_page?(document)
|
166
|
+
document.asset_file? || document.data["regenerate"] ||
|
167
|
+
source_modified_or_dest_missing?(
|
168
|
+
site.in_source_dir(document.relative_path), document.destination(@site.dest)
|
169
|
+
)
|
170
|
+
end
|
171
|
+
|
172
|
+
def regenerate_document?(document)
|
173
|
+
!document.write? || document.data["regenerate"] ||
|
174
|
+
source_modified_or_dest_missing?(
|
175
|
+
document.path, document.destination(@site.dest)
|
176
|
+
)
|
177
|
+
end
|
178
|
+
|
179
|
+
def existing_file_modified?(path)
|
180
|
+
# If one of this file dependencies have been modified,
|
181
|
+
# set the regeneration bit for both the dependency and the file to true
|
182
|
+
metadata[path]["deps"].each do |dependency|
|
183
|
+
return cache[dependency] = cache[path] = true if modified?(dependency)
|
184
|
+
end
|
185
|
+
|
186
|
+
if File.exist?(path) && metadata[path]["mtime"].eql?(File.mtime(path))
|
187
|
+
# If this file has not been modified, set the regeneration bit to false
|
188
|
+
cache[path] = false
|
189
|
+
else
|
190
|
+
# If it has been modified, set it to true
|
191
|
+
add(path)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
data/lib/jekyll/related_posts.rb
CHANGED
@@ -1,52 +1,52 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
class RelatedPosts
|
5
|
-
class << self
|
6
|
-
attr_accessor :lsi
|
7
|
-
end
|
8
|
-
|
9
|
-
attr_reader :post, :site
|
10
|
-
|
11
|
-
def initialize(post)
|
12
|
-
@post = post
|
13
|
-
@site = post.site
|
14
|
-
Jekyll::External.require_with_graceful_fail("classifier-reborn") if site.lsi
|
15
|
-
end
|
16
|
-
|
17
|
-
def build
|
18
|
-
return [] unless site.posts.docs.size > 1
|
19
|
-
|
20
|
-
if site.lsi
|
21
|
-
build_index
|
22
|
-
lsi_related_posts
|
23
|
-
else
|
24
|
-
most_recent_posts
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def build_index
|
29
|
-
self.class.lsi ||= begin
|
30
|
-
lsi = ClassifierReborn::LSI.new(:auto_rebuild => false)
|
31
|
-
Jekyll.logger.info("Populating LSI...")
|
32
|
-
|
33
|
-
site.posts.docs.each do |x|
|
34
|
-
lsi.add_item(x)
|
35
|
-
end
|
36
|
-
|
37
|
-
Jekyll.logger.info("Rebuilding index...")
|
38
|
-
lsi.build_index
|
39
|
-
Jekyll.logger.info("")
|
40
|
-
lsi
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def lsi_related_posts
|
45
|
-
self.class.lsi.find_related(post, 11)
|
46
|
-
end
|
47
|
-
|
48
|
-
def most_recent_posts
|
49
|
-
@most_recent_posts ||= (site.posts.docs.last(11).reverse! - [post]).first(10)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class RelatedPosts
|
5
|
+
class << self
|
6
|
+
attr_accessor :lsi
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :post, :site
|
10
|
+
|
11
|
+
def initialize(post)
|
12
|
+
@post = post
|
13
|
+
@site = post.site
|
14
|
+
Jekyll::External.require_with_graceful_fail("classifier-reborn") if site.lsi
|
15
|
+
end
|
16
|
+
|
17
|
+
def build
|
18
|
+
return [] unless site.posts.docs.size > 1
|
19
|
+
|
20
|
+
if site.lsi
|
21
|
+
build_index
|
22
|
+
lsi_related_posts
|
23
|
+
else
|
24
|
+
most_recent_posts
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def build_index
|
29
|
+
self.class.lsi ||= begin
|
30
|
+
lsi = ClassifierReborn::LSI.new(:auto_rebuild => false)
|
31
|
+
Jekyll.logger.info("Populating LSI...")
|
32
|
+
|
33
|
+
site.posts.docs.each do |x|
|
34
|
+
lsi.add_item(x)
|
35
|
+
end
|
36
|
+
|
37
|
+
Jekyll.logger.info("Rebuilding index...")
|
38
|
+
lsi.build_index
|
39
|
+
Jekyll.logger.info("")
|
40
|
+
lsi
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def lsi_related_posts
|
45
|
+
self.class.lsi.find_related(post, 11)
|
46
|
+
end
|
47
|
+
|
48
|
+
def most_recent_posts
|
49
|
+
@most_recent_posts ||= (site.posts.docs.last(11).reverse! - [post]).first(10)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|