Skip to content

Commit

Permalink
Moved search indexing to run after the site is generated
Browse files Browse the repository at this point in the history
  • Loading branch information
quinthar committed Oct 4, 2024
1 parent b35a978 commit 9290bf8
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions help/_plugins/60_GenerateSearchIndex.rb
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

0 comments on commit 9290bf8

Please sign in to comment.