jekyll-algolia 1.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 908e1efd4a59058e6114367dbac92298c5048fef
4
- data.tar.gz: 2af6dc2c224934a0611a5552a9bc1f24166567ac
3
+ metadata.gz: eb9ad0518a59d9f4f5f1144dd0df8fe2353fa88c
4
+ data.tar.gz: 2f250877aec7171e74d72bbb18853920d9c02887
5
5
  SHA512:
6
- metadata.gz: c59408616011d5e7588cdab5206d018d57cdc6f068dbf5cad43681b9e2f6f4aa2a0a8ce51495a867768ca004c63aa89639d6f11b0a3d081cc7d27c63d0a4c584
7
- data.tar.gz: 2d540913e362d63fc91b4e20a95ee95754fe3746c66f35267d1944846837e825eb573fd138a7425beb4f4299d5c71eb64f3cd23931c5c46b94d8e833abc85914
6
+ metadata.gz: 2458c1300860126ad1f915cb591df1b6d764fb35808578810777f4814eb1cfe711cea28eba30d3b3334307970fa85259940fd3cc822cce024636b399bad446e4
7
+ data.tar.gz: 2352c7b494c6ef70e8fa90e25c55a2ec55962abe81c7d6e690ba430a1bdfe4e1f032ea9b3a43a9bfd8eb0a90b1f60ff29b37bcd2badea3b2b13672b1067c60ca
data/README.md CHANGED
@@ -96,7 +96,7 @@ plugins.
96
96
  [6]: https://img.shields.io/badge/dynamic/json.svg?label=build%3Adevelop&query=value&uri=https%3A%2F%2Fimg.shields.io%2Ftravis%2Falgolia%2Fjekyll-algolia.json%3Fbranch%3Ddevelop
97
97
  [7]: https://img.shields.io/badge/dynamic/json.svg?label=coverage%3Adevelop&colorB=&prefix=&suffix=%25&query=$.coverage_change&uri=https%3A%2F%2Fcoveralls.io%2Fgithub%2Falgolia%2Fjekyll-algolia.json%3Fbranch%3Ddevelop
98
98
  [8]: #more-about-the-community-plan
99
- [9]: https://www.algolia.com/licensing
99
+ [9]: https://www.algolia.com/api-keys
100
100
  [10]: https://www.algolia.com/users/sign_up/hacker
101
101
  [11]: https://community.algolia.com/instantsearch.js/
102
102
  [12]: https://www.algolia.com/press#resources
@@ -1,10 +1,9 @@
1
- E: [✗ Error] Invalid credentials
1
+ E:[✗ Error] Invalid credentials
2
2
  E:
3
- E: The jekyll-algolia plugin could not connect to your application ID using the
4
- E: API key your provided.
3
+ E:The jekyll-algolia plugin could not connect to your application ID using the API key your provided.
5
4
  W:
6
- W: Make sure your API key has access to your {application_id} application.
5
+ W:Make sure your API key has access to your {application_id} application.
7
6
  I:
8
- I: You can find your API key in your Algolia dashboard here:
9
- I: https://www.algolia.com/licensing
7
+ I:You can find your API key in your Algolia dashboard here:
8
+ I:   https://www.algolia.com/licensing
10
9
  I:
@@ -1,11 +1,9 @@
1
- E: [✗ Error] Invalid index name
1
+ E:[✗ Error] Invalid index name
2
2
  E:
3
- E: The jekyll-algolia plugin could push records to your index as its name
4
- E: contains invalid characters.
3
+ E:The jekyll-algolia plugin could push records to your index as its name contains invalid characters.
5
4
  W:
6
- W: Some special characters are not allowed in the naming of indices and your
7
- W: index {index_name} contains some of them.
5
+ W:Some special characters are not allowed in the naming of indices and your index {index_name} contains some of them.
8
6
  I:
9
- I: Please, check our FAQ for more details:
10
- I: https://www.algolia.com/doc/faq/index-configuration/what-can-i-name-my-indices/
7
+ I:Please, check our FAQ for more details:
8
+ I:  https://www.algolia.com/doc/faq/index-configuration/what-can-i-name-my-indices/
11
9
  I:
@@ -1,17 +1,15 @@
1
- E: [✗ Error] Missing API key
1
+ E:[✗ Error] Missing API key
2
2
  E:
3
- E: The jekyll-algolia plugin could not find your API key.
3
+ E:The jekyll-algolia plugin could not find your API key.
4
4
  W:
5
- W: Please, define your API key either by:
5
+ W:Please, define your API key either by:
6
6
  W:
7
- W: 1/ Defining an ENV variable when calling `jekyll algolia`
8
- W: $ ALGOLIA_API_KEY='{your_api_key}' jekyll algolia
7
+ W:1/ Defining an ENV variable when calling `jekyll algolia`
8
+ W:   $ ALGOLIA_API_KEY='{your_api_key}' jekyll algolia
9
9
  W:
10
- W: 2/ Save your API key in a named `_algolia_api_key` in your source directory.
11
- W: If you do this, we strongly recommend you to NOT track this file in your
12
- W: versionning system.
13
- I:
14
- I: You can find your API key in your Algolia dashboard here:
15
- I: https://www.algolia.com/licensing
10
+ W:2/ Save your API key in a named `_algolia_api_key` in your source directory.
11
+ W:   If you do this, we strongly recommend you to NOT track this file in your versionning system.
16
12
  I:
13
+ I:You can find your API key in your Algolia dashboard here:
14
+ I:   https://www.algolia.com/api-keys
17
15
  I:
@@ -1,12 +1,11 @@
1
- E: [✗ Error] No application ID defined
1
+ E:[✗ Error] No application ID defined
2
2
  E:
3
- E: The jekyll-algolia plugin could not find your Algolia application ID.
3
+ E:The jekyll-algolia plugin could not find your Algolia application ID.
4
4
  W:
5
- W: Please, define it in your Jekyll _config.yml file like this:
5
+ W:Please, define it in your Jekyll _config.yml file like this:
6
6
  W:
7
- W: algolia:
8
- W: application_id: {your_application_id}
7
+ W:  algolia:
8
+ W:    application_id: {your_application_id}
9
9
  I:
10
- I: You can find your application ID along with all your credentials in your
11
- I: Algolia dashboard here:
12
- I: https://www.algolia.com/licensing
10
+ I:You can find your application ID along with all your credentials in your Algolia dashboard here:
11
+ I:   https://www.algolia.com/api-keys
@@ -1,19 +1,18 @@
1
- E: [✗ Error] No index name defined
1
+ E:[✗ Error] No index name defined
2
2
  E:
3
- E: The jekyll-algolia plugin could not find the name of the Algolia index you
4
- E: want to push your records to.
3
+ E:The jekyll-algolia plugin could not find the name of the Algolia index you want to push your records to.
5
4
  W:
6
- W: Please, define it in your Jekyll _config.yml file like this:
5
+ W:Please, define it in your Jekyll _config.yml file like this:
7
6
  W:
8
- W: algolia:
9
- W: index_name: {your_index_name}
7
+ W:  algolia:
8
+ W:   index_name: {your_index_name}
10
9
  W:
11
- W: Alternatively, you can also define it as an ENV variable, like this:
10
+ W:Alternatively, you can also define it as an ENV variable, like this:
12
11
  W:
13
- W: $ ALGOLIA_INDEX_NAME='{your_index_name}' jekyll algolia
12
+ W:  $ ALGOLIA_INDEX_NAME='{your_index_name}' jekyll algolia
14
13
  W:
15
- I: You can see all your indices from your Algolia dashboard here:
16
- I: https://www.algolia.com/explorer
14
+ I:You can see all your indices from your Algolia dashboard here:
15
+ I:  https://www.algolia.com/explorer
17
16
  I:
18
- I: Note that you don't have to create an index before pushing records.
19
- I: It will be created automatically if it does not exist yet.
17
+ I:Note that you don't have to create an index before pushing records.
18
+ I:It will be created automatically if it does not exist yet.
@@ -1,20 +1,14 @@
1
- E: [✗ Error] No records found
1
+ E:[✗ Error] No records found
2
2
  E:
3
- E: The jekyll-algolia plugin could find any records to index
3
+ E:The jekyll-algolia plugin could find any records to index
4
4
  W:
5
- W: The plugin tried to extract records from the pages, posts and collections of
6
- W: your site but could not find anything to index.
5
+ W:The plugin tried to extract records from the pages, posts and collections of your site but could not find anything to index.
7
6
  I:
8
- I: Make sure you did not exclude too many files from indexing using the
9
- I: `files_to_exclude` option. You are currently excluding the following files:
10
- I: {files_to_exclude}
7
+ I:Make sure you did not exclude too many files from indexing using the `files_to_exclude` option. You are currently excluding the following files:
8
+ I:    {files_to_exclude}
11
9
  I:
12
- I: Also double check that your current value for `nodes_to_index` can actually
13
- I: match something in the pages. You are current indexing the following nodes:
14
- I: {nodes_to_index}
10
+ I:Also double check that your current value for `nodes_to_index` can actually match something in the pages. You are current indexing the following nodes:
11
+ I:    {nodes_to_index}
15
12
  I:
16
- I: Note that all the markup that is defined in the layouts won't be available
17
- I: during extraction. Only the page content can be accessed. So if you defined
18
- I: a layout markup that is used only for one page, you should move it to the
19
- I: page instead.
13
+ I:Note that all the markup that is defined in the layouts won't be available during extraction. Only the page content can be accessed. So if you defined a layout markup that is used only for one page, you should move it to the page instead.
20
14
  I:
@@ -1,27 +1,22 @@
1
- E: [✗ Error] Record is too big
1
+ E:[✗ Error] Record is too big
2
2
  E:
3
- E: The jekyll-algolia plugin could not push one of your records as it exceeds
4
- E: the {size_limit} size limit.
3
+ E:The jekyll-algolia plugin could not push one of your records as it exceeds the {size_limit} size limit.
5
4
  W:
6
- W: The plugin will create one record for each element matching your
7
- W: `nodes_to_index` value (currently set to "{nodes_to_index}"). Each record
8
- W: should not weight more than {size_limit}.
9
- W: One of your records weights {size} and has been rejected.
5
+ W:The plugin will create one record for each element matching your `nodes_to_index` value (currently set to "{nodes_to_index}").
6
+ W:Each record should not weight more than {size_limit}.
7
+ W:One of your records weights {size} and has been rejected.
10
8
  W:
11
- W: objectID: {object_id}
12
- W: title: {object_title}
13
- W: url: {object_url}
9
+ W:objectID: {object_id}
10
+ W:title:    {object_title}
11
+ W:url:      {object_url}
14
12
  W:
15
- W: Most probable keys causing the issue:
16
- W: {probable_wrong_keys}
13
+ W:Most probable keys causing the issue:
14
+ W:   {probable_wrong_keys}
17
15
  W:
18
- W: Complete log of the record has been extracted to:
19
- W: {record_log_path}
20
- W:
21
- I: This issue can be caused by malformed HTML preventing the parser to correctly
22
- I: grab the content of the nodes. Double check that the page actually renders
23
- I: correctly with a regular `jekyll build`.
16
+ W:Complete log of the record has been extracted to:
17
+ W:   {record_log_path}
18
+ W:
19
+ I:This issue can be caused by malformed HTML preventing the parser to correctly grab the content of the nodes. Double check that the page actually renders correctly with a regular `jekyll build`.
24
20
  I:
25
- I: If you're having trouble solving this issue, feel free to file a bug on
26
- I: GitHub, ideally with a link to a repository where we can reproduce the issue.
27
- I: https://github.com/algolia/jekyll-algolia/issues
21
+ I:If you're having trouble solving this issue, feel free to file a bug on GitHub, ideally with a link to a repository where we can reproduce the issue.
22
+ I:  https://github.com/algolia/jekyll-algolia/issues
@@ -0,0 +1,17 @@
1
+ I:
2
+ W:[jekyll-algolia] Configuration mismatch:
3
+ W:It seems that your index settings have been edited from outside of the jekyll-algolia plugin.
4
+ I:
5
+ I:This can happen if you manually edited them from the Algolia dashboard, for example. Don't worry, they will still be honored (for now).
6
+ I:
7
+ I:Still, we strongly encourage you to save any custom config inside the algolia.settings key of your _config.yml instead. Any value set there will always take precedence over anything you manually set in your dashboard.
8
+ I:This is the best way to be sure your settings won't be lost in the future.
9
+ I:
10
+ W:To keep your current custom config, here is what you should add to your _config.yml file:
11
+ W:
12
+ W:algolia:
13
+ W:  settings:
14
+ {settings}
15
+ I:
16
+ I:If you'd like to revert your index to its default settings, the best way is to delete the index and run `jekyll algolia` again.
17
+ I:
@@ -1,20 +1,16 @@
1
- E: [✗ Error] Unreachable server
1
+ E:[✗ Error] Unreachable server
2
2
  E:
3
- E: The jekyll-algolia plugin could not contact the server hosting your
4
- E: application.
3
+ E:The jekyll-algolia plugin could not contact the server hosting your application.
5
4
  W:
6
- W: Make sure you correctly typed your application ID. As we are using the
7
- W: application ID as part of the server url, any typo in the application ID will
8
- W: prevent us from reaching your server.
5
+ W:Make sure you correctly typed your application ID. As we are using the application ID as part of the server url, any typo in the application ID will prevent us from reaching your server.
9
6
  W:
10
- I: Here is the application ID you defined: {application_id}
7
+ I:Here is the application ID you defined: {application_id}
11
8
  I:
12
- I: Make sure it's the same as the one displayed in your dashboard:
13
- I: https://www.algolia.com/licensing
9
+ I:Make sure it's the same as the one displayed in your dashboard:
10
+ I:   https://www.algolia.com/api-keys
14
11
  I:
15
- I: Then, define it in your Jekyll _config.yml file like this:
16
- I:
17
- I: algolia:
18
- I: application_id: {your_application_id}
12
+ I:Then, define it in your Jekyll _config.yml file like this:
19
13
  I:
14
+ I:  algolia:
15
+ I:    application_id: {your_application_id}
20
16
  I:
@@ -1,15 +1,12 @@
1
- E: [✗ Error] Unknown setting
1
+ E:[✗ Error] Unknown setting
2
2
  E:
3
- E: The jekyll-algolia plugin could not correctly configure your index as some of
4
- E: the settings passed are not recognized.
3
+ E:The jekyll-algolia plugin could not correctly configure your index as some of the settings passed are not recognized.
5
4
  W:
6
- W: It seems that one of the custom index settings you defined was not recognized
7
- W: by the API and was rejected:
8
- W: {setting_name}: {setting_value}
5
+ W:It seems that one of the custom index settings you defined was not recognized by the API and was rejected:
6
+ W:  {setting_name}: {setting_value}
9
7
  I:
10
- I: Make sure the setting name and value are correct. You can find a list of all
11
- I: the available settings with their documentation in our API reference:
12
- I: https://www.algolia.com/doc/api-reference/api-parameters/
13
- I: Or specifically for this setting:
14
- I: https://www.algolia.com/doc/api-reference/api-parameters/{setting_name}/
8
+ I:Make sure the setting name and value are correct. You can find a list of all the available settings with their documentation in our API reference:
9
+ I:  https://www.algolia.com/doc/api-reference/api-parameters/
10
+ I:Or specifically for this setting:
11
+ I:  https://www.algolia.com/doc/api-reference/api-parameters/{setting_name}/
15
12
  I:
@@ -1,21 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'jekyll/commands/algolia'
4
+ require 'jekyll/algolia/overwrites'
4
5
  require 'date'
5
6
 
6
7
  module Jekyll
7
8
  # Requirable file, loading all dependencies.
8
9
  # Methods here are called by the main `jekyll algolia` command
9
10
  module Algolia
10
- require 'jekyll/algolia/version'
11
- require 'jekyll/algolia/utils'
12
- require 'jekyll/algolia/hooks'
13
11
  require 'jekyll/algolia/configurator'
14
- require 'jekyll/algolia/logger'
15
12
  require 'jekyll/algolia/error_handler'
16
- require 'jekyll/algolia/file_browser'
17
13
  require 'jekyll/algolia/extractor'
14
+ require 'jekyll/algolia/file_browser'
15
+ require 'jekyll/algolia/hooks'
18
16
  require 'jekyll/algolia/indexer'
17
+ require 'jekyll/algolia/logger'
18
+ require 'jekyll/algolia/progress_bar'
19
+ require 'jekyll/algolia/utils'
20
+ require 'jekyll/algolia/version'
19
21
 
20
22
  # Public: Init the Algolia module
21
23
  #
@@ -25,7 +27,6 @@ module Jekyll
25
27
  # The gist of the plugin works by instanciating a Jekyll site,
26
28
  # monkey-patching its `write` method and building it.
27
29
  def self.init(config = {})
28
- @start_time = Time.now
29
30
  config = Configurator.init(config).config
30
31
  @site = Jekyll::Algolia::Site.new(config)
31
32
 
@@ -62,43 +63,121 @@ module Jekyll
62
63
  @site
63
64
  end
64
65
 
65
- # Public: Get access to the time at which the command was run
66
- #
67
- # Jekyll will always set the updated time of pages to the time of the build
68
- # run. The plugin needs those values to stay at nil if they did not change,
69
- # so we'll keep track of the time at build time and revert any page build at
70
- # that time to nil.
71
- def self.start_time
72
- @start_time
73
- end
74
-
75
- # A Jekyll::Site subclass that overrides #write from the parent class to
66
+ # A Jekyll::Site subclass that overrides process from the parent class to
76
67
  # create JSON records out of rendered documents and push those records to
77
68
  # Algolia instead of writing files to disk.
78
69
  class Site < Jekyll::Site
79
- # We make the cleanup method a noop, otherwise it will remove excluded
80
- # files from destination
81
- def cleanup; end
70
+ # We expose a way to reset the collection, as it will be needed in the
71
+ # tests
72
+ attr_writer :collections
73
+
74
+ # Public: Overwriting the parent method
75
+ #
76
+ # This will prepare the website, gathering all files, excluding the one we
77
+ # don't need to index, then render them (converting to HTML), the finally
78
+ # calling `push` to push to Algolia
79
+ def process
80
+ # Default Jekyll preflight
81
+ reset
82
+ read
83
+ generate
84
+
85
+ # Removing all files that won't be indexed, so we don't waste time
86
+ # rendering them
87
+ keep_only_indexable_files
88
+
89
+ # Starting the rendering progress bar
90
+ init_rendering_progress_bar
91
+
92
+ # Converting them to HTML
93
+ render
94
+
95
+ # Pushing them Algolia
96
+ push
97
+ end
98
+
99
+ # Public: Return the number of pages/documents to index
100
+ def indexable_item_count
101
+ count = @pages.length
102
+ @collections.each_value { |collection| count += collection.docs.length }
103
+ count
104
+ end
105
+
106
+ # Public: Init the rendering progress bar, incrementing it for each
107
+ # rendered item
108
+ #
109
+ # This uses Jekyll post_render hooks, listening to both pages and
110
+ # documents
111
+ def init_rendering_progress_bar
112
+ progress_bar = ProgressBar.create(
113
+ total: indexable_item_count,
114
+ format: 'Rendering to HTML (%j%%) |%B|'
115
+ )
116
+ Jekyll::Hooks.register :pages, :post_render do |_|
117
+ progress_bar.increment
118
+ end
119
+
120
+ Jekyll::Hooks.register :documents, :post_render do |_|
121
+ progress_bar.increment
122
+ end
123
+ end
82
124
 
83
- def write
125
+ # Public: Filtering a list of items to only keep the one that are
126
+ # indexable.
127
+ #
128
+ # items - List of Pages/Documents
129
+ #
130
+ # Note: It also sets the layout to nil, to further speed up the rendering
131
+ def indexable_list(items)
132
+ new_list = []
133
+ items.each do |item|
134
+ next unless FileBrowser.indexable?(item)
135
+
136
+ item.data = {} if item.data.nil?
137
+ item.data['layout'] = nil
138
+ new_list << item
139
+ end
140
+ new_list
141
+ end
142
+
143
+ # Public: Removing non-indexable Pages, Posts and Documents from the
144
+ # internals
145
+ def keep_only_indexable_files
146
+ @pages = indexable_list(@pages)
147
+
148
+ # Applying to each collections
149
+ @collections.each_value do |collection|
150
+ collection.docs = indexable_list(collection.docs)
151
+ end
152
+
153
+ # Remove all static files
154
+ @static_files = []
155
+ end
156
+
157
+ # Public: Extract records from every file and index them
158
+ def push
84
159
  records = []
85
160
  files = []
86
- Logger.log('I:Extracting records...')
161
+ progress_bar = ProgressBar.create(
162
+ total: indexable_item_count,
163
+ format: 'Extracting records (%j%%) |%B|'
164
+ )
87
165
  each_site_file do |file|
88
- path = FileBrowser.relative_path(file)
166
+ # Even if we cleared the list of documents/pages beforehand, some
167
+ # files might still sneak up to this point (like static files added to
168
+ # a collection directory), so we check again if they can really be
169
+ # indexed.
170
+ next unless FileBrowser.indexable?(file)
89
171
 
90
- # Skip files that should not be indexed
91
- is_indexable = FileBrowser.indexable?(file)
92
- unless is_indexable
93
- Logger.verbose("W:Skipping #{path}")
94
- next
95
- end
172
+ path = FileBrowser.relative_path(file.path)
96
173
 
97
174
  Logger.verbose("I:Extracting records from #{path}")
98
175
  file_records = Extractor.run(file)
99
176
 
100
177
  files << file
101
178
  records += file_records
179
+
180
+ progress_bar.increment
102
181
  end
103
182
 
104
183
  # Applying the user hook on the whole list of records