Commit 8d8e494e authored by Tobias Schmidt's avatar Tobias Schmidt

Fix relative links in repo docs

Relative links always need to point to one level below the current path,
as nanoc path end on a trailing slash.
parent 34e6a4a2
...@@ -17,9 +17,10 @@ class NormalizeLinks < ::Nanoc::Filter ...@@ -17,9 +17,10 @@ class NormalizeLinks < ::Nanoc::Filter
when link['href'].start_with?(DOMAIN) when link['href'].start_with?(DOMAIN)
link['href'][DOMAIN.size..-1] link['href'][DOMAIN.size..-1]
when link['href'].start_with?('/') when link['href'].start_with?('/')
link_to(link['href'], config) # TODO(ts): It's not guaranteed that a repository is hosted on Github.
github_link_to(link['href'], config)
when link['href'].include?('.md') when link['href'].include?('.md')
link['href'].gsub(/\.md($|#)/, '/\\1') relative_link_to(link['href'])
else else
link['href'] link['href']
end end
...@@ -28,12 +29,16 @@ class NormalizeLinks < ::Nanoc::Filter ...@@ -28,12 +29,16 @@ class NormalizeLinks < ::Nanoc::Filter
doc.to_s doc.to_s
end end
# TODO(ts): It's not guaranteed that a repository is hosted on Github. def github_link_to(file, config)
def link_to(file, config)
base = config[:repository] base = config[:repository]
if base.end_with?('.git') if base.end_with?('.git')
base = base[0..-5] base = base[0..-5]
end end
File.join(base, 'blob', config[:refspec], file) File.join(base, 'blob', config[:refspec], file)
end end
def relative_link_to(link)
# All nanoc pages end on a trailing slash.
File.join("../", link.gsub(/\.md($|#)/, '/\\1'))
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment