-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathbreadcrumbs.rb
37 lines (32 loc) · 1.1 KB
/
breadcrumbs.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Jekyll::Hooks.register :pages, :pre_render do |page, payload|
drop = Drops::BreadcrumbItem
if page.url == "/"
then payload["breadcrumbs"] = [
drop.new(page, payload)
]
else
payload["breadcrumbs"] = []
pth = page.url.split("/")
0.upto(pth.size - 1) do |int|
joined_path = pth[0..int].join("/")
item = page.site.pages.find { |page_| joined_path == "" && page_.url == "/" || page_.url.chomp("/") == joined_path }
payload["breadcrumbs"] << drop.new(item, payload) if item
end
end
end
Jekyll::Hooks.register :documents, :pre_render do |documents, payload|
drop = Drops::BreadcrumbItem
if documents.url == "/"
then payload["breadcrumbs"] = [
drop.new(documents, payload)
]
else
payload["breadcrumbs"] = []
pth = documents.url.split("/")
0.upto(pth.size - 1) do |int|
joined_path = pth[0..int].join("/")
item = documents.site.documents.find { |documents| joined_path == "" && documents.url == "/" || documents.url.chomp("/") == joined_path }
payload["breadcrumbs"] << drop.new(item, payload) if item
end
end
end