From 9290bf8049978fe4e8cbb7188ca9bb0891c03c35 Mon Sep 17 00:00:00 2001 From: David Barrett Date: Fri, 4 Oct 2024 11:17:30 -0700 Subject: [PATCH] Moved search indexing to run after the site is generated --- help/_plugins/60_GenerateSearchIndex.rb | 44 +++++++++++++++++-------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/help/_plugins/60_GenerateSearchIndex.rb b/help/_plugins/60_GenerateSearchIndex.rb index d7bef34d9e08..ac466aa9fc37 100644 --- a/help/_plugins/60_GenerateSearchIndex.rb +++ b/help/_plugins/60_GenerateSearchIndex.rb @@ -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 +