There was an error while loading. Please reload this page.
1 parent 9e93772 commit 558533bCopy full SHA for 558533b
1 file changed
lib/search_generator.rb
@@ -7,7 +7,7 @@ class SearchFilter < Nanoc::Filter
7
8
$search_file_path = File.join(Dir.pwd, "static", "search-index.json")
9
$search_file_contents = { :pages => [] }
10
-
+
11
sidebar = File.open(File.join(Dir.pwd, "layouts", "sidebar.html"))
12
$sidebar_doc = Nokogiri::HTML(sidebar)
13
sidebar.close
@@ -31,7 +31,7 @@ def run(content, params={})
31
32
def write_search_file
33
begin
34
- File.open($search_file_path, 'w') {|f| f.write(JSON.pretty_generate($search_file_contents)) }
+ File.open($search_file_path, 'w') {|f| f.write(JSON.pretty_generate($search_file_contents) << "\n") } # and final newline)
35
rescue
36
puts 'WARNING: cannot write search file.'
37
end
@@ -47,12 +47,12 @@ def merge_sort(a)
47
l, r = split_array(a)
48
result = combine(merge_sort(l), merge_sort(r))
49
50
51
def split_array(a)
52
mid = (a.size / 2).round
53
[a.take(mid), a.drop(mid)]
54
55
56
def combine(a, b)
57
return b.empty? ? a : b if a.empty? || b.empty?
58
smallest = a.first[:url] <= b.first[:url] ? a.shift : b.shift
0 commit comments