jekyll-pagefind 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da6350f1cdab2054988ffbd388592a97df71a8a193dd7c086c94f56f63073ae1
4
- data.tar.gz: 41ef3c9bbb2e05ab8b7e960ba36f52bb444295f3bf209036635987917d7dc5c9
3
+ metadata.gz: 7354120e9ae2690548d13b7f1caca98d7d9565b3326c1dca67ec417c82c0be12
4
+ data.tar.gz: cb762ce2575300b20c80cba8c99e6dd3cc2981af14101b3f8e657679b9ed5197
5
5
  SHA512:
6
- metadata.gz: 84ceb9bcaeb5feaae2f28c00be44de3a03ceaa8eb26adf0f5060a22807558a0f50f8f4b81179438b88d6971e13cdf44f4089c6e1db3e2a0e4bd2ec8a8968070d
7
- data.tar.gz: 8902b9fcb368cec056f541b07a92753e05b98862be590aaaa8ddbc649fc203bd01061919f9689f2836a14fbd5b55ca42842309c683778dddfca5377970560c6e
6
+ metadata.gz: 4110df9a227f32c095f5b569a59b103794c842f935ecb5ef717daa20cc87398ff8d1480a518601728bcc69ad9d3779e5fc3cb489fdac65d14561b50dfafcca65
7
+ data.tar.gz: 90a8d55735e526c12fed6cae896a9c1c03b19bd547a6c04c1039c216b34a851fbeed0846ad8603e7ebc270f774bca1c01732cf0669b2ff8174f1005cbf86fc57
data/README.md CHANGED
@@ -1,29 +1,25 @@
1
1
  <!-- markdownlint-disable MD033 -->
2
2
  <!-- markdownlint-disable MD041 -->
3
3
  <p align="center">
4
- <img src="https://github.com/phothinmg/jekykll-pagefind/blob/main/rubygems_logo.png" width="160" height="160" alt="mmdevs" style="border-radius:50%" />
4
+ <img src="https://susee.phothin.dev/logo/rubygems_logo.png" width="160" height="160" alt="mmdevs" style="border-radius:50%" />
5
5
  </p>
6
- <h1 align="center">Jekyll::Pagefind</h1>
6
+ <h1 align="center">jekyll-pagefind</h1>
7
7
 
8
8
  [![Gem Version](https://badge.fury.io/rb/jekyll-pagefind.svg?icon=si%3Arubygems)](https://badge.fury.io/rb/jekyll-pagefind)
9
9
 
10
10
  ## Overview
11
11
 
12
- Jekyll-Pagefind is a plugin I use for my personal and project sites. It was inspired by [Adding search to Jekyll using pagefind][pf_to_jekyll]. It fits easily into the default Jekyll GitHub Actions workflow for deploying to GitHub Pages.
12
+ Jekyll-Pagefind is a plugin that runs the Pagefind binary for a Jekyll site.
13
13
 
14
14
  ## Install
15
15
 
16
- Install the gem and add to the application's Gemfile by executing:
16
+ Install the gem and add it to your application's Gemfile by running:
17
17
 
18
18
  ```sh
19
19
  bundle add jekyll-pagefind
20
20
  ```
21
21
 
22
- ```sh
23
- bundle install
24
- ```
25
-
26
- In `Gemfile`
22
+ In your `Gemfile`:
27
23
 
28
24
  ```ruby
29
25
  group :jekyll_plugins do
@@ -32,50 +28,157 @@ group :jekyll_plugins do
32
28
  end
33
29
  ```
34
30
 
35
- If bundler is not being used to manage dependencies, install the gem by executing:
31
+ ```sh
32
+ bundle install
33
+ ```
34
+
35
+ If Bundler is not being used to manage dependencies, install the gem by running:
36
36
 
37
37
  ```sh
38
38
  gem install jekyll-pagefind
39
39
  ```
40
40
 
41
- ## How to
41
+ ## Use
42
+
43
+ ### Jekyll site configuration
42
44
 
43
- This guide is intended for Jekyll sites deployed to GitHub Pages.
45
+ **`_config.yml`**
44
46
 
45
- ### Download pagefind
47
+ ```yaml
48
+ plugins:
49
+ # other plugin
50
+ - jekyll-pagefind
51
+ # other config
52
+ # Optional Jekyll Pagefind Options
53
+ jekyll_pagefind:
54
+ output_subdir: pagefind
55
+ ```
46
56
 
47
- First, download the standalone binary (`pagefind`) from the [pagefind releases][pf_release_page] page.
57
+ ---
48
58
 
49
- Make sure to use the correct binary:
59
+ ### Jekyll Pagefind options (optional)
50
60
 
51
- 1. For local development, download the standalone binary (`pagefind`) for your host platform.
52
- 2. For deployment to GitHub Pages, the binary must be `pagefind-v{version}-x86_64-unknown-linux-musl.tar.gz`.
61
+ These options map to the settings available in [Pagefind config files](https://pagefind.app/docs/config-sources/#:~:text=overriding%20configuration%20files.-,Config%20files,-Pagefind%20will%20look).
53
62
 
54
- ### Place the binary file `pagefind`
63
+ For more details, see [Pagefind CLI configuration options](https://pagefind.app/docs/config-options/). `jekyll_pagefind` supports the following options.
55
64
 
56
- Place the `pagefind` binary in the root of your Jekyll project, which is the recommended default, or anywhere else under the project root.
65
+ #### 1. output_subdir
57
66
 
58
- ### Jekyll Config
67
+ The folder where the search bundle is written, relative to Jekyll `{{ site.dest }}`. The default is `pagefind`.
59
68
 
60
- **`_config.yml`**
69
+ **Example:**
61
70
 
62
71
  ```yaml
63
- plugins:
64
- # other plugin
65
- - jekyll-pagefind
72
+ output_subdir: pf # becomes _site/pf
66
73
  ```
67
74
 
68
- If your `pagefind` binary is not in the project root, add this configuration option:
75
+ #### 2. exclude_selectors
76
+
77
+ Pass extra element selectors that Pagefind should ignore when indexing.
78
+
79
+ **Example :**
69
80
 
70
81
  ```yaml
71
- pagefind: path_to_your/pagefind # where your `pagefind` was located
82
+ exclude_selectors:
83
+ - "#my_navigation"
84
+ - "blockquote > span"
85
+ - "[id^='prefix-']"
86
+ ```
87
+
88
+ #### 3. keep_index_url
89
+
90
+ Keeps `index.html` at the end of search result paths. The default is `false`.
91
+
92
+ By default, a file at `animals/cat/index.html` will be given the URL `/animals/cat/`. Setting this option to true will result in the URL `/animals/cat/index.html`.
93
+
94
+ #### 4. quiet
95
+
96
+ Logs only errors and warnings while indexing the site.
97
+
98
+ ---
99
+
100
+ ### Pagefind UI
101
+
102
+ #### 1. Using the Default UI
103
+
104
+ Using the Default UI is still supported, but it is no longer Pagefind's primary recommendation.
105
+
106
+ You can add the Pagefind UI to any page with the following snippet. The `/pagefind/` directory, or the directory specified by `output_subdir` in the [config](#1-output_subdir), will be created along with its files.
107
+
108
+ ```liquid
109
+ <script src="{{ '/pagefind/pagefind-ui.js' | relative_url }}"></script>
110
+ <link rel="stylesheet" href="{{ '/pagefind/pagefind-ui.css' | relative_url }}" />
111
+
112
+ <div id="search"></div>
113
+ <script>
114
+ window.addEventListener('DOMContentLoaded', (event) => {
115
+ new PagefindUI({ element: "#search", showSubResults: true });
116
+ });
117
+ </script>
118
+ ```
119
+
120
+ For dark mode:
121
+
122
+ ```css
123
+ body.dark {
124
+ --pagefind-ui-primary: #eeeeee;
125
+ --pagefind-ui-text: #eeeeee;
126
+ --pagefind-ui-background: #152028;
127
+ --pagefind-ui-border: #152028;
128
+ --pagefind-ui-tag: #152028;
129
+ }
130
+ ```
131
+
132
+ For more details, see [Using the Default UI](https://pagefind.app/docs/ui-usage/).
133
+
134
+ #### 2. Pagefind Component UI
135
+
136
+ Add the following snippet to `<head>`. The `/pagefind/` directory, or the directory specified by `output_subdir` in the [config](#1-output_subdir), will be created along with its files.
137
+
138
+ ```liquid
139
+ <script src="{{ '/pagefind/pagefind-component-ui.js' | relative_url }}" type="module"></script>
140
+ <link rel="stylesheet" href="{{ '/pagefind/pagefind-component-ui.css' | relative_url }}" />
72
141
  ```
73
142
 
74
- ## Development
143
+ For dark mode:
75
144
 
76
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
145
+ ```html
146
+ <div data-pf-theme="dark">
147
+ <pagefind-searchbox></pagefind-searchbox>
148
+ </div>
149
+ ```
150
+
151
+ ```css
152
+ @media (prefers-color-scheme: dark) {
153
+ :root {
154
+ --pf-text: #e5e5e5;
155
+ --pf-text-secondary: #a0a0a0;
156
+ --pf-text-muted: #949494;
157
+ --pf-background: #1a1a1a;
158
+ --pf-border: #333;
159
+ --pf-border-focus: #555;
160
+ --pf-skeleton: #2a2a2a;
161
+ --pf-skeleton-shine: #333;
162
+ --pf-hover: #252525;
163
+ --pf-mark: #e5e5e5;
164
+ --pf-scroll-shadow: rgba(255, 255, 255, 0.1);
165
+ --pf-outline-focus: #58a6ff;
166
+
167
+ --pf-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
168
+ --pf-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
169
+ --pf-shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
170
+
171
+ --pf-error-bg: #2a1a1a;
172
+ --pf-error-border: #5c2828;
173
+ --pf-error-text: #f87171;
174
+ --pf-error-text-secondary: #ef4444;
175
+ }
176
+ }
177
+ ```
77
178
 
78
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
179
+ For more details, see [Using the Default UI](https://pagefind.app/docs/search-ui/).
180
+
181
+ ---
79
182
 
80
183
  ## Contributing
81
184
 
@@ -87,9 +190,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
87
190
 
88
191
  ## Code of Conduct
89
192
 
90
- Everyone interacting in the Jekyll::Pagefind project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/phothinmg/jekyll-pagefind/blob/master/CODE_OF_CONDUCT.md).
91
-
92
- <!-- markdownlint-disable MD053 -->
93
-
94
- [pf_release_page]: https://github.com/Pagefind/pagefind/releases/latest
95
- [pf_to_jekyll]: https://www.bfoliver.com/2025/pagefind
193
+ Everyone interacting in the Jekyll::Pagefind project's codebase, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/phothinmg/jekyll-pagefind/blob/master/CODE_OF_CONDUCT.md).
Binary file
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/jekyll/pagefind/version"
3
+ require_relative "lib/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "jekyll-pagefind"
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "Run pagefind binary in jekyll site"
13
13
  spec.homepage = "https://rubygems.org/gems/jekyll-pagefind"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 3.2.0"
15
+ spec.required_ruby_version = ">= 3.1.0"
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = "https://github.com/phothinmg/jekykll-pagefind"
18
18
  spec.metadata["changelog_uri"] = "https://github.com/phothinmg/jekykll-pagefind/blob/main/CHANGELOG.md"
@@ -4,14 +4,14 @@ require "rbconfig"
4
4
  require "open3"
5
5
  require "jekyll"
6
6
 
7
- require_relative "jekyll/pagefind/version"
7
+ require_relative "version"
8
8
 
9
9
  module Jekyll
10
10
  # module Jekyll::Pagefind
11
11
  module Pagefind
12
12
  GEM_ROOT = File.expand_path("..", __dir__)
13
13
 
14
- def self.pagefind_binary_path # rubocop:disable Metrics/MethodLength
14
+ def self.pagefind_binary_path # rubocop:disable Metrics/MethodLength,Metrics/PerceivedComplexity
15
15
  os = RbConfig::CONFIG["host_os"]
16
16
  cpu = RbConfig::CONFIG["host_cpu"]
17
17
 
@@ -34,13 +34,52 @@ module Jekyll
34
34
  end
35
35
  # spellchecker:disable-next-line
36
36
  when /mswin|msys|mingw|cygwin|bccwin/i
37
- File.join(GEM_ROOT, "assets", "windows-x64", "pagefind.exe")
37
+ # Differentiate between Intel/AMD and ARM Windows machines
38
+ if cpu =~ /arm64|aarch64/i
39
+ File.join(GEM_ROOT, "assets", "windows-arm64", "pagefind.exe")
40
+ else
41
+ File.join(GEM_ROOT, "assets", "windows-x64", "pagefind.exe")
42
+ end
38
43
  else
39
- raise "Jekyll-PF Mismatch Error: Pagefind binary not provided for host environment: #{os} (#{cpu})"
44
+ raise "Jekyll-Pagefind Mismatch Error: Pagefind binary not provided for host environment: #{os} (#{cpu})"
40
45
  end
41
46
  end
42
47
 
43
- def self.run_pagefind(site_destination) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
48
+ # valid the cli flag
49
+ def self.valid_args(arg)
50
+ %w[output_subdir exclude_selectors keep_index_url quiet].include?(arg)
51
+ end
52
+
53
+ # Converts Jekyll config options into matching Pagefind command line flags
54
+ def self.build_cli_arguments(config) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
55
+ plugin_config = config["jekyll_pagefind"] || {}
56
+ args = []
57
+
58
+ plugin_config.each do |key, value|
59
+ next unless valid_args(key)
60
+
61
+ # Transform snake_case keys to kebab-case (e.g., keep_index_url -> keep-index-url)
62
+ flag_name = key.to_s.gsub("_", "-")
63
+
64
+ case value
65
+ when TrueClass
66
+ # Boolean flags like --keep-index-url require no attached value
67
+ args << "--#{flag_name}"
68
+ when FalseClass
69
+ # Ignore false booleans unless Pagefind specifically supports a negative override
70
+ next
71
+ when Array
72
+ # Arrays like exclude_selectors need to be repeated: --exclude-selectors ".footer" --exclude-selectors "nav"
73
+ value.each { |val| args << "--#{flag_name} \"#{val}\"" }
74
+ else
75
+ # Strings or numbers like --bundle-dir "search"
76
+ args << "--#{flag_name} \"#{value}\""
77
+ end
78
+ end
79
+ args.join(" ")
80
+ end
81
+
82
+ def self.run_pagefind(site_destination, extra_arguments = "") # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
44
83
  binary = pagefind_binary_path
45
84
 
46
85
  # Force execution bits on UNIX hosts because gem unpacking can reset permissions flags
@@ -49,15 +88,17 @@ module Jekyll
49
88
  File.chmod(0o755, binary)
50
89
  end
51
90
 
52
- # Run the indexer pointing explicitly at Jekyll's output directory
53
- Jekyll.logger.info "Jekyll-PF:", "Starting Pagefind indexing on target folder..."
54
- stdout, stderr, status = Open3.capture3("#{binary} --site \"#{site_destination}\"")
91
+ # Combine the mandatory --site parameter with any user-defined configuration flags
92
+ full_command = "#{binary} --site \"#{site_destination}\" #{extra_arguments}".strip
93
+
94
+ Jekyll.logger.info "Jekyll-Pagefind:", "Running command: #{full_command}"
95
+ stdout, stderr, status = Open3.capture3(full_command)
55
96
 
56
97
  if status.success?
57
- Jekyll.logger.info "Jekyll-PF:", "Indexing finished successfully!"
98
+ Jekyll.logger.info "Jekyll-Pagefind:", "Indexing finished successfully!"
58
99
  puts stdout
59
100
  else
60
- Jekyll.logger.error "Jekyll-PF Error:", stderr
101
+ Jekyll.logger.error "Jekyll-Pagefind Error:", stderr
61
102
  raise "Pagefind binary exited with non-zero status code: #{status.exitstatus}"
62
103
  end
63
104
  end
@@ -66,6 +107,8 @@ end
66
107
 
67
108
  # Hook ensures Jekyll is entirely done writing HTML pages to disk
68
109
  Jekyll::Hooks.register :site, :post_write do |site|
69
- # site.dest points dynamically to the configured destination folder (usually '_site')
70
- Jekyll::Pagefind.run_pagefind(site.dest)
71
- end
110
+ # 1. Parse your plugin settings out of site.config
111
+ custom_flags = Jekyll::Pagefind.build_cli_arguments(site.config)
112
+ # 2. Run Pagefind with the compiled flags
113
+ Jekyll::Pagefind.run_pagefind(site.dest, custom_flags)
114
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Pagefind
5
- VERSION = "0.2.1"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-pagefind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - phothinmg
@@ -50,10 +50,11 @@ files:
50
50
  - assets/linux-x64/pagefind
51
51
  - assets/macos-arm64/pagefind
52
52
  - assets/macos-x64/pagefind
53
+ - assets/windows-arm64/pagefind.exe
53
54
  - assets/windows-x64/pagefind.exe
54
55
  - jekyll-pagefind.gemspec
55
56
  - lib/jekyll-pagefind.rb
56
- - lib/jekyll/pagefind/version.rb
57
+ - lib/version.rb
57
58
  homepage: https://rubygems.org/gems/jekyll-pagefind
58
59
  licenses:
59
60
  - MIT
@@ -68,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
69
  requirements:
69
70
  - - ">="
70
71
  - !ruby/object:Gem::Version
71
- version: 3.2.0
72
+ version: 3.1.0
72
73
  required_rubygems_version: !ruby/object:Gem::Requirement
73
74
  requirements:
74
75
  - - ">="