Skip to content

Commit

Permalink
Merge pull request #615 from tnir/tnir-fix-link-to-editable-version
Browse files Browse the repository at this point in the history
Fix dead links on GitHub from man pages
  • Loading branch information
deivid-rodriguez authored Jun 24, 2022
2 parents c68dedd + 31f2213 commit 88e9077
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions helpers/docs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,34 @@ def link_to_documentation(page, version=nil)
end

def link_to_editable_version
editable = true
path = current_page.file_descriptor.relative_path.to_s
repo =
if path.start_with?('doc/')
path = "bundler/#{path}"
'rubygems/rubygems'
elsif path =~ %r{\Av\d+\.\d+/man/(bundle[_-]|gemfile)}
path = "#{strip_version_from_url(path)}.ronn"
path = "bundler/#{path}"
elsif %r{\A(?<version>v\d+\.\d+)/man/(?<filename>(bundle[_-]|gemfile)[^/]*)\.html} =~ path
if version == current_version
path = "bundler/lib/bundler/man/#{filename}.ronn"
else
editable = false
end
'rubygems/rubygems'
else
path = File.join 'source', path
'rubygems/bundler-site'
end
url = "https://github.com/#{repo}/blob/master/#{path}"

link_to('Edit this document on GitHub', url) +
' if you caught an error or noticed something was missing.'
if editable
url = "https://github.com/#{repo}/blob/master/#{path}"
link_to('Edit this document on GitHub', url) +
' if you caught an error or noticed something was missing.'
else
url = "/" + path.sub(version, current_version).sub(/\.html.*/, '.html')
'This document is obsolete. ' +
link_to('See the latest version of this document', url) +
' if you caught an error or noticed something was missing, it may be fixed there.'
end
end

def path_exist?(page, version=nil)
Expand Down

0 comments on commit 88e9077

Please sign in to comment.