Skip to content

Commit 60f3d31

Browse files
authored
Make sure path link in footers work correctly (#1508)
Fixes #1498
1 parent b407fdd commit 60f3d31

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/rdoc/generator/aliki.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require 'uri'
4+
35
##
46
# Aliki theme for RDoc documentation
57
#
@@ -115,6 +117,21 @@ def write_search_index
115117
File.write search_index_path, "var search_data = #{JSON.generate(data)};"
116118
end
117119

120+
##
121+
# Resolves a URL for use in templates. Absolute URLs are returned unchanged.
122+
# Relative URLs are prefixed with rel_prefix to ensure they resolve correctly from any page.
123+
124+
def resolve_url(rel_prefix, url)
125+
uri = URI.parse(url)
126+
if uri.absolute?
127+
url
128+
else
129+
"#{rel_prefix}/#{url}"
130+
end
131+
rescue URI::InvalidURIError
132+
"#{rel_prefix}/#{url}"
133+
end
134+
118135
private
119136

120137
def build_class_module_entry(klass)

lib/rdoc/generator/template/aliki/_footer.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<h3><%= h column_title %></h3>
77
<ul>
88
<% links.each do |text, url| %>
9-
<li><a href="<%= h url %>"><%= h text %></a></li>
9+
<li><a href="<%= h resolve_url(rel_prefix, url) %>"><%= h text %></a></li>
1010
<% end %>
1111
</ul>
1212
</div>

0 commit comments

Comments
 (0)