Skip to content

Conversation

@mikeygough
Copy link

Motivation / Background

Browsing rubygems.org recently I found it strange that some gems show a "Source Code" link in the sidebar while others do not, even if it is set in the gemspec's source_code_uri field.

For example:

Rake does not show "Source Code"

ActiveSupport does show "Source Code"

Both gems specify a source_code_uri value in their respective gemspec files.

I dove into this and it looks like we are deduping links to declutter the sidebar.

I think this is generally a good idea but would like to propose we always show "Source Code" if it is set. Yes, users can always find the Github page for a gem by clicking the Github Star icon but it feels more intuitive to click "Source Code" if you're looking for the source code.

@etherbob Do you have a strong opinion about this? I don't want to completely revert your change but I also see that even you noted in your original PR, "There's probably also a question to be asked about gem author intent with the duplicate links and whether or not someone might get confused if they don't see a specific link to "source code" for instance if it's been superseded by the "home page" link." I think this is exactly what I'm experiencing and maybe others are as well 😅

Detail

This Pull Request modifies the unique_links method implementation to remove duplicate links but always include source_code_uri.

I decided to change the unique_links method to preserve most of the existing behavior. Given that I'm introducing a uniqueness exception to source_code_uri, should we rename this method? It is still removing duplicate links so maybe it's fine but value others' opinions.

@mikeygough mikeygough force-pushed the always-show-source-code-on-sidebar branch from 72a99f6 to 1f163fd Compare November 25, 2025 20:54
@codecov
Copy link

codecov bot commented Dec 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.46%. Comparing base (bb5e82b) to head (1f163fd).
⚠️ Report is 13 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6118      +/-   ##
==========================================
- Coverage   97.24%   94.46%   -2.78%     
==========================================
  Files         476      476              
  Lines        9785     9851      +66     
==========================================
- Hits         9515     9306     -209     
- Misses        270      545     +275     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@jenshenny jenshenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes sense to me

end

should "always include source code even when duplicate" do
metadata = { "homepage_uri" => "https://example.com", "source_code_uri" => "https://example.com" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
metadata = { "homepage_uri" => "https://example.com", "source_code_uri" => "https://example.com" }
metadata = { "homepage_uri" => "https://example.code", "source_code_uri" => "https://example.code" }

I think you mean this?

Comment on lines +38 to +49
seen_urls = {}
links.select do |short, long|
url = send(long)
# always include 'code' (source_code_uri) even if URL is duplicate
if short == "code"
true
elsif seen_urls[url]
false
else
seen_urls[url] = true
true
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slightly confusing to me since there's a lot of booleans and conditionals, how about this?

Have REQUIRED_INDEXED_LINK_KEYS

Suggested change
seen_urls = {}
links.select do |short, long|
url = send(long)
# always include 'code' (source_code_uri) even if URL is duplicate
if short == "code"
true
elsif seen_urls[url]
false
else
seen_urls[url] = true
true
end
unique_links = links.uniq do |_short, long|
send(long)
end.to_h
# always include certain URLs even if URL is a duplicate
links.select do |short, _long|
unique_links.key?(short) || REQUIRED_INDEXED_LINK_KEYS.include?(short)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants