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
when link['href'].start_with?(DOMAIN)
link['href'][DOMAIN.size..-1]
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')
link['href'].gsub(/\.md($|#)/, '/\\1')
relative_link_to(link['href'])
else
link['href']
end
......@@ -28,12 +29,16 @@ class NormalizeLinks < ::Nanoc::Filter
doc.to_s
end
# TODO(ts): It's not guaranteed that a repository is hosted on Github.
def link_to(file, config)
def github_link_to(file, config)
base = config[:repository]
if base.end_with?('.git')
base = base[0..-5]
end
File.join(base, 'blob', config[:refspec], file)
end
def relative_link_to(link)
# All nanoc pages end on a trailing slash.
File.join("../", link.gsub(/\.md($|#)/, '/\\1'))
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