Module: Jekyll::Algolia::Hooks
- Defined in:
- lib/jekyll/algolia/hooks.rb
Overview
Applying user-defined hooks on the processing pipeline
Class Method Summary collapse
-
.apply_all(records, context) ⇒ Object
Public: Apply the before_indexing_all hook to all records.
-
.apply_each(record, node, context) ⇒ Object
Public: Apply the before_indexing_each hook to the record.
-
.before_indexing_all(records, _context) ⇒ Object
Public: Custom method to be run on the list of all records before indexing them.
-
.before_indexing_each(record, _node, _context) ⇒ Object
Public: Custom method to be run on the record before indexing it.
-
.should_be_excluded?(_filepath) ⇒ Boolean
Public: Check if the file should be indexed or not.
Class Method Details
.apply_all(records, context) ⇒ Object
Public: Apply the before_indexing_all hook to all records. This method is a simple wrapper around methods that can be overwritten by users. Using a wrapper around it makes testing their behavior easier as they can be mocked in tests.
records - The list of all records to be indexed
31 32 33 34 35 36 37 38 |
# File 'lib/jekyll/algolia/hooks.rb', line 31 def self.apply_all(records, context) case method(:before_indexing_all).arity when 1 before_indexing_all(records) else before_indexing_all(records, context) end end |
.apply_each(record, node, context) ⇒ Object
Public: Apply the before_indexing_each hook to the record. This method is a simple wrapper around methods that can be overwritten by users. Using a wrapper around it makes testing their behavior easier as they can be mocked in tests.
record - The hash of the record to be pushed node - The Nokogiri node of the element
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/jekyll/algolia/hooks.rb', line 14 def self.apply_each(record, node, context) case method(:before_indexing_each).arity when 1 before_indexing_each(record) when 2 before_indexing_each(record, node) else before_indexing_each(record, node, context) end end |
.before_indexing_all(records, _context) ⇒ Object
Public: Custom method to be run on the list of all records before indexing them
records - The list of all records to be indexed
Users can modify the full list from here. It might provide an easier interface than ‘hook_before_indexing_each` when knowing the full context is necessary
74 75 76 |
# File 'lib/jekyll/algolia/hooks.rb', line 74 def self.before_indexing_all(records, _context) records end |
.before_indexing_each(record, _node, _context) ⇒ Object
Public: Custom method to be run on the record before indexing it
record - The hash of the record to be pushed node - The Nokogiri node of the element
Users can modify the record (adding/editing/removing keys) here. It can be used to remove keys that should not be indexed, or access more information from the HTML node.
Users can return nil to signal that the record should not be indexed
62 63 64 |
# File 'lib/jekyll/algolia/hooks.rb', line 62 def self.before_indexing_each(record, _node, _context) record end |
.should_be_excluded?(_filepath) ⇒ Boolean
Public: Check if the file should be indexed or not
filepath - The path to the file, before transformation
This hook allow users to define if a specific file should be indexed or not. Basic exclusion can be done through the ‘files_to_exclude` option, but a custom hook like this one can allow more fine-grained customisation.
48 49 50 |
# File 'lib/jekyll/algolia/hooks.rb', line 48 def self.should_be_excluded?(_filepath) false end |