Class: WaxTasks::Index
- Inherits:
-
Object
- Object
- WaxTasks::Index
- Defined in:
- lib/wax_tasks/index.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
readonly
Returns the value of attribute collections.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(config) ⇒ Index
constructor
A new instance of Index.
- #records ⇒ Object
- #write_to(dir) ⇒ Object
Constructor Details
#initialize(config) ⇒ Index
Returns a new instance of Index.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/wax_tasks/index.rb', line 8 def initialize(config) @config = config @collections = config.dig 'collections' @path = config.dig 'index' raise WaxTasks::Error::NoSearchCollections if @collections.nil? raise WaxTasks::Error::InvalidConfig if @path.nil? @records = records end |
Instance Attribute Details
#collections ⇒ Object (readonly)
Returns the value of attribute collections.
6 7 8 |
# File 'lib/wax_tasks/index.rb', line 6 def collections @collections end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/wax_tasks/index.rb', line 6 def path @path end |
Instance Method Details
#records ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wax_tasks/index.rb', line 21 def records lunr_id = 0 @collections.flat_map do |collection| collection.records_from_pages.each.flat_map do |r| r.keep_only collection.search_fields r.set 'lunr_id', lunr_id r.lunr_normalize_values lunr_id += 1 r end end end |
#write_to(dir) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/wax_tasks/index.rb', line 36 def write_to(dir) file_path = WaxTasks::Utils.safe_join dir, @path FileUtils.mkdir_p File.dirname(file_path) File.open(file_path, 'w') do |f| f.puts "---\nlayout: none\n---\n" f.puts JSON.pretty_generate(@records.map(&:hash)) end end |