jekyll-navigation-tree 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/jekyll-navigation-tree.rb +174 -0
- metadata +44 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 3911b4295f97f6cd8b19b126f758e178d87868ac
|
|
4
|
+
data.tar.gz: 54dfc6104b9e93c010bf706d6bc15bbee43de673
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6b39c08ae79de42a5c88eea4af184be243942ebf98868bfe1ade18c4f229f7c5ffddd09f087a22f9ff1e39d01207fcceb460000abbf15b5cbf24f4c83f3d4bcb
|
|
7
|
+
data.tar.gz: 41f655a2002b61f72b650061cefa72f048ae928cf26223f0642f3780d32205a1290604efa27e16d2b319f22f48852f136ac9ec75c3e611436181f61642d28948
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# For debugging purposes use: pp variable
|
|
2
|
+
require("pp")
|
|
3
|
+
require("awesome_print")
|
|
4
|
+
|
|
5
|
+
# based on https://gist.github.com/brandonmwest/3536551
|
|
6
|
+
|
|
7
|
+
# Usage: {% navigation %}
|
|
8
|
+
# or
|
|
9
|
+
# {% navigation base/path %}
|
|
10
|
+
|
|
11
|
+
module Jekyll
|
|
12
|
+
# Add accessor for directory
|
|
13
|
+
class Page
|
|
14
|
+
attr_reader :dir
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class NavTree < Liquid::Tag
|
|
18
|
+
|
|
19
|
+
def initialize(tag_name, path, tokens)
|
|
20
|
+
super
|
|
21
|
+
@path = path
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def render(context)
|
|
25
|
+
site = context.registers[:site]
|
|
26
|
+
|
|
27
|
+
@page_url = context.environments.first["page"]["url"]
|
|
28
|
+
# @page_url: "/tech/"
|
|
29
|
+
|
|
30
|
+
@dirs = {}
|
|
31
|
+
tree = {}
|
|
32
|
+
|
|
33
|
+
site.pages.each do |page|
|
|
34
|
+
ap page
|
|
35
|
+
if ! page.data.has_key? "nav_tree" || page.data["nav_tree"] == true
|
|
36
|
+
# page: #<Jekyll:Page @name="Motorola-Moto-E-2nd-Gen-XT1524-4G-LTE.md">
|
|
37
|
+
path = page.url
|
|
38
|
+
# path: /tech/hardware/Motorola-Moto-E-2nd-Gen-XT1524-4G-LTE.html
|
|
39
|
+
path = path.index('/') == 0 ? path[1..-1] : path
|
|
40
|
+
|
|
41
|
+
# page.data:
|
|
42
|
+
|
|
43
|
+
# {
|
|
44
|
+
# "layout" => "page",
|
|
45
|
+
# "title" => "About",
|
|
46
|
+
# "permalink" => "/about/"
|
|
47
|
+
# }
|
|
48
|
+
@dirs[path] = page.data
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @dirs:
|
|
53
|
+
|
|
54
|
+
# {
|
|
55
|
+
# "tech/hardware/Motorola-Moto-E-2nd-Gen-XT1524-4G-LTE.html"=>{
|
|
56
|
+
# "title"=>"Motorola Moto E 2nd Gen XT1524 4G LTE"
|
|
57
|
+
# },
|
|
58
|
+
# "about/ "=> {
|
|
59
|
+
# "layout"=>"page",
|
|
60
|
+
# "title"=>"About",
|
|
61
|
+
# "permalink"=>"/about/"
|
|
62
|
+
# },
|
|
63
|
+
# "tech/commands/adb.html"=>{
|
|
64
|
+
# "title"=>"adb (Android Debug Bridge)"
|
|
65
|
+
# },
|
|
66
|
+
# "tech/websites/lrz-seite-2003/"=>{
|
|
67
|
+
# "title"=>"LRZ-Seite (2003)"
|
|
68
|
+
# },
|
|
69
|
+
# }
|
|
70
|
+
|
|
71
|
+
@dirs.each do |path, data|
|
|
72
|
+
current = tree
|
|
73
|
+
path.split("/").inject("") do |sub_path, dir|
|
|
74
|
+
sub_path = File.join(sub_path, dir)
|
|
75
|
+
|
|
76
|
+
current[sub_path] ||= {}
|
|
77
|
+
current = current[sub_path]
|
|
78
|
+
sub_path
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
puts "generating nav tree for #{@page_url}"
|
|
83
|
+
|
|
84
|
+
# tree:
|
|
85
|
+
# {"/tech"=>
|
|
86
|
+
# {"/tech/hardware"=>
|
|
87
|
+
# {"/tech/hardware/Motorola-Moto-E-2nd-Gen-XT1524-4G-LTE.html"=>{},
|
|
88
|
+
# "/tech/hardware/banana-pi-pro.html"=>{},
|
|
89
|
+
# "/tech/hardware/brother-hl-5350dn.html"=>{},
|
|
90
|
+
if @path == nil || @path == ""
|
|
91
|
+
base_path = @page_url.chomp('/')
|
|
92
|
+
else
|
|
93
|
+
base_path = @path.strip.chomp('/')
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
if base_path == ""
|
|
97
|
+
sub_tree = tree
|
|
98
|
+
else
|
|
99
|
+
if base_path.index('/') != 0
|
|
100
|
+
base_path = '/' + base_path
|
|
101
|
+
end
|
|
102
|
+
sub_tree = tree[base_path]
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
files_first_traverse("", sub_tree)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def files_first_traverse(prefix, node = {})
|
|
109
|
+
output = ""
|
|
110
|
+
output += "#{prefix}<ul>"
|
|
111
|
+
node_list = node.sort
|
|
112
|
+
|
|
113
|
+
# node_list:
|
|
114
|
+
|
|
115
|
+
# [["/about", {}],
|
|
116
|
+
# ["/assets", {"/assets/main.css"=>{}}],
|
|
117
|
+
# ["/feed.xml", {}],
|
|
118
|
+
# ["/imprint", {}],
|
|
119
|
+
# ["/mixing",
|
|
120
|
+
# {"/mixing/defaults.html"=>{},
|
|
121
|
+
# "/mixing/shure-beta-58a.html"=>{},
|
|
122
|
+
# "/mixing/shure-ulx.html"=>{},
|
|
123
|
+
# "/mixing/t-bone-free-solo-pt-823-mhz.html"=>{}}],
|
|
124
|
+
# ["/rezepte",
|
|
125
|
+
# {"/rezepte/fleisch"=>
|
|
126
|
+
# {"/rezepte/fleisch/amerikanisches-rindersteak.html"=>{},
|
|
127
|
+
# "/rezepte/fleisch/chili-con-carne.html"=>{},
|
|
128
|
+
# "/rezepte/fleisch/fleischpfanzerl.html"=>{},
|
|
129
|
+
|
|
130
|
+
node_list.each do |base, subtree|
|
|
131
|
+
# base: "/about"
|
|
132
|
+
name = base[1..-1]
|
|
133
|
+
# name: "about"
|
|
134
|
+
if name.index('.html')
|
|
135
|
+
name = @dirs[name]["title"] || name
|
|
136
|
+
# e. g.: "tech/websites/lrz/index.html" => is "tech/websites/lrz/"
|
|
137
|
+
# in @dirs hash.
|
|
138
|
+
elsif @dirs.has_key? name + "/"
|
|
139
|
+
name = @dirs[name + "/"]["title"] || name
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
output += "#{prefix} <li><a href=\"#{base}\">#{name}</a></li>" if subtree.empty?
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
node_list.each do |base, subtree|
|
|
146
|
+
next if subtree.empty?
|
|
147
|
+
name = base[1..-1]
|
|
148
|
+
# name: "tech/commands"
|
|
149
|
+
if @dirs.has_key? name + '/'
|
|
150
|
+
href = base
|
|
151
|
+
name = @dirs[name + '/']['title'] || name
|
|
152
|
+
elsif name.index('/')
|
|
153
|
+
name = name[name.rindex('/')+1..-1] || name
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
if href
|
|
157
|
+
name_link = "<a href=\"#{base}\">#{name}</a>"
|
|
158
|
+
else
|
|
159
|
+
name_link = "<div class=\"subtree-name\">#{name}</div>"
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
output += "#{prefix} <li>#{name_link}"
|
|
163
|
+
output += files_first_traverse(prefix + ' ', subtree)
|
|
164
|
+
output+= "</li>"
|
|
165
|
+
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
output += "#{prefix} </ul>"
|
|
169
|
+
output
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
Liquid::Template.register_tag("navigation", Jekyll::NavTree)
|
metadata
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jekyll-navigation-tree
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Josef Friedrich
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-03-21 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A jekyll plugin for building hierarchial navigation trees from pages.
|
|
14
|
+
email: josef@friedrich.rocks
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/jekyll-navigation-tree.rb
|
|
20
|
+
homepage: https://github.com/Josef-Friedrich/jekyll-navigation-tree
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubyforge_project:
|
|
40
|
+
rubygems_version: 2.5.1
|
|
41
|
+
signing_key:
|
|
42
|
+
specification_version: 4
|
|
43
|
+
summary: Hierachial navigation trees
|
|
44
|
+
test_files: []
|