not-pure-poole 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +10 -0
- data/README.md +198 -0
- data/_includes/content.html +17 -0
- data/_includes/custom-head.html +6 -0
- data/_includes/disqus.html +17 -0
- data/_includes/google-analytics.html +9 -0
- data/_includes/head.html +12 -0
- data/_includes/home-header.html +13 -0
- data/_includes/scroll.html +40 -0
- data/_includes/sidebar-left.html +42 -0
- data/_includes/sidebar-right.html +8 -0
- data/_includes/toc.html +170 -0
- data/_layouts/archive-dates.html +46 -0
- data/_layouts/archive-taxonomies.html +85 -0
- data/_layouts/default.html +41 -0
- data/_layouts/home.html +45 -0
- data/_layouts/page.html +8 -0
- data/_layouts/post.html +49 -0
- data/_sass/_archive.scss +48 -0
- data/_sass/_base.scss +70 -0
- data/_sass/_code.scss +58 -0
- data/_sass/_home-header.scss +29 -0
- data/_sass/_layout.scss +77 -0
- data/_sass/_message.scss +12 -0
- data/_sass/_pagination.scss +52 -0
- data/_sass/_posts.scss +87 -0
- data/_sass/_sidebar.scss +90 -0
- data/_sass/_syntax.scss +65 -0
- data/_sass/_toc.scss +63 -0
- data/_sass/_type.scss +115 -0
- data/_sass/_variables.scss +73 -0
- data/assets/styles.scss +49 -0
- metadata +203 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '09b6f809ab509e351784a2bb691837ae6e5cec9e7cdc00b7546376abdef21936'
|
4
|
+
data.tar.gz: c86dd16b949cc88fc313d11313fa5f1843141c40813a73de9d29be4e4be967d2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9429cc88b6df5c40325ebc14b2a18871416c7741b69717be803651718263c66f4001df33729e29287e4831e619369065e3b0e005ff50df689c67ed1023a6cd7
|
7
|
+
data.tar.gz: d951d22365f4886e6a0ea45bb5fd50c01d64dc357cd8c28e4ae447fa5672864ea7451a07417f1ef6c59ecfabbd6717d07328e4f1bf24d5ab99ef1e8b58e328d9
|
data/LICENSE.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Released under MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2013 Mark Otto.
|
4
|
+
Copyright (c) 2020 Songzi Vong.
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
+
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
9
|
+
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
# Not Pure Poole <!-- omit in toc -->
|
2
|
+
|
3
|
+
**Not Pure Poole** is a simple, beautiful, and powerful Jekyll theme for blogs. It is built on [Poole](https://github.com/poole/poole) and [Pure](https://purecss.io/).
|
4
|
+
|
5
|
+
-----
|
6
|
+
|
7
|
+
See Not Pure Poole in action with [the demo site](https://vszhub.github.io/not-pure-poole/).
|
8
|
+
|
9
|
+
![Screenshot](screenshot.png)
|
10
|
+
|
11
|
+
## Table of Contents <!-- omit in toc -->
|
12
|
+
|
13
|
+
- [Features](#features)
|
14
|
+
- [Installation](#installation)
|
15
|
+
- [Usage](#usage)
|
16
|
+
- [Configuration](#configuration)
|
17
|
+
- [Customizing Head](#customizing-head)
|
18
|
+
- [Creating Themes](#creating-themes)
|
19
|
+
- [Customizing Navigation](#customizing-navigation)
|
20
|
+
- [Customizing Cover Image](#customizing-cover-image)
|
21
|
+
- [Customizing Social Links](#customizing-social-links)
|
22
|
+
- [Enabling Posts Archive](#enabling-posts-archive)
|
23
|
+
- [Enabling TOC](#enabling-toc)
|
24
|
+
- [Something More](#something-more)
|
25
|
+
- [Development](#development)
|
26
|
+
- [License](#license)
|
27
|
+
|
28
|
+
## Features
|
29
|
+
|
30
|
+
- [Jekyll SEO Tag](https://github.com/jekyll/jekyll-seo-tag)
|
31
|
+
- [Jekyll Feed](https://github.com/jekyll/jekyll-feed)
|
32
|
+
- [Jekyll Sitemap](https://github.com/jekyll/jekyll-sitemap)
|
33
|
+
- [Jekyll Gist](https://github.com/jekyll/jekyll-gist)
|
34
|
+
- [Google Analytics](https://analytics.google.com/)
|
35
|
+
- [Disqus](https://disqus.com/)
|
36
|
+
- [Font Awesome](https://fontawesome.com/)
|
37
|
+
- Dark mode (enabled automatically via CSS media query)
|
38
|
+
- Posts archive by dates, categories, and tags
|
39
|
+
- Pagination, generated by [Jekyll Paginate](https://github.com/jekyll/jekyll-paginate)
|
40
|
+
- TOC (generated by Vladimir "allejo" Jimenez's [jekyll-toc](https://github.com/allejo/jekyll-toc))
|
41
|
+
- Related posts (time-based, because Jekyll) below each post
|
42
|
+
- Mobile friendly design and development
|
43
|
+
- Easily scalable text and component sizing with `rem` units in the CSS
|
44
|
+
- Support for a wide gamut of HTML elements
|
45
|
+
- Syntax highlighting, courtesy Pygments (the Python-based code snippet highlighter)
|
46
|
+
|
47
|
+
## Installation
|
48
|
+
|
49
|
+
You can choose one of the following methods to install Not Pure Poole:
|
50
|
+
|
51
|
+
- Directly specify the `not-pure-poole` gem.
|
52
|
+
|
53
|
+
1. Add `gem 'not-pure-poole'` into your `Gemfile`.
|
54
|
+
2. Add the below lines into your `_config.yml`.
|
55
|
+
|
56
|
+
```yml
|
57
|
+
plugins:
|
58
|
+
- not-pure-poole
|
59
|
+
```
|
60
|
+
|
61
|
+
- If your site is hosted on GitHub Pages, you can use [`jekyll-remote-theme`](https://github.com/benbalter/jekyll-remote-theme) to import the master branch of Not Pure Poole.
|
62
|
+
|
63
|
+
1. Add `gem 'jekyll-remote-theme'` into your `Gemfile`.
|
64
|
+
2. Add the below lines into your `_config.yml`.
|
65
|
+
|
66
|
+
```yml
|
67
|
+
plugins:
|
68
|
+
- jekyll-remote-theme
|
69
|
+
|
70
|
+
remote_theme: vszhub/not-pure-poole
|
71
|
+
```
|
72
|
+
|
73
|
+
## Usage
|
74
|
+
|
75
|
+
You can read this [example post](https://vszhub.github.io/not-pure-poole/2020/09/29/welcome-to-not-pure-poole/) to see the rendering result in this theme, and put the [source](_posts/2020-09-29-welcome-to-not-pure-poole.md) aside to learn some basic usages.
|
76
|
+
|
77
|
+
### Configuration
|
78
|
+
|
79
|
+
The [`_config.yml`](_config.yml) file in this repository already contains some variables, you can try to override them in your repository.
|
80
|
+
|
81
|
+
### Customizing Head
|
82
|
+
|
83
|
+
Not Pure Poole leaves a placeholder to allow defining custom head, in principle, you can add anything here, e.g. favicons. All you need to do is just creating a file `_includes/custom-head.html` and put data into it.
|
84
|
+
|
85
|
+
### Creating Themes
|
86
|
+
|
87
|
+
If you want to make your own color schemes, modify the CSS variables in the `_sass/_variables.scss` stylesheet with a scoped data attribute or class name.
|
88
|
+
|
89
|
+
For example, below we've created the beginnings of a blue theme:
|
90
|
+
|
91
|
+
```scss
|
92
|
+
// Example blue theme
|
93
|
+
[data-theme="blue"] {
|
94
|
+
--body-bg: var(--blue);
|
95
|
+
--body-color: #fff;
|
96
|
+
}
|
97
|
+
```
|
98
|
+
|
99
|
+
Then, apply the theme by adding `data-theme="blue"` to the `<html>` element.
|
100
|
+
|
101
|
+
### Customizing Navigation
|
102
|
+
|
103
|
+
You can create a file `_data/navigation.yml` to configure links to some pages. For example,
|
104
|
+
|
105
|
+
```yml
|
106
|
+
- title: Blog
|
107
|
+
url: /
|
108
|
+
- title: About
|
109
|
+
url: /about/
|
110
|
+
```
|
111
|
+
|
112
|
+
### Customizing Cover Image
|
113
|
+
|
114
|
+
You can set your own cover image by modifying the `cover_image` variable in `_config.yml`, and you can also set different cover images on different pages by setting the `cover_image` variable on each page.
|
115
|
+
|
116
|
+
If you discover that the contrast between the cover text color and the cover background color is not enough, you can also adjust these two variables:
|
117
|
+
|
118
|
+
```yml
|
119
|
+
cover_bg_color: rgb(40, 73, 77)
|
120
|
+
cover_color: rgb(255, 255, 255)
|
121
|
+
```
|
122
|
+
|
123
|
+
### Customizing Social Links
|
124
|
+
|
125
|
+
You can set your social links in `_data/social.yml`. You can custom titles, URLs, and icons (only support [Font Awesome](https://fontawesome.com/) currently), for example:
|
126
|
+
|
127
|
+
```yml
|
128
|
+
- title: Email
|
129
|
+
url: mailto://vszhub@gmail.com
|
130
|
+
icon: fas fa-envelope
|
131
|
+
- title: Twitter
|
132
|
+
url: https://twitter.com/vszhub
|
133
|
+
icon: fab fa-twitter
|
134
|
+
- title: GitHub
|
135
|
+
url: https://github.com/vszhub/not-pure-poole
|
136
|
+
icon: fab fa-github
|
137
|
+
```
|
138
|
+
|
139
|
+
### Enabling Posts Archive
|
140
|
+
|
141
|
+
Not Pure Poole supports posts archive by date, categories, and tags. For enabling that, you should put some data like below into `_data/archive.yml`:
|
142
|
+
|
143
|
+
```yml
|
144
|
+
- type: dates
|
145
|
+
title: Dates
|
146
|
+
url: /dates/
|
147
|
+
- type: categories
|
148
|
+
title: Categories
|
149
|
+
url: /categories/
|
150
|
+
- type: tags
|
151
|
+
title: Tags
|
152
|
+
url: /tags/
|
153
|
+
```
|
154
|
+
|
155
|
+
After that, the navigation to these archive pages would be shown on the top of the homepage.
|
156
|
+
|
157
|
+
Then, you can create a category archive page, and set the below parameters on that page:
|
158
|
+
|
159
|
+
```yml
|
160
|
+
---
|
161
|
+
layout: archive-taxonomies
|
162
|
+
type: categories
|
163
|
+
---
|
164
|
+
```
|
165
|
+
|
166
|
+
Or a tag archive page:
|
167
|
+
|
168
|
+
```yml
|
169
|
+
layout: archive-taxonomies
|
170
|
+
type: tags
|
171
|
+
```
|
172
|
+
|
173
|
+
Or archive by dates:
|
174
|
+
|
175
|
+
```yml
|
176
|
+
layout: archive-dates
|
177
|
+
```
|
178
|
+
|
179
|
+
### Enabling TOC
|
180
|
+
|
181
|
+
If you want to show the TOC of a page on the right side, just set `toc: true` on that page.
|
182
|
+
|
183
|
+
### Something More
|
184
|
+
|
185
|
+
Just **hack** into the code and see what you can get.
|
186
|
+
|
187
|
+
## Development
|
188
|
+
|
189
|
+
To set up your environment to develop this theme, run `bundle install`.
|
190
|
+
|
191
|
+
Your theme is setup just like a normal Jekyll site! To test your theme, run `bundle exec jekyll serve` and open your browser at `http://localhost:4000`. This starts a Jekyll server using your theme. Add pages, documents, data, etc. like normal to test your theme's contents. As you make modifications to your theme and to your content, your site will regenerate and you should see the changes in the browser after a refresh, just like normal.
|
192
|
+
|
193
|
+
When your theme is released, only the files in `_layouts`, `_includes`, `_sass` and `assets` tracked with Git will be bundled.
|
194
|
+
To add a custom directory to your theme-gem, please edit the regexp in `not-pure-poole.gemspec` accordingly.
|
195
|
+
|
196
|
+
## License
|
197
|
+
|
198
|
+
The theme is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<main>
|
2
|
+
{{ content }}
|
3
|
+
</main>
|
4
|
+
|
5
|
+
<footer class="footer">
|
6
|
+
{%- assign year_from = site.posts[-1].date | date: '%Y' -%}
|
7
|
+
{%- assign year_to = site.time | date: '%Y' -%}
|
8
|
+
{%- if year_from == nil or year_from == year_to -%}
|
9
|
+
{%- assign year_string = year_from -%}
|
10
|
+
{%- else -%}
|
11
|
+
{%- assign year_string = year_from | append: ' ' | append: '-' | append: ' ' | append: year_to -%}
|
12
|
+
{%- endif -%}
|
13
|
+
<small>
|
14
|
+
© {{ year_string }} {% if site.author %}<a href="{{ site.author.url }}">{{ site.author.name }}</a>{% endif %}. All rights reserved.
|
15
|
+
Powered by <a href="https://jekyllrb.com/">Jekyll</a> & <a href="https://github.com/vszhub/not-pure-poole">Not Pure Poole</a>.
|
16
|
+
</small>
|
17
|
+
</footer>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
{% comment %}
|
2
|
+
Placeholder to allow defining custom head, in principle, you can add anything here, e.g. favicons:
|
3
|
+
|
4
|
+
1. Head over to https://realfavicongenerator.net/ to add your own favicons.
|
5
|
+
2. Customize default _includes/custom-head.html in your source directory and insert the given code snippet.
|
6
|
+
{% endcomment %}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<div id="disqus_thread"></div>
|
2
|
+
<script>
|
3
|
+
var disqus_config = function () {
|
4
|
+
this.page.url = '{{ page.url | absolute_url }}';
|
5
|
+
this.page.identifier = '{{ page.url | absolute_url }}';
|
6
|
+
};
|
7
|
+
|
8
|
+
(function() {
|
9
|
+
var d = document, s = d.createElement('script');
|
10
|
+
|
11
|
+
s.src = 'https://{{ site.disqus }}.disqus.com/embed.js';
|
12
|
+
|
13
|
+
s.setAttribute('data-timestamp', +new Date());
|
14
|
+
(d.head || d.body).appendChild(s);
|
15
|
+
})();
|
16
|
+
</script>
|
17
|
+
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}"></script>
|
2
|
+
<script>
|
3
|
+
window['ga-disable-{{ site.google_analytics }}'] = window.doNotTrack === "1" || navigator.doNotTrack === "1" || navigator.doNotTrack === "yes" || navigator.msDoNotTrack === "1";
|
4
|
+
window.dataLayer = window.dataLayer || [];
|
5
|
+
function gtag(){dataLayer.push(arguments);}
|
6
|
+
gtag('js', new Date());
|
7
|
+
|
8
|
+
gtag('config', '{{ site.google_analytics }}');
|
9
|
+
</script>
|
data/_includes/head.html
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
<head>
|
2
|
+
<meta charset="UTF-8">
|
3
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
4
|
+
<link rel="stylesheet" href="https://unpkg.com/purecss@2.0.3/build/pure-min.css" integrity="sha384-cg6SkqEOCV1NbJoCu11+bm0NvBRc8IYLRGXkmNrqUBfTjmMYwNKPWBTIKyw9mHNJ" crossorigin="anonymous">
|
5
|
+
<link rel="stylesheet" href="https://unpkg.com/purecss@2.0.3/build/grids-responsive-min.css">
|
6
|
+
<link rel="stylesheet" href="{{ 'assets/styles.css' | relative_url }}">
|
7
|
+
|
8
|
+
{%- seo -%}
|
9
|
+
{%- feed_meta -%}
|
10
|
+
|
11
|
+
{%- include custom-head.html -%}
|
12
|
+
</head>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<div class="home-header pure-menu pure-menu-horizontal">
|
2
|
+
<div class="home-header-bar">
|
3
|
+
{% if site.data.archive %}
|
4
|
+
<ul class="home-header-menu pure-menu-list">
|
5
|
+
{% for item in site.data.archive %}
|
6
|
+
<li class="pure-menu-item">
|
7
|
+
<a href="{{ item.url | relative_url }}" class="pure-menu-link {% if page.url == item.url %}current-item{% endif %}"">{{ item.title }}</a>
|
8
|
+
</li>
|
9
|
+
{% endfor %}
|
10
|
+
</ul>
|
11
|
+
{% endif %}
|
12
|
+
</div>
|
13
|
+
</div>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<script>
|
2
|
+
function strip(str, remove) {
|
3
|
+
while (str.length > 0 && remove.indexOf(str.charAt(0)) != -1) {
|
4
|
+
str = str.substr(1);
|
5
|
+
}
|
6
|
+
while (str.length > 0 && remove.indexOf(str.charAt(str.length - 1)) != -1) {
|
7
|
+
str = str.substr(0, str.length - 1);
|
8
|
+
}
|
9
|
+
return str;
|
10
|
+
}
|
11
|
+
|
12
|
+
function scroll() {
|
13
|
+
console.log('scroll');
|
14
|
+
window.scrollTo({
|
15
|
+
left: 0,
|
16
|
+
top: window.innerHeight,
|
17
|
+
behavior: 'smooth'
|
18
|
+
});
|
19
|
+
sessionStorage.removeItem('forceCheckScroll');
|
20
|
+
}
|
21
|
+
|
22
|
+
const forceCheckScroll = sessionStorage.getItem('forceCheckScroll') === 'true';
|
23
|
+
const checkScroll = strip(window.location.pathname, '/') !== strip('{{ site.baseurl }}', '/');
|
24
|
+
|
25
|
+
if (forceCheckScroll || checkScroll) {
|
26
|
+
const maxWidth = "(max-width: 48rem)";
|
27
|
+
const result = window.matchMedia(maxWidth);
|
28
|
+
if (result.matches) {
|
29
|
+
scroll();
|
30
|
+
} else {
|
31
|
+
result.addListener((match) => {
|
32
|
+
if (match.media == maxWidth) {
|
33
|
+
if (match.matches) {
|
34
|
+
scroll();
|
35
|
+
}
|
36
|
+
}
|
37
|
+
});
|
38
|
+
}
|
39
|
+
}
|
40
|
+
</script>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<header class="masthead">
|
2
|
+
{% if site.avatar -%}
|
3
|
+
<div class="avatar">
|
4
|
+
{%- if site.avatar contains "://" -%}
|
5
|
+
{%- assign avatar = site.avatar -%}
|
6
|
+
{%- else -%}
|
7
|
+
{%- assign avatar = site.avatar | relative_url -%}
|
8
|
+
{%- endif -%}
|
9
|
+
<img src="{{ avatar }}" class="avatar-image" alt="{{ site.author.name }}">
|
10
|
+
</div>
|
11
|
+
{%- endif %}
|
12
|
+
<div class="masthead-title">
|
13
|
+
<a href="{{ "/" | relative_url }}" title="Home">{{ site.title }}</a>
|
14
|
+
</div>
|
15
|
+
<div class="masthead-tagline">
|
16
|
+
<small>{{ site.description }}</small>
|
17
|
+
</div>
|
18
|
+
{%- if site.data.navigation -%}
|
19
|
+
<nav class="navigation">
|
20
|
+
<ul class="navigation-list">
|
21
|
+
{%- for nav in site.data.navigation -%}
|
22
|
+
<li class="navigation-item">
|
23
|
+
<a onclick="sessionStorage.setItem('forceCheckScroll', 'true')" href="{{ nav.url | relative_url }}">{{ nav.title | escape }}</a>
|
24
|
+
</li>
|
25
|
+
{%- endfor -%}
|
26
|
+
</ul>
|
27
|
+
</nav>
|
28
|
+
{%- endif -%}
|
29
|
+
{% if site.data.social -%}
|
30
|
+
<div class="social pure-menu pure-menu-horizontal">
|
31
|
+
<ul class="social-icons pure-menu-list">
|
32
|
+
{% for social in site.data.social -%}
|
33
|
+
<li class="pure-menu-item">
|
34
|
+
<a class="social-icon pure-menu-link" href="{{ social.url }}">
|
35
|
+
<i class="{{ social.icon | default: 'fas fa-link' }}" title="{{ social.title }}"></i>
|
36
|
+
</a>
|
37
|
+
</li>
|
38
|
+
{%- endfor %}
|
39
|
+
</ul>
|
40
|
+
</div>
|
41
|
+
{%- endif %}
|
42
|
+
</header>
|
data/_includes/toc.html
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
{% capture tocWorkspace %}
|
2
|
+
{% comment %}
|
3
|
+
Copyright (c) 2017 Vladimir "allejo" Jimenez
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person
|
6
|
+
obtaining a copy of this software and associated documentation
|
7
|
+
files (the "Software"), to deal in the Software without
|
8
|
+
restriction, including without limitation the rights to use,
|
9
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the
|
11
|
+
Software is furnished to do so, subject to the following
|
12
|
+
conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
19
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
21
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
22
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
24
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
{% endcomment %}
|
26
|
+
{% comment %}
|
27
|
+
Version 1.0.14
|
28
|
+
https://github.com/allejo/jekyll-toc
|
29
|
+
|
30
|
+
"...like all things liquid - where there's a will, and ~36 hours to spare, there's usually a/some way" ~jaybe
|
31
|
+
|
32
|
+
Usage:
|
33
|
+
{% include toc.html html=content sanitize=true class="inline_toc" id="my_toc" h_min=2 h_max=3 %}
|
34
|
+
|
35
|
+
Parameters:
|
36
|
+
* html (string) - the HTML of compiled markdown generated by kramdown in Jekyll
|
37
|
+
|
38
|
+
Optional Parameters:
|
39
|
+
* sanitize (bool) : false - when set to true, the headers will be stripped of any HTML in the TOC
|
40
|
+
* class (string) : '' - a CSS class assigned to the TOC
|
41
|
+
* id (string) : '' - an ID to assigned to the TOC
|
42
|
+
* h_min (int) : 1 - the minimum TOC header level to use; any header lower than this value will be ignored
|
43
|
+
* h_max (int) : 6 - the maximum TOC header level to use; any header greater than this value will be ignored
|
44
|
+
* ordered (bool) : false - when set to true, an ordered list will be outputted instead of an unordered list
|
45
|
+
* item_class (string) : '' - add custom class(es) for each list item; has support for '%level%' placeholder, which is the current heading level
|
46
|
+
* submenu_class (string) : '' - add custom class(es) for each child group of headings; has support for '%level%' placeholder which is the current "submenu" heading level
|
47
|
+
* baseurl (string) : '' - add a base url to the TOC links for when your TOC is on another page than the actual content
|
48
|
+
* anchor_class (string) : '' - add custom class(es) for each anchor element
|
49
|
+
* skipNoIDs (bool) : false - skip headers that do not have an `id` attribute
|
50
|
+
|
51
|
+
Output:
|
52
|
+
An ordered or unordered list representing the table of contents of a markdown block. This snippet will only
|
53
|
+
generate the table of contents and will NOT output the markdown given to it
|
54
|
+
{% endcomment %}
|
55
|
+
|
56
|
+
{% capture my_toc %}{% endcapture %}
|
57
|
+
{% assign orderedList = include.ordered | default: false %}
|
58
|
+
{% assign skipNoIDs = include.skipNoIDs | default: false %}
|
59
|
+
{% assign minHeader = include.h_min | default: 1 %}
|
60
|
+
{% assign maxHeader = include.h_max | default: 6 %}
|
61
|
+
{% assign nodes = include.html | split: '<h' %}
|
62
|
+
{% assign firstHeader = true %}
|
63
|
+
{% assign previousLevel = 0 %}
|
64
|
+
|
65
|
+
{% capture listModifier %}{% if orderedList %}1.{% else %}-{% endif %}{% endcapture %}
|
66
|
+
|
67
|
+
{% for node in nodes %}
|
68
|
+
{% if node == "" %}
|
69
|
+
{% continue %}
|
70
|
+
{% endif %}
|
71
|
+
|
72
|
+
{% assign headerLevel = node | replace: '"', '' | slice: 0, 1 | times: 1 %}
|
73
|
+
|
74
|
+
{% if headerLevel < minHeader or headerLevel > maxHeader %}
|
75
|
+
{% continue %}
|
76
|
+
{% endif %}
|
77
|
+
|
78
|
+
{% assign _workspace = node | split: '</h' %}
|
79
|
+
|
80
|
+
{% assign _idWorkspace = _workspace[0] | split: 'id="' %}
|
81
|
+
{% assign _idWorkspace = _idWorkspace[1] | split: '"' %}
|
82
|
+
{% assign html_id = _idWorkspace[0] %}
|
83
|
+
|
84
|
+
{% assign _classWorkspace = _workspace[0] | split: 'class="' %}
|
85
|
+
{% assign _classWorkspace = _classWorkspace[1] | split: '"' %}
|
86
|
+
{% assign html_class = _classWorkspace[0] %}
|
87
|
+
|
88
|
+
{% if html_class contains "no_toc" %}
|
89
|
+
{% continue %}
|
90
|
+
{% endif %}
|
91
|
+
|
92
|
+
{% if firstHeader %}
|
93
|
+
{% assign firstHeader = false %}
|
94
|
+
{% assign minHeader = headerLevel %}
|
95
|
+
{% endif %}
|
96
|
+
|
97
|
+
{% capture _hAttrToStrip %}{{ _workspace[0] | split: '>' | first }}>{% endcapture %}
|
98
|
+
{% assign header = _workspace[0] | replace: _hAttrToStrip, '' %}
|
99
|
+
|
100
|
+
{% assign indentAmount = headerLevel | minus: minHeader %}
|
101
|
+
{% assign space = '' %}
|
102
|
+
{% for i in (1..indentAmount) %}
|
103
|
+
{% assign space = space | prepend: ' ' %}
|
104
|
+
{% endfor %}
|
105
|
+
|
106
|
+
{% if include.item_class and include.item_class != blank %}
|
107
|
+
{% capture listItemClass %}{:.{{ include.item_class | replace: '%level%', headerLevel }}}{% endcapture %}
|
108
|
+
{% endif %}
|
109
|
+
|
110
|
+
{% capture anchor_body %}{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}{% endcapture %}
|
111
|
+
{% capture anchor_body %}{{ anchor_body | replace: "|", "\|" }}{% endcapture %}
|
112
|
+
|
113
|
+
{% if html_id %}
|
114
|
+
{% capture list_item %}[{{ anchor_body }}]({% if include.baseurl %}{{ include.baseurl }}{% endif %}#{{ html_id }}){% endcapture %}
|
115
|
+
{% elsif skipNoIDs == true %}
|
116
|
+
{% continue %}
|
117
|
+
{% else %}
|
118
|
+
{% capture list_item %}{{ anchor_body }}{% endcapture %}
|
119
|
+
{% endif %}
|
120
|
+
|
121
|
+
<!--
|
122
|
+
If we have a submenu class and we're unindenting, then we need to add a "closing" class to this group of bullet
|
123
|
+
points
|
124
|
+
-->
|
125
|
+
{% if include.submenu_class and previousLevel > indentAmount %}
|
126
|
+
<!--
|
127
|
+
`space` is the current indentation, so we if want to close off the previous grouping, we need to add one
|
128
|
+
more level of indentation
|
129
|
+
-->
|
130
|
+
{% assign submenuIndentation = space | prepend: ' ' %}
|
131
|
+
|
132
|
+
{% capture my_toc %}{{ my_toc }}
|
133
|
+
{{ submenuIndentation }}{:.{{ include.submenu_class | replace: '%level%', previousLevel }}}{% endcapture %}
|
134
|
+
{% endif %}
|
135
|
+
|
136
|
+
{% capture my_toc %}{{ my_toc }}
|
137
|
+
{{ space }}{{ listModifier }} {{ listItemClass }} {{ list_item }}{% if include.anchor_class %}{:.{{ include.anchor_class }}}{% endif %}{% endcapture %}
|
138
|
+
|
139
|
+
{% assign previousLevel = indentAmount %}
|
140
|
+
{% endfor %}
|
141
|
+
|
142
|
+
{% if include.class and include.class != blank %}
|
143
|
+
{% capture my_toc %}{:.{{ include.class }}}
|
144
|
+
{{ my_toc | lstrip }}{% endcapture %}
|
145
|
+
{% endif %}
|
146
|
+
|
147
|
+
{% if include.id %}
|
148
|
+
{% capture my_toc %}{: #{{ include.id }}}
|
149
|
+
{{ my_toc | lstrip }}{% endcapture %}
|
150
|
+
{% endif %}
|
151
|
+
|
152
|
+
<!--
|
153
|
+
If we have a submenu class, we need to close off all the remaining list item groups so that submenu classes are
|
154
|
+
applied correctly to them
|
155
|
+
-->
|
156
|
+
{% if include.submenu_class != blank %}
|
157
|
+
<!-- The last level of indentation that we were at, we need to work backwards from there closing each group -->
|
158
|
+
{% for i in (1..previousLevel) %}
|
159
|
+
{% assign lvl = previousLevel | plus: 1 | minus: i %} <!-- Invert the indent level based on `i` -->
|
160
|
+
{% assign closingSpace = '' %}
|
161
|
+
|
162
|
+
{% for i in (1..lvl) %}
|
163
|
+
{% assign closingSpace = closingSpace | prepend: ' ' %}
|
164
|
+
{% endfor %}
|
165
|
+
|
166
|
+
{% capture my_toc %}{{ my_toc }}
|
167
|
+
{{ closingSpace }}{:.{{ include.submenu_class | replace: '%level%', lvl }}}{% endcapture %}
|
168
|
+
{% endfor %}
|
169
|
+
{% endif %}
|
170
|
+
{% endcapture %}{% assign tocWorkspace = '' %}{{ my_toc | markdownify | strip }}
|