Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Begin populating search index with API docs
Browse files Browse the repository at this point in the history
With these changes, we populate the search index with all instance
methods present in the latest version of Atom. Next up, we'll need to
add classes, class methods, and instance properties to the search index.

Co-Authored-By: Antonio Scandurra <[email protected]>
  • Loading branch information
jasonrudolph and Antonio Scandurra committed Jul 1, 2019
1 parent 5dfe19b commit aeee307
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
15 changes: 15 additions & 0 deletions content/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>

{}
]
}
1 change: 1 addition & 0 deletions lib/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'active_support/core_ext/string'

require_relative 'chapters'
require_relative 'search'
require_relative 'sections'
require_relative 'strings'

Expand Down
19 changes: 19 additions & 0 deletions lib/search.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit aeee307

Please sign in to comment.