jekyll-pagefind 0.2.0 → 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: 8e8984579d241274aedab47fb65d068c4fb963c4695d6a06a0fd4d3f4b7a2636
4
- data.tar.gz: 48d51482f1506b7286891df917d6eccc33abbe0f68e94421fe9aa06d102338af
3
+ metadata.gz: 7354120e9ae2690548d13b7f1caca98d7d9565b3326c1dca67ec417c82c0be12
4
+ data.tar.gz: cb762ce2575300b20c80cba8c99e6dd3cc2981af14101b3f8e657679b9ed5197
5
5
  SHA512:
6
- metadata.gz: 53fba7b6eb1961fd013fc625489601177b7ade0dfdb2311bc4cff248c7ef91d872c1201fd61045309b7e7da950d6182d01413b43169b56ae2ef56999763dfcad
7
- data.tar.gz: 8a3433e32d7a351198b6e0c5fc6c353845dd2d6669c20d4d98a1329c59e29ee4cc1f8cc8e6238b39b69edebdc70e46dca85f27b7223008b97ce06c0725e8c2fd
6
+ metadata.gz: 4110df9a227f32c095f5b569a59b103794c842f935ecb5ef717daa20cc87398ff8d1480a518601728bcc69ad9d3779e5fc3cb489fdac65d14561b50dfafcca65
7
+ data.tar.gz: 90a8d55735e526c12fed6cae896a9c1c03b19bd547a6c04c1039c216b34a851fbeed0846ad8603e7ebc270f774bca1c01732cf0669b2ff8174f1005cbf86fc57
data/README.md CHANGED
@@ -1,38 +1,188 @@
1
- # Jekyll::Pagefind
1
+ <!-- markdownlint-disable MD033 -->
2
+ <!-- markdownlint-disable MD041 -->
3
+ <p align="center">
4
+ <img src="https://susee.phothin.dev/logo/rubygems_logo.png" width="160" height="160" alt="mmdevs" style="border-radius:50%" />
5
+ </p>
6
+ <h1 align="center">jekyll-pagefind</h1>
2
7
 
3
- TODO: Delete this and the text below, and describe your gem
8
+ [![Gem Version](https://badge.fury.io/rb/jekyll-pagefind.svg?icon=si%3Arubygems)](https://badge.fury.io/rb/jekyll-pagefind)
4
9
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jekyll/pagefind`. To experiment with that code, run `bin/console` for an interactive prompt.
10
+ ## Overview
6
11
 
7
- ## Installation
12
+ Jekyll-Pagefind is a plugin that runs the Pagefind binary for a Jekyll site.
8
13
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
14
+ ## Install
10
15
 
11
- 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:
12
17
 
13
- ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+ ```sh
19
+ bundle add jekyll-pagefind
15
20
  ```
16
21
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
22
+ In your `Gemfile`:
18
23
 
19
- ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
24
+ ```ruby
25
+ group :jekyll_plugins do
26
+ # other jekyll plugins
27
+ gem 'jekyll-pagefind' # add pagefind plugin
28
+ end
21
29
  ```
22
30
 
23
- ## Usage
31
+ ```sh
32
+ bundle install
33
+ ```
34
+
35
+ If Bundler is not being used to manage dependencies, install the gem by running:
36
+
37
+ ```sh
38
+ gem install jekyll-pagefind
39
+ ```
40
+
41
+ ## Use
42
+
43
+ ### Jekyll site configuration
44
+
45
+ **`_config.yml`**
46
+
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
+ ```
56
+
57
+ ---
58
+
59
+ ### Jekyll Pagefind options (optional)
60
+
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).
62
+
63
+ For more details, see [Pagefind CLI configuration options](https://pagefind.app/docs/config-options/). `jekyll_pagefind` supports the following options.
64
+
65
+ #### 1. output_subdir
66
+
67
+ The folder where the search bundle is written, relative to Jekyll `{{ site.dest }}`. The default is `pagefind`.
68
+
69
+ **Example:**
70
+
71
+ ```yaml
72
+ output_subdir: pf # becomes _site/pf
73
+ ```
74
+
75
+ #### 2. exclude_selectors
76
+
77
+ Pass extra element selectors that Pagefind should ignore when indexing.
78
+
79
+ **Example :**
80
+
81
+ ```yaml
82
+ exclude_selectors:
83
+ - "#my_navigation"
84
+ - "blockquote > span"
85
+ - "[id^='prefix-']"
86
+ ```
87
+
88
+ #### 3. keep_index_url
24
89
 
25
- TODO: Write usage instructions here
90
+ Keeps `index.html` at the end of search result paths. The default is `false`.
26
91
 
27
- ## Development
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 }}" />
141
+ ```
142
+
143
+ For dark mode:
144
+
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
+ ```
28
178
 
29
- 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.
179
+ For more details, see [Using the Default UI](https://pagefind.app/docs/search-ui/).
30
180
 
31
- 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).
181
+ ---
32
182
 
33
183
  ## Contributing
34
184
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jekyll-pagefind. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/jekyll-pagefind/blob/master/CODE_OF_CONDUCT.md).
185
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/phothinmg/jekyll-pagefind>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/phothinmg/jekyll-pagefind/blob/master/CODE_OF_CONDUCT.md).
36
186
 
37
187
  ## License
38
188
 
@@ -40,4 +190,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
40
190
 
41
191
  ## Code of Conduct
42
192
 
43
- 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/[USERNAME]/jekyll-pagefind/blob/master/CODE_OF_CONDUCT.md).
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
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "jekyll-pagefind"
7
+ spec.version = Jekyll::Pagefind::VERSION
8
+ spec.authors = ["phothinmg"]
9
+ spec.email = ["phothinmg@disroot.org"]
10
+
11
+ spec.summary = "Pagefind plugin for Jekyll"
12
+ spec.description = "Run pagefind binary in jekyll site"
13
+ spec.homepage = "https://rubygems.org/gems/jekyll-pagefind"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.1.0"
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/phothinmg/jekykll-pagefind"
18
+ spec.metadata["changelog_uri"] = "https://github.com/phothinmg/jekykll-pagefind/blob/main/CHANGELOG.md"
19
+
20
+ spec.files = Dir.chdir(__dir__) do
21
+ Dir["README.md", "LICENSE.txt", "lib/**/*", "assets/**/*", "jekyll-pagefind.gemspec"]
22
+ end
23
+ spec.require_paths = ["lib"]
24
+ spec.add_dependency "jekyll", "~> 4.4"
25
+ spec.add_dependency "open3", "~> 0.2.1"
26
+ end
@@ -1,22 +1,114 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "jekyll/pagefind/version"
3
+ require "rbconfig"
4
+ require "open3"
5
+ require "jekyll"
6
+
7
+ require_relative "version"
4
8
 
5
9
  module Jekyll
10
+ # module Jekyll::Pagefind
6
11
  module Pagefind
7
- # class Jekyll::Pagefind::PagefindGenerator
8
- class PagefindGenerator < Jekyll::Generator
9
- safe true
10
- priority :low
11
-
12
- def generate(site)
13
- dest_dir = site.dest
14
- pf_location = site.config["pagefind"] || "pagefind"
15
- Jekyll::Hooks.register :site, :post_write do |_site|
16
- command = "./#{pf_location} --site #{dest_dir}"
17
- system(command)
12
+ GEM_ROOT = File.expand_path("..", __dir__)
13
+
14
+ def self.pagefind_binary_path # rubocop:disable Metrics/MethodLength,Metrics/PerceivedComplexity
15
+ os = RbConfig::CONFIG["host_os"]
16
+ cpu = RbConfig::CONFIG["host_cpu"]
17
+
18
+ case os
19
+ when /darwin|mac os/i
20
+ # Differentiate between Apple Silicon and Intel Macs
21
+ if cpu =~ /arm64|aarch64/i
22
+ File.join(GEM_ROOT, "assets", "macos-arm64",
23
+ "pagefind")
24
+ else
25
+ File.join(GEM_ROOT, "assets", "macos-x64", "pagefind")
26
+ end
27
+ when /linux/i
28
+ # Differentiate between standard servers and ARM instances
29
+ if cpu =~ /arm64|aarch64/i
30
+ File.join(GEM_ROOT, "assets", "linux-arm64",
31
+ "pagefind")
32
+ else
33
+ File.join(GEM_ROOT, "assets", "linux-x64", "pagefind")
34
+ end
35
+ # spellchecker:disable-next-line
36
+ when /mswin|msys|mingw|cygwin|bccwin/i
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
43
+ else
44
+ raise "Jekyll-Pagefind Mismatch Error: Pagefind binary not provided for host environment: #{os} (#{cpu})"
45
+ end
46
+ end
47
+
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}\""
18
77
  end
19
78
  end
79
+ args.join(" ")
80
+ end
81
+
82
+ def self.run_pagefind(site_destination, extra_arguments = "") # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
83
+ binary = pagefind_binary_path
84
+
85
+ # Force execution bits on UNIX hosts because gem unpacking can reset permissions flags
86
+ # spellchecker:disable-next-line
87
+ if RbConfig::CONFIG["host_os"] !~ /mswin|msys|mingw|cygwin|bccwin/i && !File.executable?(binary)
88
+ File.chmod(0o755, binary)
89
+ end
90
+
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)
96
+
97
+ if status.success?
98
+ Jekyll.logger.info "Jekyll-Pagefind:", "Indexing finished successfully!"
99
+ puts stdout
100
+ else
101
+ Jekyll.logger.error "Jekyll-Pagefind Error:", stderr
102
+ raise "Pagefind binary exited with non-zero status code: #{status.exitstatus}"
103
+ end
20
104
  end
21
105
  end
22
106
  end
107
+
108
+ # Hook ensures Jekyll is entirely done writing HTML pages to disk
109
+ Jekyll::Hooks.register :site, :post_write do |site|
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.0"
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.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - phothinmg
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '4.4'
26
+ - !ruby/object:Gem::Dependency
27
+ name: open3
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.2.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.2.1
26
40
  description: Run pagefind binary in jekyll site
27
41
  email:
28
42
  - phothinmg@disroot.org
@@ -32,8 +46,15 @@ extra_rdoc_files: []
32
46
  files:
33
47
  - LICENSE.txt
34
48
  - README.md
49
+ - assets/linux-arm64/pagefind
50
+ - assets/linux-x64/pagefind
51
+ - assets/macos-arm64/pagefind
52
+ - assets/macos-x64/pagefind
53
+ - assets/windows-arm64/pagefind.exe
54
+ - assets/windows-x64/pagefind.exe
55
+ - jekyll-pagefind.gemspec
35
56
  - lib/jekyll-pagefind.rb
36
- - lib/jekyll/pagefind/version.rb
57
+ - lib/version.rb
37
58
  homepage: https://rubygems.org/gems/jekyll-pagefind
38
59
  licenses:
39
60
  - MIT
@@ -48,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
69
  requirements:
49
70
  - - ">="
50
71
  - !ruby/object:Gem::Version
51
- version: 3.2.0
72
+ version: 3.1.0
52
73
  required_rubygems_version: !ruby/object:Gem::Requirement
53
74
  requirements:
54
75
  - - ">="