Skip to content

Commit

Permalink
FIX: Broken GitHub folder onebox logic (discourse#15612)
Browse files Browse the repository at this point in the history
1. `html_doc.css('.Box.md')` always returns a truthy value (e.g. `[]`) so the second branch of the if-elsif never ran
2. `node&.css('text()')` was invalid code that would raise an error
3. Matching on h3 elements is no longer correct with the current html structure returned by GitHub
  • Loading branch information
CvX authored Jan 17, 2022
1 parent 59d78dc commit 31b27b3
Show file tree
Hide file tree
Showing 3 changed files with 2,406 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/onebox/engine/github_folder_onebox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ def data
if fragment
fragment = Addressable::URI.unencode(fragment)

if html_doc.css('.Box.md')
# For links to markdown docs
# For links to markdown and rdoc
if html_doc.css(".Box.md, .Box.rdoc").present?
node = html_doc.css('a.anchor').find { |n| n['href'] == "##{fragment}" }
subtitle = node&.parent&.text
elsif html_doc.css('.Box.rdoc')
# For links to rdoc docs
node = html_doc.css('h3').find { |n| n['id'] == "user-content-#{fragment.downcase}" }
subtitle = node&.css('text()')&.first&.text
end

title = "#{title} - #{subtitle}" if subtitle
Expand Down
Loading

0 comments on commit 31b27b3

Please sign in to comment.