Skip to content

Commit fb5efaa

Browse files
committed
Fix sidebar links on /docs site
1 parent beb28e3 commit fb5efaa

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/contents.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def nextpages
130130

131131
def toc_link page
132132
link_text = page.split(/[-_]/).map{|s|s.capitalize}.join(' ')
133-
path = "/#{@site_name}/" + page
133+
path = page.start_with?('/') ? page : "/#{@site_name}/" + page
134134
li do
135135
if page == page_name
136136
span link_text, class: 'current'

spec/contents_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@
44
require_relative "../lib/contents"
55

66
here = File.expand_path File.dirname(__FILE__)
7+
real_sites_dir = File.expand_path "#{here}/../sites"
78

89
describe Contents do
9-
before :all do
10+
before do
1011
@meals_toc = Contents.new(site_name: 'meals', site_dir: "#{here}/sites/meals", page_name: 'prepare_a_meal')
1112
end
1213

14+
it "should render absolute links absolutely" do
15+
@docs_toc = Contents.new(site_name: 'docs', site_dir: "#{real_sites_dir}/docs", page_name: 'docs')
16+
17+
toc_html = Nokogiri.parse(@docs_toc.to_html)
18+
links = toc_html.css('a').inject({}) { |hsh, link| hsh[link.text] = link.attr('href'); hsh }
19+
links['/curriculum'].should == '/curriculum'
20+
end
21+
1322
it "scans for subpage links" do
1423
@meals_toc.subpages.should == {
1524
"breakfast"=>[],

0 commit comments

Comments
 (0)