class WaxTasks::Index
Attributes
collections[R]
path[R]
Public Class Methods
new(config)
click to toggle source
# 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
Public Instance Methods
records()
click to toggle source
# 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)
click to toggle source
# 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