Skip to content

Commit

Permalink
Rip out the old JS TOC generator and use liquid instead (#1909)
Browse files Browse the repository at this point in the history
* Switch to liquid toc

* Remove old TOC div

* Improve formatting slightly

* No TOC in legal

* Minor fixes

* Docs :-D

* Add anchors

* Also on Enterprise

* Test the lang block

* Update class name to use list language style

* Fix language aside block

* Only show H2 in toc

* Dont include html in toc heading

* Dont need this

* Use the same for Enterprise and hosted
  • Loading branch information
plaindocs authored Jul 25, 2018
1 parent 471da1c commit 429e9d3
Show file tree
Hide file tree
Showing 81 changed files with 304 additions and 150 deletions.
1 change: 0 additions & 1 deletion 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@
</style>
<link rel="alternate" type="application/rss+xml" title="Travis CI Build Environment Updates" href="http://docs.travis-ci.com/feed.build-env-updates.xml">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" defer></script>
<script src="{{ site.baseurl }}/assets/javascripts/site.js" type="text/javascript" charset="utf-8" defer></script>
<script src="{{ site.baseurl }}/assets/javascripts/main.js" type="text/javascript" charset="utf-8" defer></script>
<script type="text/javascript">
var _gaq = _gaq || [];
Expand Down
8 changes: 3 additions & 5 deletions STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ If you have long lists you can wrap them into 2 (`.column-2`) or 3 (`.column-3`)
{: .column-2 }
```

### TOC
#### In-page table of contents

Add a table of contents to a page with the following HTML snippet:
All pages have tables of contents generated automatically from H2 and H3

```html
<div id="toc"></div>
```
To remove the TOC from a page add `no_toc: true` to the frontmatter.

### Beta features

Expand Down
86 changes: 86 additions & 0 deletions _includes/anchor_headings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{% capture headingsWorkspace %}
{% comment %}
Version 1.0.0-RC3
https://github.com/allejo/jekyll-headings

"Be the pull request you wish to see in the world." ~Ben Balter

Usage:
{% include anchor_headings.html html=content %}

Parameters:
* html (string) - the HTML of compiled markdown generated by kramdown in Jekyll

Optional Parameters:
* beforeHeading (bool) : false - Set to true if the anchor should be placed _before_ the heading's content
* anchorBody (string) : '' - The content that will be placed inside the anchor; the `%heading%` placeholder is available
* anchorClass (string) : '' - The class(es) that will be used for each anchor. Separate multiple classes with a space
* anchorTitle (string) : '' - The `title` attribute that will be used for anchors

Output:
The original HTML with the addition of anchors inside of all of the h1-h6 headings.
{% endcomment %}

{% assign beforeHeading = include.beforeHeading %}
{% assign nodes = include.html | split: '<h' %}
{% assign nodeCount = nodes | size %}

{% capture edited_headings %}{% endcapture %}

<!-- If nodeCount is less than 2, that means there were no headings -->
{% if nodeCount >= 2 %}
{% for node in nodes %}
{% if node == "" %}
{% continue %}
{% endif %}

{% assign headerLevel = node | replace: '"', '' | slice: 0, 1 | times: 1 %}

{% if headerLevel < 1 or headerLevel > 6 %}
{% continue %}
{% endif %}

{% assign _workspace = node | split: '</h' %}
{% assign _idWorkspace = _workspace[0] | split: 'id="' %}
{% assign _idWorkspace = _idWorkspace[1] | split: '"' %}
{% assign html_id = _idWorkspace[0] %}

{% capture _hAttrToStrip %}{{ _workspace[0] | split: '>' | first }}>{% endcapture %}
{% assign header = _workspace[0] | replace: _hAttrToStrip, '' %}

<!-- Build the anchor to inject for our heading -->
{% capture anchor %}{% endcapture %}

{% if html_id %}
{% capture anchor %}href="#{{ html_id}}"{% endcapture %}

{% if include.anchorClass %}
{% capture anchor %}{{ anchor }} class="{{ include.anchorClass }}"{% endcapture %}
{% endif %}

{% if include.anchorTitle %}
{% capture anchor %}{{ anchor }} title="{{ include.anchorTitle | replace: '%heading%', header }}"{% endcapture %}
{% endif %}

{% capture anchor %}<a {{ anchor }}>{{ include.anchorBody | replace: '%heading%', header | default: '' | raw }}</a>{% endcapture %}

{% if beforeHeading %}
{% capture anchor %}{{ anchor }} {% endcapture %}
{% else %}
{% capture anchor %} {{ anchor }}{% endcapture %}
{% endif %}
{% endif %}

<!-- The placement of our anchor, before the heading content or after -->
{% if beforeHeading %}
{% capture _current %}<h{{ _hAttrToStrip | raw }}{{ anchor }}{% endcapture %}
{% capture edited_headings %}{{ edited_headings }}{{ node | replace: _hAttrToStrip, _current | raw }}{% endcapture %}
{% else %}
{% capture _current %}<h{{ _workspace | first }}{{ anchor }}</h{{ _workspace | last }}{% endcapture %}
{% capture edited_headings %}{{ edited_headings }}{{ _current }}{% endcapture %}
{% endif %}
{% endfor %}
{% else %}
{% capture edited_headings %}{{ include.html }}{% endcapture %}
{% endif %}
{% endcapture %}{% assign headingsWorkspace = '' %}{{ edited_headings | strip }}
4 changes: 1 addition & 3 deletions _includes/conditional_deploy.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3>Conditional Deploys</h3>
<h3 id="conditional-deploys">Conditional Deploys</h3>

<p>It is possible to make deployments conditional using the <strong>on</strong> option:</p>

Expand Down Expand Up @@ -40,5 +40,3 @@ <h3>Conditional Deploys</h3>
<li><strong>ruby</strong> - Ruby version to deploy from if passing</li>
<li><strong>repo</strong> - only trigger a build for the given repository, to play nice with forks</li>
</ul>


2 changes: 1 addition & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<link rel="stylesheet" href="{{ "/assets/stylesheets/main.css" | prepend: site.baseurl }}">
<link rel="alternate" type="application/rss+xml" title="Travis CI Build Environment Updates" href="http://docs.travis-ci.com/feed.build-env-updates.xml">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" defer></script>
<script src="{{ "/assets/javascripts/site.js" | prepend: site.baseurl }}" type="text/javascript" charset="utf-8" defer></script>

<script src="{{ "/assets/javascripts/main.js" | prepend: site.baseurl }}" type="text/javascript" charset="utf-8" defer></script>
<script src="{{ "/assets/javascripts/prism.js" | prepend: site.baseurl }}" type="text/javascript" charset="utf-8" defer></script>

Expand Down
85 changes: 85 additions & 0 deletions _includes/toc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{% capture tocWorkspace %}
{% comment %}
Version 1.0.4
https://github.com/allejo/jekyll-toc

"...like all things liquid - where there's a will, and ~36 hours to spare, there's usually a/some way" ~jaybe

Usage:
{% include toc.html html=content sanitize=true class="inline_toc" id="my_toc" h_min=2 h_max=3 %}

Parameters:
* html (string) - the HTML of compiled markdown generated by kramdown in Jekyll

Optional Parameters:
* sanitize (bool) : false - when set to true, the headers will be stripped of any HTML in the TOC
* class (string) : '' - a CSS class assigned to the TOC
* id (string) : '' - an ID to assigned to the TOC
* h_min (int) : 1 - the minimum TOC header level to use; any header lower than this value will be ignored
* h_max (int) : 6 - the maximum TOC header level to use; any header greater than this value will be ignored
* ordered (bool) : false - when set to true, an ordered list will be outputted instead of an unordered list
* item_class (string) : '' - add custom class for each list item; has support for '%level%' placeholder, which is the current heading level

Output:
An ordered or unordered list representing the table of contents of a markdown block. This snippet will only generate the table of contents and will NOT output the markdown given to it
{% endcomment %}

{% capture my_toc %}{% endcapture %}
{% assign orderedList = include.ordered | default: false %}
{% assign minHeader = include.h_min | default: 1 %}
{% assign maxHeader = include.h_max | default: 6 %}
{% assign nodes = include.html | split: '<h' %}
{% assign firstHeader = true %}

{% capture listModifier %}{% if orderedList %}1.{% else %}-{% endif %}{% endcapture %}

{% for node in nodes %}
{% if node == "" %}
{% continue %}
{% endif %}

{% assign headerLevel = node | replace: '"', '' | slice: 0, 1 | times: 1 %}

{% if headerLevel < minHeader or headerLevel > maxHeader %}
{% continue %}
{% endif %}

{% if firstHeader %}
{% assign firstHeader = false %}
{% assign minHeader = headerLevel %}
{% endif %}

{% assign indentAmount = headerLevel | minus: minHeader | add: 1 %}
{% assign _workspace = node | split: '</h' %}

{% assign _idWorkspace = _workspace[0] | split: 'id="' %}
{% assign _idWorkspace = _idWorkspace[1] | split: '"' %}
{% assign html_id = _idWorkspace[0] %}

{% capture _hAttrToStrip %}{{ _workspace[0] | split: '>' | first }}>{% endcapture %}
{% assign header = _workspace[0] | replace: _hAttrToStrip, '' %}

{% assign space = '' %}
{% for i in (1..indentAmount) %}
{% assign space = space | prepend: ' ' %}
{% endfor %}

{% unless include.item_class == blank %}
{% capture listItemClass %}{:.{{ include.item_class | replace: '%level%', headerLevel }}}{% endcapture %}
{% endunless %}

{% capture my_toc %}{{ my_toc }}
{{ space }}{{ listModifier }} {{ listItemClass }} [{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}](#{{ html_id }}){% endcapture %}

{% endfor %}

{% if include.class %}
{% capture my_toc %}{:.{{ include.class }}}
{{ my_toc | lstrip }}{% endcapture %}
{% endif %}

{% if include.id %}
{% capture my_toc %}{: #{{ include.id }}}
{{ my_toc | lstrip }}{% endcapture %}
{% endif %}
{% endcapture %}{% assign tocWorkspace = '' %}{{ my_toc | markdownify | strip }}
10 changes: 9 additions & 1 deletion _layouts/en.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
<aside class="improve-page" data-swiftype-index='false'><a href="{{ site.docs_github }}edit/master/{{ page.path }}" target="_blank" title="Edit this page on GitHub" class="button-pen" data-proofer-ignore>Improve this page on GitHub</a></aside>
<h1 class="title">{{ page.title }}</h1>
{% endunless %}
{{ content }}

{% unless page.no_toc %}
<div id="toc" class="toc">
{% include toc.html h_min=2 h_max=2 class="list-language" santize=true html=content %}
</div>
{% endunless%}

{% include anchor_headings.html html=content anchorClass="toc-anchor" anchorBody="#" %}

</main>
</div><!-- /#content -->

Expand Down
10 changes: 9 additions & 1 deletion _layouts/en_enterprise.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
<aside class="improve-page"><a href="{{ site.docs_github }}edit/master/{{ page.path }}" target="_blank" title="Edit this page on GitHub" class="button-pen" data-proofer-ignore>Improve this page on GitHub</a></aside>
<h1 class="title">{{ page.title }}</h1>
{% endunless %}
{{ content }}

{% unless page.no_toc %}
<div id="toc" class="toc">
{% include toc.html h_min=2 h_max=2 class="list-language" santize=true html=content %}
</div>
{% endunless%}

{% include anchor_headings.html html=content anchorClass="toc-anchor" anchorBody="#" %}

</main>
</div><!-- /#content -->

Expand Down
24 changes: 0 additions & 24 deletions assets/javascripts/site.js

This file was deleted.

1 change: 0 additions & 1 deletion assets/stylesheets/_ataglance.sass
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
border: solid 2px $pebble-grey
border-radius: 2px
padding: 0.5em 1em
margin-top: 2em

@media #{$medium-up}
float: right
Expand Down
1 change: 1 addition & 0 deletions imprint.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
layout: en
title: Imprint
permalink: /imprint.html
no_toc: true
---

<article id="imprint">
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
layout: en
permalink: /
no_header: true
no_toc: true
short_title: true
---

Expand Down
3 changes: 1 addition & 2 deletions legal/data-processing-agreement.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Data Processing Agreement
layout: en

no_toc: true
---

## Between
Expand Down Expand Up @@ -142,4 +142,3 @@ The list shall state the extent, the nature and purpose of any contemplated coll

2. Organizational provision on processing
- Travis-CI maintains a system to examine, assess, and evaluate regularly the effectivity of the security of processing data. Travis-CI will, on request, provide details on such security measures. Travis-CI will also, on request, prove such system of evaluation to the Client.

Loading

0 comments on commit 429e9d3

Please sign in to comment.