guides_style_18f 0.1.13 → 0.1.14
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 +4 -4
- data/README.md +16 -0
- data/lib/guides_style_18f/includes/sidebar-children.html +2 -2
- data/lib/guides_style_18f/includes/sidebar.html +3 -4
- data/lib/guides_style_18f/navigation.rb +99 -86
- data/lib/guides_style_18f/repository.rb +1 -1
- data/lib/guides_style_18f/tags.rb +1 -0
- data/lib/guides_style_18f/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dce17bb3ce830151e80b02ba3d972d29d2d52eaf
|
|
4
|
+
data.tar.gz: 56b84fb06608302738694a29f9a74cb7dade21c2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eb9110487567bca200583b368fc657b7677d70074efa224d08fa475ec9ebf6416a851f185906b1e43e5ab66969dd5f309b8a24e7ac56789c3379b0fb381dbed4
|
|
7
|
+
data.tar.gz: eb7dcebc6877231d7e8d2b1244b00c709f47fc27e53d0f1b77a895241830018a91a36ed8f78744c7dd2fe5dfc31d027d5e9424412cc9bae7212ab90060a3bbae
|
data/README.md
CHANGED
|
@@ -58,6 +58,10 @@ back_link:
|
|
|
58
58
|
|
|
59
59
|
# If you use Analytics, add your code here:
|
|
60
60
|
google_analytics_ua: UA-????????-??
|
|
61
|
+
|
|
62
|
+
# If you want all of the navigation bar entries expanded by default, add this
|
|
63
|
+
# property and it to true:
|
|
64
|
+
expand_nav: true
|
|
61
65
|
```
|
|
62
66
|
|
|
63
67
|
### Additional scripts and styles
|
|
@@ -66,6 +70,18 @@ If you'd like to add additional scripts or styles to every page on the site,
|
|
|
66
70
|
you can add `styles:` and `scripts:` lists to `_config.yml`. To add them to a
|
|
67
71
|
particular page, add these lists to the page's front matter.
|
|
68
72
|
|
|
73
|
+
### Alternate navigation bar titles
|
|
74
|
+
|
|
75
|
+
If you want a page to have a different title in the navigation bar than that
|
|
76
|
+
of the page itself, add a `navtitle:` property to the page's front matter:
|
|
77
|
+
|
|
78
|
+
```md
|
|
79
|
+
---
|
|
80
|
+
title: Since brevity is the soul of wit, I'll be brief.
|
|
81
|
+
navtitle: Polonius's advice
|
|
82
|
+
---
|
|
83
|
+
```
|
|
84
|
+
|
|
69
85
|
### Development
|
|
70
86
|
|
|
71
87
|
First, choose a Jekyll site you'd like to use to view the impact of your
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
aria-hidden="{% if expand_nav == 'true' %}false{% else %}true{% endif %}">
|
|
8
8
|
{% for child in parent.children %}
|
|
9
9
|
{% capture child_url %}{{ parent_url }}{{ child.url }}{% endcapture %}
|
|
10
|
-
<li class="{% if page.
|
|
10
|
+
<li class="{% if page.url == child_url %}sidebar-nav-active{% endif %}">
|
|
11
11
|
<a href="{% if child.internal == true %}{{ site.baseurl }}{{ child_url }}{% else %}{{ child.url }}{% endif %}"
|
|
12
|
-
title="{% if page.
|
|
12
|
+
title="{% if page.url == child_url %}Current Page{% else %}{{ child.text }}{% endif %}">{{ child.text }}</a>
|
|
13
13
|
{% assign parent = child %}{% assign parent_url = child_url %}
|
|
14
14
|
{% guides_style_18f_include sidebar-children.html %}
|
|
15
15
|
{% capture parent_url %}{% guides_style_18f_pop_last_url_component parent_url %}{% endcapture %}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
<aside>
|
|
2
2
|
<p class="intro">{{ site.subtitle }}</p>
|
|
3
3
|
<nav class="sidebar-nav" role="navigation">
|
|
4
|
-
<ul>{% for link in site.navigation %}
|
|
5
|
-
<li class="group {% if page.
|
|
4
|
+
<ul>{% for link in site.navigation %}{% capture parent_url %}/{{ link.url }}{% endcapture %}
|
|
5
|
+
<li class="group {% if page.url == parent_url %}sidebar-nav-active{% endif %}">
|
|
6
6
|
<a href="{% if link.internal == true %}{{ site.baseurl }}/{% endif %}{{ link.url }}"
|
|
7
|
-
title="{% if page.
|
|
7
|
+
title="{% if page.url == parent_url %}Current Page
|
|
8
8
|
{% else %}{{ link.text }}{% endif %}">{{ link.text }}</a>
|
|
9
9
|
{% assign parent = link %}
|
|
10
|
-
{% capture parent_url %}/{{ link.url }}{% endcapture %}
|
|
11
10
|
{% guides_style_18f_include sidebar-children.html %}
|
|
12
11
|
</li>{% endfor %}
|
|
13
12
|
</ul>
|
|
@@ -5,6 +5,8 @@ require 'safe_yaml'
|
|
|
5
5
|
|
|
6
6
|
module GuidesStyle18F
|
|
7
7
|
module FrontMatter
|
|
8
|
+
EXTNAMES = %w(.md .html)
|
|
9
|
+
|
|
8
10
|
def self.load(basedir)
|
|
9
11
|
# init_file_to_front_matter_map is initializing the map with a nil value
|
|
10
12
|
# for every file that _should_ contain front matter as far as the
|
|
@@ -87,7 +89,8 @@ module GuidesStyle18F
|
|
|
87
89
|
Dir.chdir(basedir) do
|
|
88
90
|
pages_dir = Dir.exist?('_pages') ? '_pages' : 'pages'
|
|
89
91
|
Dir[File.join(pages_dir, '**', '*')].each do |file_name|
|
|
90
|
-
|
|
92
|
+
extname = File.extname(file_name)
|
|
93
|
+
next unless File.file?(file_name) && EXTNAMES.include?(extname)
|
|
91
94
|
file_to_front_matter[file_name] = nil
|
|
92
95
|
end
|
|
93
96
|
end
|
|
@@ -119,111 +122,121 @@ module GuidesStyle18F
|
|
|
119
122
|
config_data = SafeYAML.load_file config_path, safe: true
|
|
120
123
|
return unless config_data
|
|
121
124
|
nav_data = config_data['navigation'] || []
|
|
122
|
-
update_navigation_data(nav_data, basedir)
|
|
123
|
-
write_navigation_data_to_config_file(config_path, nav_data)
|
|
125
|
+
NavigationMenu.update_navigation_data(nav_data, basedir)
|
|
126
|
+
NavigationMenu.write_navigation_data_to_config_file(config_path, nav_data)
|
|
124
127
|
end
|
|
125
128
|
|
|
126
129
|
private
|
|
127
130
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
module NavigationMenu
|
|
132
|
+
def self.update_navigation_data(nav_data, basedir)
|
|
133
|
+
original = map_nav_items_by_url('/', nav_data).to_h
|
|
134
|
+
updated = updated_nav_data(basedir)
|
|
135
|
+
remove_stale_nav_entries(nav_data, original, updated)
|
|
136
|
+
updated.map { |url, nav| apply_nav_update(url, nav, nav_data, original) }
|
|
137
|
+
check_for_orphaned_items(nav_data)
|
|
138
|
+
end
|
|
135
139
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
def self.map_nav_items_by_url(parent_url, nav_data)
|
|
141
|
+
nav_data.flat_map do |nav|
|
|
142
|
+
url = File.join('', parent_url, nav['url'] || '')
|
|
143
|
+
[[url, nav]].concat(map_nav_items_by_url(url, nav['children'] || []))
|
|
144
|
+
end
|
|
140
145
|
end
|
|
141
|
-
end
|
|
142
146
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
def self.updated_nav_data(basedir)
|
|
148
|
+
front_matter = FrontMatter.load basedir
|
|
149
|
+
errors = FrontMatter.validate_with_message_upon_error front_matter
|
|
150
|
+
abort errors + "\n_config.yml not updated" if errors
|
|
151
|
+
front_matter.values.sort_by { |fm| fm['permalink'] }
|
|
152
|
+
.map { |fm| [fm['permalink'], page_nav(fm)] }.to_h
|
|
153
|
+
end
|
|
150
154
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
155
|
+
def self.page_nav(front_matter)
|
|
156
|
+
url_components = front_matter['permalink'].split('/')[1..-1]
|
|
157
|
+
result = {
|
|
158
|
+
'text' => front_matter['navtitle'] || front_matter['title'],
|
|
159
|
+
'url' => "#{url_components.nil? ? '' : url_components.last}/",
|
|
160
|
+
'internal' => true,
|
|
161
|
+
}
|
|
162
|
+
# Delete the root URL so we don't have an empty `url:` property laying
|
|
163
|
+
# around.
|
|
164
|
+
result.delete 'url' if result['url'] == '/'
|
|
165
|
+
result
|
|
166
|
+
end
|
|
163
167
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
def self.remove_stale_nav_entries(nav_data, original, updated)
|
|
169
|
+
# Remove old entries whose pages have been deleted
|
|
170
|
+
original.each do |url, nav|
|
|
171
|
+
nav['delete'] = true if !updated.member?(url) && nav['internal']
|
|
172
|
+
end
|
|
173
|
+
original.delete_if { |_url, nav| nav['delete'] }
|
|
174
|
+
nav_data.delete_if { |nav| nav['delete'] }
|
|
175
|
+
nav_data.each { |nav| remove_stale_children(nav) }
|
|
168
176
|
end
|
|
169
|
-
original.delete_if { |_url, nav| nav['delete'] }
|
|
170
|
-
nav_data.delete_if { |nav| nav['delete'] }
|
|
171
|
-
end
|
|
172
177
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
def self.remove_stale_children(parent)
|
|
179
|
+
children = (parent['children'] || [])
|
|
180
|
+
children.delete_if { |nav| nav['delete'] }
|
|
181
|
+
parent.delete 'children' if children.empty?
|
|
182
|
+
children.each { |child| remove_stale_children(child) }
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def self.apply_nav_update(url, nav, nav_data, original)
|
|
186
|
+
orig = original[url]
|
|
187
|
+
if orig.nil?
|
|
188
|
+
apply_new_nav_item(url, nav, nav_data, original)
|
|
189
|
+
else
|
|
190
|
+
orig['text'] = nav['text']
|
|
191
|
+
end
|
|
179
192
|
end
|
|
180
|
-
end
|
|
181
193
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
194
|
+
def self.apply_new_nav_item(url, nav, nav_data, original)
|
|
195
|
+
parent_url = File.dirname(url || '/')
|
|
196
|
+
parent = original["#{parent_url}/"]
|
|
197
|
+
if parent_url == '/'
|
|
198
|
+
nav_data << (original[url] = nav)
|
|
199
|
+
elsif parent.nil?
|
|
200
|
+
nav_data << { orphan_url: url }
|
|
201
|
+
else
|
|
202
|
+
(parent['children'] ||= []) << nav
|
|
203
|
+
end
|
|
191
204
|
end
|
|
192
|
-
end
|
|
193
205
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
206
|
+
def self.check_for_orphaned_items(nav_data)
|
|
207
|
+
orphans = nav_data.map { |nav| nav[:orphan_url] }.compact
|
|
208
|
+
unless orphans.empty?
|
|
209
|
+
fail(StandardError, "Parent pages missing for the following:\n " +
|
|
210
|
+
orphans.join("\n "))
|
|
211
|
+
end
|
|
199
212
|
end
|
|
200
|
-
end
|
|
201
213
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
214
|
+
def self.write_navigation_data_to_config_file(config_path, nav_data)
|
|
215
|
+
lines = []
|
|
216
|
+
in_navigation = false
|
|
217
|
+
open(config_path).each_line do |line|
|
|
218
|
+
in_navigation = process_line line, lines, nav_data, in_navigation
|
|
219
|
+
end
|
|
220
|
+
File.write config_path, lines.join
|
|
207
221
|
end
|
|
208
|
-
File.write config_path, lines.join
|
|
209
|
-
end
|
|
210
222
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
+
def self.process_line(line, lines, nav_data, in_navigation = false)
|
|
224
|
+
if !in_navigation && line.start_with?('navigation:')
|
|
225
|
+
lines << line << format_navigation_section(nav_data)
|
|
226
|
+
in_navigation = true
|
|
227
|
+
elsif in_navigation
|
|
228
|
+
in_navigation = line.start_with?(' ') || line.start_with?('-')
|
|
229
|
+
lines << line unless in_navigation
|
|
230
|
+
else
|
|
231
|
+
lines << line
|
|
232
|
+
end
|
|
233
|
+
in_navigation
|
|
234
|
+
end
|
|
223
235
|
|
|
224
|
-
|
|
236
|
+
YAML_PREFIX = "---\n"
|
|
225
237
|
|
|
226
|
-
|
|
227
|
-
|
|
238
|
+
def self.format_navigation_section(nav_data)
|
|
239
|
+
nav_data.empty? ? '' : nav_data.to_yaml[YAML_PREFIX.size..-1]
|
|
240
|
+
end
|
|
228
241
|
end
|
|
229
242
|
end
|
|
@@ -9,6 +9,7 @@ module GuidesStyle18F
|
|
|
9
9
|
_pages/add-a-new-page.md
|
|
10
10
|
_pages/add-images.md
|
|
11
11
|
_pages/github-setup.md
|
|
12
|
+
_pages/images.png
|
|
12
13
|
_pages/post-your-guide.md
|
|
13
14
|
_pages/update-the-config-file/understanding-baseurl.md
|
|
14
15
|
_pages/update-the-config-file.md
|
|
@@ -19,7 +20,6 @@ module GuidesStyle18F
|
|
|
19
20
|
images/gh-default-branch.png
|
|
20
21
|
images/gh-settings-button.png
|
|
21
22
|
images/gh-webhook.png
|
|
22
|
-
images/images.png
|
|
23
23
|
)
|
|
24
24
|
|
|
25
25
|
def self.clear_template_files_and_create_new_repository(
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: guides_style_18f
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.14
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Bland
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-01-
|
|
11
|
+
date: 2016-01-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: jekyll
|