diff --git a/content/search.json b/content/search.json index b2a4ad278b..ceb3f1c2f8 100644 --- a/content/search.json +++ b/content/search.json @@ -13,6 +13,21 @@ }, <% end %> <% end %> + + <% latest_atom_version_apis.each do |klass| %> + <% klass.fetch('instanceMethods', []).each do |instance_method| %> + <% body = compress(safe_embed(instance_method['description'])) %> + { + "title": "<%= klass['name'] %>::<%= instance_method['name'] %>", + "category": "", + "category_url": "", + "url": "/api/<%= latest_atom_version_number %>/<%= klass['name'] %>/#instance-<%= instance_method['name'] %>", + "body": "<%= body %>", + "excerpt": "<%= body[0..140] %>…" + }, + <% end %> + <% end %> + {} ] } diff --git a/lib/helpers.rb b/lib/helpers.rb index d61bb7664d..acb5be9bd3 100644 --- a/lib/helpers.rb +++ b/lib/helpers.rb @@ -5,6 +5,7 @@ require 'active_support/core_ext/string' require_relative 'chapters' +require_relative 'search' require_relative 'sections' require_relative 'strings' diff --git a/lib/search.rb b/lib/search.rb new file mode 100644 index 0000000000..b1eb02135f --- /dev/null +++ b/lib/search.rb @@ -0,0 +1,19 @@ +require('json') + +def latest_atom_version_apis + items = @items.find_all("/api/v#{latest_atom_version_number}/*.json") + items.map { |item| JSON.parse(File.read(item.raw_filename)) } +end + +def latest_atom_version_number + @latest_atom_version_number ||= begin + versions = @items.find_all('/api/*/*.json').map { |item| item.path.split('/')[2] }.uniq + + exploded_version_numbers = versions.map { |version| + version_without_prefix = version[1..-1] + version_without_prefix.split('.') + } + + exploded_version_numbers.sort.last.join('.') + end +end