Skip to content

Commit b40c280

Browse files
author
Misty Stanley-Jones
authored
Merge pull request docker#1842 from mstanleyjones/allow_h1_in_toc
Allow h1 in in-page toc
2 parents fec6553 + e96b5ce commit b40c280

File tree

3 files changed

+55
-13
lines changed

3 files changed

+55
-13
lines changed

README.md

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,23 @@ You have three options:
136136
docker-compose down
137137
```
138138
139-
2. Use Jekyll directly.
139+
2. Use Jekyll directly.
140140
141141
a. Clone this repo by running:
142142
143143
```bash
144144
git clone https://github.com/docker/docker.github.io.git
145145
```
146-
146+
147147
b. Install Ruby 2.3 or later as described in [Installing Ruby]
148148
(https://www.ruby-lang.org/en/documentation/installation/).
149-
149+
150150
c. Install Bundler:
151151
152152
```bash
153153
gem install bundler
154154
```
155-
155+
156156
d. If you use Ubuntu, install packages required for the Nokogiri HTML
157157
parser:
158158
@@ -165,7 +165,7 @@ You have three options:
165165
```bash
166166
bundle install
167167
```
168-
168+
169169
>**Note**: You may have to install some packages manually.
170170
171171
f. Change the directory to `docker.github.io`.
@@ -203,12 +203,43 @@ guidance about grammar, syntax, formatting, styling, language, or tone. If
203203
something isn't clear in the guide, please submit an issue to let us know or
204204
submit a pull request to help us improve it.
205205
206-
### Generate the man pages
207-
208-
For information on generating man pages (short for manual page), see the README.md
209-
document in [the man page directory](https://github.com/docker/docker/tree/master/man)
210-
in this project.
206+
### Per-page front-matter
207+
208+
The front-matter of a given page is in a section at the top of the Markdown
209+
file that starts and ends with three hyphens. It includes YAML content. The
210+
following keys are supported. The title, description, and keywords are required.
211+
212+
| Key | Required | Description |
213+
|------------------------|-----------|-----------------------------------------|
214+
| title | yes | The page title. This is added to the HTML output as a `<h1>` level header. |
215+
| description | yes | A sentence that describes the page contents. This is added to the HTML metadata. |
216+
| keywords | yes | A comma-separated list of keywords. These are added to the HTML metadata. |
217+
| redirect_from | no | A YAML list of pages which should redirect to THIS page. At build time, each page listed here is created as a HTML stub containing a 302 redirect to this page. |
218+
| notoc | no | Either `true` or `false`. If `true`, no in-page TOC is generated for the HTML output of this page. Defaults to `false`. Appropriate for some landing pages that have no in-page headings.|
219+
| toc_min | no | Ignored if `notoc` is set to `true`. The minimum heading level included in the in-page TOC. Defaults to `2`, to show `<h2>` headings as the minimum. |
220+
| toc_max | no | Ignored if `notoc` is set to `false`. The maximum heading level included in the in-page TOC. Defaults to `3`, to show `<h3>` headings. Set to the same as `toc_min` to only show `toc_min` level of headings. |
221+
| tree | no | Either `true` or `false`. Set to `false` to disable the left-hand site-wide navigation for this page. Appropriate for some pages like the search page or the 404 page. |
222+
| no_ratings | no | Either `true` or `false`. Set to `true` to disable the page-ratings applet for this page. Defaults to `false`. |
223+
224+
The following is an example of valid (but contrived) page metadata. The order of
225+
the metadata elements in the front-matter is not important.
226+
227+
```liquid
228+
---
229+
description: Instructions for installing Docker on Ubuntu
230+
keywords: requirements, apt, installation, ubuntu, install, uninstall, upgrade, update
231+
redirect_from:
232+
- /engine/installation/ubuntulinux/
233+
- /installation/ubuntulinux/
234+
- /engine/installation/linux/ubuntulinux/
235+
title: Get Docker for Ubuntu
236+
toc_min: 1
237+
toc_max: 6
238+
tree: false
239+
no_ratings: true
240+
---
241+
```
211242
212243
## Copyright and license
213244
214-
Code and documentation copyright 2016 Docker, inc, released under the Apache 2.0 license.
245+
Code and documentation copyright 2017 Docker, inc, released under the Apache 2.0 license.

_includes/toc_pure_liquid.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
{% assign html_id = _idWorkspace[1] %}
4646

4747
{% capture _hAttrToStrip %}{{ headerLevel }} id="{{ html_id }}">{% endcapture %}
48-
{% assign header = _workspace[0] | replace: _hAttrToStrip, '' %}
48+
{% assign header = _workspace[0] | replace: _hAttrToStrip, '' | remove_first: "1>" %}
4949

5050
{% assign space = '' %}
5151
{% for i in (1..indentAmount) %}

_layouts/docs.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,19 @@
289289
{% assign my_min = page.toc_min | default: site.toc_min | default: 2 %}
290290
{% assign my_max = page.toc_max | default: site.toc_max | default: 3 %}
291291
{% assign my_name = page.url | default: "unnamed" %}
292-
<div id="side-toc"><div id="side-toc-title">On this page:</div><div id="side-toc-contents">{% include toc_pure_liquid.html html=content sanitize=true class="inline_toc" id="my_toc" toc_min=my_min toc_max=my_max page_name=my_name %}</div></div>
292+
{% if my_min < 2 %}
293+
{% comment %}
294+
the 'content' variable doesn't include the <h1> by default
295+
so if we request the h1 heading to be in the in-page TOC,
296+
append it to the content before we pass it to the TOC generator
297+
{% endcomment %}
298+
{% assign my_content = "<h1>" | append: page.title | append: "</h1>" | append: content %}
299+
{% else %}
300+
{% assign my_content = content %}
301+
{% endif %}
302+
<div id="side-toc"><div id="side-toc-title">On this page:</div><div id="side-toc-contents">{% include toc_pure_liquid.html html=my_content sanitize=true class="inline_toc" id="my_toc" toc_min=my_min toc_max=my_max page_name=my_name %}</div></div>
293303
{% endunless %}
304+
<div>{{content}}</div>
294305
</section>
295306
</div>
296307
</div>

0 commit comments

Comments
 (0)