Module: Jekyll::Pagefind
- Defined in:
- lib/jekyll-pagefind.rb,
lib/version.rb
Overview
module Jekyll::Pagefind
Constant Summary collapse
- VERSION =
"0.3.3"- GEM_ROOT =
File.("..", __dir__)
Class Method Summary collapse
-
.build_cli_arguments(config) ⇒ Object
Converts Jekyll config options into matching Pagefind command line flags.
-
.pagefind_binary_path ⇒ Object
rubocop:disable Metrics/MethodLength,Metrics/PerceivedComplexity.
-
.run_pagefind(site_destination, extra_arguments = "") ⇒ Object
rubocop:disable Metrics/MethodLength,Metrics/AbcSize.
-
.valid_arg?(arg) ⇒ Boolean
valid the cli flag.
Class Method Details
.build_cli_arguments(config) ⇒ Object
Converts Jekyll config options into matching Pagefind command line flags
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/jekyll-pagefind.rb', line 55 def self.build_cli_arguments(config) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity plugin_config = config["jekyll_pagefind"] || {} args = [] plugin_config.each do |key, value| next unless valid_arg?(key) # Transform snake_case keys to kebab-case (e.g., keep_index_url -> keep-index-url) flag_name = key.to_s.gsub("_", "-") case value when TrueClass # Boolean flags like --keep-index-url require no attached value args << "--#{flag_name}" when FalseClass # Ignore false booleans unless Pagefind specifically supports a negative override next when Array # Arrays like exclude_selectors need to be repeated: --exclude-selectors ".footer" --exclude-selectors "nav" value.each { |val| args << "--#{flag_name} \"#{val}\"" } else # Strings or numbers like --bundle-dir "search" args << "--#{flag_name} \"#{value}\"" end end args.join(" ") end |
.pagefind_binary_path ⇒ Object
rubocop:disable Metrics/MethodLength,Metrics/PerceivedComplexity
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jekyll-pagefind.rb', line 15 def self.pagefind_binary_path # rubocop:disable Metrics/MethodLength,Metrics/PerceivedComplexity os = RbConfig::CONFIG["host_os"] cpu = RbConfig::CONFIG["host_cpu"] case os when /darwin|mac os/i # Differentiate between Apple Silicon and Intel Macs if cpu =~ /arm64|aarch64/i File.join(GEM_ROOT, "assets", "macos-arm64", "pagefind") else File.join(GEM_ROOT, "assets", "macos-x64", "pagefind") end when /linux/i # Differentiate between standard servers and ARM instances if cpu =~ /arm64|aarch64/i File.join(GEM_ROOT, "assets", "linux-arm64", "pagefind") else File.join(GEM_ROOT, "assets", "linux-x64", "pagefind") end # spellchecker:disable-next-line when /mswin|msys|mingw|cygwin|bccwin/i # Differentiate between Intel/AMD and ARM Windows machines if cpu =~ /arm64|aarch64/i File.join(GEM_ROOT, "assets", "windows-arm64", "pagefind.exe") else File.join(GEM_ROOT, "assets", "windows-x64", "pagefind.exe") end else raise "Jekyll-Pagefind Mismatch Error: Pagefind binary not provided for host environment: #{os} (#{cpu})" end end |
.run_pagefind(site_destination, extra_arguments = "") ⇒ Object
rubocop:disable Metrics/MethodLength,Metrics/AbcSize
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/jekyll-pagefind.rb', line 83 def self.run_pagefind(site_destination, extra_arguments = "") # rubocop:disable Metrics/MethodLength,Metrics/AbcSize binary = pagefind_binary_path # Force execution bits on UNIX hosts because gem unpacking can reset permissions flags # spellchecker:disable-next-line if RbConfig::CONFIG["host_os"] !~ /mswin|msys|mingw|cygwin|bccwin/i && !File.executable?(binary) File.chmod(0o755, binary) end # Combine the mandatory --site parameter with any user-defined configuration flags full_command = [ Shellwords.escape(binary), "--site", Shellwords.escape(site_destination), extra_arguments ].join(" ").strip started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) Jekyll.logger.info "Jekyll-Pagefind:", "Running Pagefind..." _stdout, stderr, status = Open3.capture3(full_command) if status.success? elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started_at Jekyll.logger.info "Jekyll-Pagefind:", format("Done in %.2fs", elapsed) else Jekyll.logger.error "Jekyll-Pagefind Error:", stderr raise "Pagefind binary exited with non-zero status code: #{status.exitstatus}" end end |
.valid_arg?(arg) ⇒ Boolean
valid the cli flag
50 51 52 |
# File 'lib/jekyll-pagefind.rb', line 50 def self.valid_arg?(arg) %w[output_subdir exclude_selectors keep_index_url quiet].include?(arg) end |