-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved search indexing to run after the site is generated
- Loading branch information
Showing
1 changed file
with
31 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,41 @@ | ||
require 'nokogiri' | ||
require 'open3' | ||
|
||
module Jekyll | ||
class GenerateSearchIndex < Generator | ||
priority 60 | ||
def generate(site) | ||
class GenerateSearchIndexPostWrite | ||
# Hook into Jekyll's post_write stage, which runs after all files have been written | ||
Jekyll::Hooks.register :site, :post_write do |site| | ||
process_site(site) | ||
end | ||
|
||
def self.process_site(site) | ||
# Define the path to your Node.js script | ||
script_path = File.join(site.source, '_scripts', 'generateSearchIndex.js') | ||
# Execute the Node.js script using Open3.capture3 to capture output and errors | ||
|
||
# Run the Node.js script using Open3.popen3 to stream stdout and stderr | ||
puts "Running Node.js script to generate search index: #{script_path}" | ||
stdout, stderr, status = Open3.capture3("node", script_path) | ||
|
||
if status.success? | ||
puts "Search index generated successfully" | ||
else | ||
puts "Error generating search index:\n#{stderr}" | ||
raise "Search index generation failed" | ||
|
||
Open3.popen3("node", script_path) do |stdin, stdout, stderr, wait_thr| | ||
# Stream stdout and stderr to the calling process | ||
stdout_thread = Thread.new do | ||
stdout.each { |line| puts line } | ||
end | ||
|
||
stderr_thread = Thread.new do | ||
stderr.each { |line| warn line } | ||
end | ||
|
||
# Wait for both stdout and stderr threads to finish | ||
stdout_thread.join | ||
stderr_thread.join | ||
|
||
# Check if the process was successful | ||
exit_status = wait_thr.value | ||
unless exit_status.success? | ||
raise "Search index generation failed with exit code #{exit_status.exitstatus}" | ||
end | ||
end | ||
puts "Search index generated successfully" | ||
end | ||
end | ||
end | ||
|