jekyll-meilisearch 0.4.5 → 0.4.6

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: 46eee9fd58f159de8337a68eb168e1cec2f44557335c8750c59d04c60a2cd2b3
4
- data.tar.gz: 2517d87cbe406a3c9c95786e5a38f6c9d63480226cf43885a88377e4c6e10820
3
+ metadata.gz: 9a72d0c48b806db86d5f211b3159947de63c62251159cb106e51bb511479af94
4
+ data.tar.gz: 22c93c7ccebd787cfbd368fa5f153e07557d598262ed57190be71a4ef66d0257
5
5
  SHA512:
6
- metadata.gz: 205b32e6ecd9bb4b9b5b6fe721f147bf8832df362480c0b5278f5be737b48f65c2126016136998d6e8d116c9118fd249b40745f705bfbdf7f89f458b91f91ffb
7
- data.tar.gz: 4942ed0d26057413b014dcc49c9ac2f944c02108ebc2d080d9fe4a30ba687da3f6e2352959a48e24d269fb1487a1c0f1410204a7e1227ef193c7df5fcbd0936b
6
+ metadata.gz: e2095243088ae1c036775dc5b4f4c667000645f72d81f967fbefabd078f2639cdf1dbcf10cd20f03870db864219d450456e59bcf2bcfc1b812a15b0722ce56e1
7
+ data.tar.gz: be0979f777189fec3ad95da485a91eac4ae946698a95c0109b895b3ebceb8ea3264fc69f0bcee1647e4d144c54edd532f23dd1cb27030e3132455447dd81f5ba
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A Jekyll plugin that indexes your site’s content into Meilisearch, a fast and lightweight search engine. This plugin supports incremental indexing, ensuring efficient updates by only syncing changes between your Jekyll site and Meilisearch.
4
4
 
5
- [![Continuous Integration](https://github.com/unicolored/jekyll-meilisearch/actions/workflows/ruby.yml/badge.svg)](https://github.com/unicolored/jekyll-meilisearch/actions/workflows/ruby.yml) [![Gem Version](https://badge.fury.io/rb/jekyll-meilisearch.svg)](https://badge.fury.io/rb/jekyll-meilisearch)
5
+ [![Gem Version](https://badge.fury.io/rb/jekyll-meilisearch.svg)](https://badge.fury.io/rb/jekyll-meilisearch)
6
6
 
7
7
  ## Features
8
8
  - Indexes Jekyll collections (e.g., posts, pages) into Meilisearch.
@@ -72,8 +72,9 @@ Build your site. The plugin will:
72
72
  - Create the Meilisearch index if it doesn’t exist.
73
73
  - Fetch existing documents from Meilisearch.
74
74
  - Delete obsolete documents.
75
- - Index new or updated documents.
75
+ - Index only new or updated collections defined in the config
76
76
  - Logs will output to STDOUT with details about the indexing process.
77
+ - Skip indexing if the meilisearch host is unavailable
77
78
 
78
79
  Include the following for adding search to your front :
79
80
  ```html
@@ -12,15 +12,49 @@ module JekyllMeilisearch
12
12
  Jekyll.logger.info "Jekyll Meilisearch:", "Skipping meilisearch indexation in development"
13
13
  return
14
14
  end
15
+
16
+ # Skip indexing unless relevant files have changed in incremental mode
17
+ unless should_index?
18
+ Jekyll.logger.info "Jekyll Meilisearch:", "No relevant changes detected. Skipping indexing."
19
+ return
20
+ end
21
+
15
22
  Jekyll.logger.info "Starting Meilisearch incremental indexing..."
16
23
  return unless validate_config
17
24
 
18
- @documents = build_documents
19
- sync_with_meilisearch
25
+ begin
26
+ @documents = build_documents
27
+ sync_with_meilisearch
28
+ rescue StandardError => e
29
+ Jekyll.logger.error "Jekyll Meilisearch:", "Indexing failed due to an error: #{e.message}"
30
+ Jekyll.logger.info "Jekyll Meilisearch:", "Skipping Meilisearch indexing, but continuing Jekyll build."
31
+ nil
32
+ end
20
33
  end
21
34
 
22
35
  private
23
36
 
37
+ # Determine if indexing should occur based on changed files
38
+ def should_index?
39
+ # If not in incremental mode or first build, always index
40
+ return true unless @site.incremental?
41
+
42
+ # Get the collections to monitor from config
43
+ collections_config = config["collections"] || { "posts" => { "fields" => %w(title content url date) } }
44
+ monitored_collections = collections_config.keys
45
+
46
+ # Check if any changed files belong to the monitored collections
47
+ changed_files = @site.regenerator.modified_files
48
+ return false if changed_files.empty?
49
+
50
+ changed_files.any? do |file|
51
+ # Extract the relative path and check if it matches a collection
52
+ relative_path = file.relative_path.sub(%r!^/!, "")
53
+ collection_name = relative_path.split("/").first
54
+ monitored_collections.include?(collection_name)
55
+ end
56
+ end
57
+
24
58
  # Returns the plugin's config or an empty hash if not set
25
59
  def config
26
60
  @config ||= begin
@@ -61,7 +95,6 @@ module JekyllMeilisearch
61
95
  id_format = collection_settings["id_format"] || :default
62
96
 
63
97
  collection_docs = collection.docs.map do |doc|
64
- # Skip if no front matter
65
98
  next unless doc.data.any?
66
99
 
67
100
  sanitized_id = generate_id(doc, collection_name, id_format)
@@ -134,8 +167,7 @@ module JekyllMeilisearch
134
167
  loop do
135
168
  response = attempt_request(
136
169
  lambda {
137
- HTTParty.get("#{url}/indexes/#{index_name}/documents?limit=#{limit}&offset=#{offset}", :headers => headers,
138
- :timeout => 30)
170
+ HTTParty.get("#{url}/indexes/#{index_name}/documents?limit=#{limit}&offset=#{offset}", :headers => headers, :timeout => 30)
139
171
  },
140
172
  "fetching documents"
141
173
  )
@@ -179,7 +211,6 @@ module JekyllMeilisearch
179
211
  "indexing documents"
180
212
  )
181
213
  Jekyll.logger.info "Response code: #{response&.code}"
182
- Jekyll.logger.info "Response response: #{response&.response}"
183
214
  if response&.code == 202
184
215
  if response.body
185
216
  task = JSON.parse(response.body)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Meilisearch
5
- VERSION = "0.4.5"
5
+ VERSION = "0.4.6"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-meilisearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - unicolored
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-30 00:00:00.000000000 Z
11
+ date: 2025-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty