Primer CSS breadcrumbs (related to #1394).

This commit is contained in:
Bart Kamphorst
2020-03-25 20:50:03 +01:00
parent e6ee27a083
commit f1e8d30a43
2 changed files with 9 additions and 8 deletions
+5 -5
View File
@@ -20,18 +20,18 @@ module Precious
def breadcrumb def breadcrumb
if @path if @path
path = Pathname.new(@path) path = Pathname.new(@path)
breadcrumb = [%{<a href="#{overview_path}">Home</a>}] breadcrumb = [%{<nav aria-label="Breadcrumb"><ol><li class="breadcrumb-item"><a href="#{overview_path}">Home</a></li>}]
path.descend do |crumb| path.descend do |crumb|
title = crumb.basename title = crumb.basename
if title == path.basename if title == path.basename
breadcrumb << title breadcrumb << %{<li class="breadcrumb-item" aria-current="page">#{title}</li>}
else else
breadcrumb << %{<a href="#{overview_path}/#{crumb}/">#{title}</a>} breadcrumb << %{<li class="breadcrumb-item"><a href="#{overview_path}/#{crumb}/">#{title}</a></li>}
end end
end end
breadcrumb << %{</ol></nav>}
breadcrumb.join(' / ') breadcrumb.join("\n")
else else
'Home' 'Home'
end end
+4 -3
View File
@@ -28,13 +28,14 @@ module Precious
def breadcrumb def breadcrumb
path = Pathname.new(@page.url_path).parent path = Pathname.new(@page.url_path).parent
return '' if path.to_s == '.' return '' if path.to_s == '.'
breadcrumb = [] breadcrumb = [%{<nav aria-label="Breadcrumb"><ol>}]
path.descend do |crumb| path.descend do |crumb|
element = "#{crumb.basename}" element = "#{crumb.basename}"
next if element == @page.title next if element == @page.title
breadcrumb << %{<a href="#{overview_path}/#{crumb}/">#{element}</a>} breadcrumb << %{<li class="breadcrumb-item"><a href="#{overview_path}/#{crumb}/">#{element}</a></li>}
end end
breadcrumb.join(' / ') << ' /' breadcrumb << %{</ol></nav>}
breadcrumb.join("\n")
end end
def content def content