Commit c4ded595 authored by David Wagner's avatar David Wagner

Fix broken external links in help/index.html

An external link was recently added but was broken because
'https://gitlab.com/help/' was prepended to every link in the page.

Since no link in the main help readme begins with "help" and since doing
so wouldn't make sense, the substitution conditionaly prepending "help"
can be simplified and reused.
Signed-off-by: default avatarDavid Wagner <david@marvid.fr>
parent 9aded5c8
......@@ -6,9 +6,9 @@ class HelpController < ApplicationController
def index
@help_index = File.read(Rails.root.join('doc', 'README.md'))
# Prefix Markdown links with `help/` unless they already have been
# See http://rubular.com/r/ie2MlpdUMq
@help_index.gsub!(/(\]\()(\/?help\/)?([^\)\(]+\))/, '\1/help/\3')
# Prefix Markdown links with `help/` unless they are external links
# See http://rubular.com/r/MioSrVLK3S
@help_index.gsub!(%r{(\]\()(?!.+://)([^\)\(]+\))}, '\1/help/\2')
end
def show
......
......@@ -16,14 +16,6 @@ describe HelpController do
end
end
context 'when url prefixed with help/' do
it 'will be an absolute path' do
stub_readme("[API](help/api/README.md)")
get :index
expect(assigns[:help_index]).to eq '[API](/help/api/README.md)'
end
end
context 'when url prefixed with help' do
it 'will be an absolute path' do
stub_readme("[API](helpful_hints/README.md)")
......@@ -32,11 +24,11 @@ describe HelpController do
end
end
context 'when url prefixed with /help/' do
context 'when url is an external link' do
it 'will not be changed' do
stub_readme("[API](/help/api/README.md)")
stub_readme("[external](https://some.external.link)")
get :index
expect(assigns[:help_index]).to eq '[API](/help/api/README.md)'
expect(assigns[:help_index]).to eq '[external](https://some.external.link)'
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