jekyll_outline 1.0.2 → 1.1.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 +4 -4
- data/.rubocop.yml +6 -3
- data/CHANGELOG.md +10 -1
- data/README.md +126 -18
- data/demo/assets/js/jekyll_outline.js +31 -0
- data/jekyll_outline.gemspec +7 -4
- data/lib/jekyll_outline/version.rb +1 -1
- data/lib/jekyll_outline.rb +4 -109
- data/lib/outline_js.rb +40 -0
- data/lib/outline_tag.rb +135 -0
- data/spec/status_persistence.txt +3 -0
- metadata +13 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 464b66396b0abd3369669875ca6b2be97b51e7823e31d5fa163b4248afc0dc50
|
4
|
+
data.tar.gz: 1253ef8b8218d0c4f76cb66d5f79ef0bc4fef48cec8d057ef33b0af0411e352f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96bf42bd9e24050bf05fc9c5d1a2094383f2dd3853c301da97ce5e8276969de31ddc98cc5102f3288e46cb84ae9032a2e8c40813993445d837a5a60ffd4b0559
|
7
|
+
data.tar.gz: 56facfe2c9305b0945ad1d315018b078f1a0402b1c91655ea01a2741f9f39d2975bce5de31eb84490126f4b19700e98a617a84d61a17fbc27a225cc750b941ba
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require:
|
2
|
-
- rubocop-
|
2
|
+
- rubocop-md
|
3
|
+
- rubocop-performance
|
3
4
|
- rubocop-rake
|
5
|
+
- rubocop-rspec
|
4
6
|
|
5
7
|
AllCops:
|
6
8
|
Exclude:
|
@@ -17,7 +19,8 @@ Gemspec/RequireMFA:
|
|
17
19
|
Enabled: false
|
18
20
|
|
19
21
|
Layout/HashAlignment:
|
20
|
-
|
22
|
+
EnforcedColonStyle: table
|
23
|
+
EnforcedHashRocketStyle: table
|
21
24
|
|
22
25
|
Layout/LineLength:
|
23
26
|
Max: 150
|
@@ -25,7 +28,7 @@ Layout/LineLength:
|
|
25
28
|
Metrics/BlockLength:
|
26
29
|
Exclude:
|
27
30
|
- jekyll_outline.gemspec
|
28
|
-
Max:
|
31
|
+
Max: 40
|
29
32
|
|
30
33
|
Metrics/MethodLength:
|
31
34
|
Max: 30
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 1.1.1 / 2023-04-02
|
2
|
+
* Added [`attribution` support](https://github.com/mslinn/jekyll_plugin_support#subclass-attribution).
|
3
|
+
|
4
|
+
## 1.1.0 / 2023-03-14
|
5
|
+
* `outline_js` tag added, for including Javascript necessary to position images relating to the outline.
|
6
|
+
* Now generates a series of divs, instead of one big div.
|
7
|
+
* Now interprets numbers as decimal instead of octal.
|
8
|
+
* CSS documented and new `post_title` class defined.
|
9
|
+
|
1
10
|
## 1.0.2 / 2023-02-16
|
2
11
|
* Updated to `jekyll_plugin_support` v0.5.1
|
3
12
|
|
@@ -5,4 +14,4 @@
|
|
5
14
|
* Now dependent upon `jekyll_plugin_support`
|
6
15
|
|
7
16
|
## 1.0.0 / 2022-04-02
|
8
|
-
* Initial version
|
17
|
+
* Initial version, this Jekyll plugin defines a block tag called `outline`.
|
data/README.md
CHANGED
@@ -6,11 +6,12 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
## Installation
|
9
|
-
|
10
|
-
Add this line to your application's Gemfile:
|
9
|
+
Add the following line to your Jekyll project's Gemfile, within the `jekyll_plugins` group:
|
11
10
|
|
12
11
|
```ruby
|
13
|
-
|
12
|
+
group :jekyll_plugins do
|
13
|
+
gem 'jekyll_outline'
|
14
|
+
end
|
14
15
|
```
|
15
16
|
|
16
17
|
And then execute:
|
@@ -18,21 +19,118 @@ And then execute:
|
|
18
19
|
$ bundle install
|
19
20
|
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
### CSS
|
23
|
+
The CSS used for the demo website should be copied to your project.
|
24
|
+
See the section of `demo/assets/css/styles.css` as shown:
|
24
25
|
|
26
|
+
```css
|
27
|
+
/* Start of jekyll_outline css */
|
28
|
+
... copy this portion ...
|
29
|
+
/* End of jekyll_outline css */
|
30
|
+
```
|
25
31
|
|
26
|
-
|
32
|
+
### JavaScript
|
33
|
+
This project's `outline_js` tag returns the Javascript necessary to position images relating to the outline. If used without parameters it just returns the JavaScript:
|
34
|
+
|
35
|
+
```html
|
36
|
+
<script>
|
37
|
+
{%= outline_js %}
|
38
|
+
</script>
|
39
|
+
```
|
27
40
|
|
28
|
-
|
29
|
-
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
41
|
+
If passed the `wrap_in_script_tag` parameter, it wraps the JavaScript in `<script></script>`:
|
30
42
|
|
31
|
-
|
43
|
+
```html
|
44
|
+
{% outline_js wrap_in_script_tag %}
|
32
45
|
```
|
33
|
-
|
46
|
+
|
47
|
+
|
48
|
+
## Explanation
|
49
|
+
Given an outline that looks like this:
|
50
|
+
```html
|
51
|
+
{% outline stuff %}
|
52
|
+
000: Topic 0..19
|
53
|
+
020: Topic 20..39
|
54
|
+
040: Topic 40..
|
55
|
+
{% endoutline %}
|
56
|
+
```
|
57
|
+
|
58
|
+
...and given pages in the `stuff` collection with the following names:
|
59
|
+
|
60
|
+
- 010-published.html has title **Published Stuff Post 010**
|
61
|
+
- 020-unpublished.html has title **Unpublished Post 020**
|
62
|
+
- 030-unpublished.html has title **Unpublished Post 030**
|
63
|
+
|
64
|
+
Then links to the pages in the `stuff` collection's pages are interleaved into the generated outline like this:
|
65
|
+
```html
|
66
|
+
<div class="outer_posts">
|
67
|
+
<h3 class='post_title clear' id="title_0">Topic 0..19</h3>
|
68
|
+
<div id='posts_wrapper_0' class='clearfix'>
|
69
|
+
<div id='posts_0' class='posts'>
|
70
|
+
<span>2022-04-01</span> <span><a href='/stuff/010-published.html'>Published Stuff Post 010</a></span>
|
71
|
+
<span>2022-04-17</span> <span><a href='/stuff/020-unpublished.html'>Unpublished Post 020</a> <i class='jekyll_draft'>Draft</i></span>
|
72
|
+
</div>
|
73
|
+
</div>
|
74
|
+
<h3 class='post_title clear' id="title_20">Topic 20..39</h3>
|
75
|
+
<div id='posts_wrapper_20' class='clearfix'>
|
76
|
+
<div id='posts_20' class='posts'>
|
77
|
+
<span>2022-04-17</span> <span><a href='/stuff/030-unpublished.html'>Unpublished Post 030</a> <i class='jekyll_draft'>Draft</i></span>
|
78
|
+
</div>
|
79
|
+
</div>
|
80
|
+
</div>
|
34
81
|
```
|
35
82
|
|
83
|
+
The JavaScript searches for images in the current page that were created by the [`img`](https://github.com/mslinn/jekyll_img) tag plugin,
|
84
|
+
and have `id`s that correspond to outline sections.
|
85
|
+
|
86
|
+
Each of following image's `id`s have a `outline_` prefix, followed by a number, which corresponds to one of the sections.
|
87
|
+
Note that leading zeros in the first column above are not present in the `id`s below.
|
88
|
+
|
89
|
+
The images are wrapped within an invisible `div` so the web page does not jump around as the images are loaded.
|
90
|
+
```html
|
91
|
+
<div style="display: none;">
|
92
|
+
{% img align="right"
|
93
|
+
id="outline_0"
|
94
|
+
size="quartersize"
|
95
|
+
src="/assets/images/porcelain_washbasin.webp"
|
96
|
+
style="margin-top: 0"
|
97
|
+
wrapper_class="clear"
|
98
|
+
%}
|
99
|
+
{% img align="right"
|
100
|
+
id="outline_20"
|
101
|
+
size="quartersize"
|
102
|
+
src="/assets/images/pipes.webp"
|
103
|
+
style="margin-top: 0"
|
104
|
+
wrapper_class="clear"
|
105
|
+
%}
|
106
|
+
{% img align="right"
|
107
|
+
id="outline_40"
|
108
|
+
size="quartersize"
|
109
|
+
src="/assets/images/libgit2.webp"
|
110
|
+
style="margin-top: 0"
|
111
|
+
wrapper_class="clear"
|
112
|
+
%}
|
113
|
+
</div>
|
114
|
+
```
|
115
|
+
The JavaScript identifies the images and repositions them in the DOM such that they follow the appropriate heading.
|
116
|
+
If no image corresponds to a heading, no error or warning is generated.
|
117
|
+
The images can be located anywhere on the page; they will be relocated appropriately.
|
118
|
+
If an image does not correspond to a heading, it is deleted.
|
119
|
+
|
120
|
+
|
121
|
+
## Attribution
|
122
|
+
See [`jekyll_plugin_support` for `attribution`](https://github.com/mslinn/jekyll_plugin_support#subclass-attribution)
|
123
|
+
|
124
|
+
|
125
|
+
## Additional Information
|
126
|
+
More information is available on
|
127
|
+
[Mike Slinn’s website](https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#outline).
|
128
|
+
|
129
|
+
|
130
|
+
## Development
|
131
|
+
After checking out the repo, run `bin/setup` to install development dependencies.
|
132
|
+
Then you can run `bin/console` for an interactive prompt that will allow you to experiment with `irb`.
|
133
|
+
|
36
134
|
To build and install this gem onto your local machine, run:
|
37
135
|
```shell
|
38
136
|
$ bundle exec rake install
|
@@ -54,16 +152,28 @@ jekyll_outline (0.1.0)
|
|
54
152
|
```
|
55
153
|
|
56
154
|
|
57
|
-
##
|
58
|
-
A test website is provided in the `demo` directory.
|
59
|
-
|
155
|
+
## Demo
|
156
|
+
A demo / test website is provided in the `demo` directory.
|
157
|
+
It can be used to debug the plugin or to run freely.
|
158
|
+
|
159
|
+
### Run Freely
|
160
|
+
1. Run from the command line:
|
161
|
+
```shell
|
162
|
+
$ demo/_bin/debug -r
|
163
|
+
```
|
164
|
+
|
165
|
+
2. View the generated website at [`http://localhost:4444`](http://localhost:4444)
|
166
|
+
|
167
|
+
### Plugin Debugging
|
168
|
+
1. Set breakpoints in Visual Studio Code.
|
60
169
|
|
61
170
|
2. Initiate a debug session from the command line:
|
62
171
|
```shell
|
63
|
-
$
|
172
|
+
$ demo/_bin/debug
|
64
173
|
```
|
65
174
|
|
66
|
-
3. Once the `Fast Debugger` signon appears, launch the Visual Studio Code launch
|
175
|
+
3. Once the `Fast Debugger` signon appears, launch the Visual Studio Code launch
|
176
|
+
configuration called `Attach rdebug-ide`.
|
67
177
|
|
68
178
|
4. View the generated website at [`http://localhost:4444`](http://localhost:4444)
|
69
179
|
|
@@ -82,10 +192,8 @@ To release a new version,
|
|
82
192
|
|
83
193
|
|
84
194
|
## Contributing
|
85
|
-
|
86
195
|
Bug reports and pull requests are welcome on GitHub at https://github.com/mslinn/jekyll_outline.
|
87
196
|
|
88
197
|
|
89
198
|
## License
|
90
|
-
|
91
199
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,31 @@
|
|
1
|
+
// jekyll_img generates picture tags wrapped within divs
|
2
|
+
// We move the entire div, not just the picture tag
|
3
|
+
// If an image does not correspond to a heading, delete it
|
4
|
+
function position_outline_image(picture, before_id) {
|
5
|
+
var img = picture.parentElement;
|
6
|
+
var before_element = document.getElementById(before_id);
|
7
|
+
if (before_element) {
|
8
|
+
var parent = before_element.parentElement;
|
9
|
+
parent.insertBefore(img, before_element);
|
10
|
+
} else {
|
11
|
+
img.remove();
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
function getElementsByIdPrefix(selectorTag, prefix) {
|
16
|
+
var items = [];
|
17
|
+
var myPosts = document.getElementsByTagName(selectorTag);
|
18
|
+
for (var i = 0; i < myPosts.length; i++) {
|
19
|
+
//omitting undefined null check for brevity
|
20
|
+
if (myPosts[i].id.lastIndexOf(prefix, 0) === 0)
|
21
|
+
items.push(myPosts[i]);
|
22
|
+
}
|
23
|
+
return items;
|
24
|
+
}
|
25
|
+
|
26
|
+
window.onload = (event) => {
|
27
|
+
getElementsByIdPrefix("picture", "outline_").forEach(picture => {
|
28
|
+
num = picture.id.substring("outline_".length)
|
29
|
+
position_outline_image(picture, `posts_wrapper_${num}`)
|
30
|
+
});
|
31
|
+
}
|
data/jekyll_outline.gemspec
CHANGED
@@ -9,8 +9,11 @@ Gem::Specification.new do |spec|
|
|
9
9
|
Jekyll tag plugin that creates a clickable table of contents.
|
10
10
|
END_OF_DESC
|
11
11
|
spec.email = ['mslinn@mslinn.com']
|
12
|
-
spec.files = Dir[
|
13
|
-
|
12
|
+
spec.files = Dir[
|
13
|
+
'.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md',
|
14
|
+
'demo/assets/js/jekyll_outline.js'
|
15
|
+
]
|
16
|
+
spec.homepage = 'https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#outline'
|
14
17
|
spec.license = 'MIT'
|
15
18
|
spec.metadata = {
|
16
19
|
'allowed_push_host' => 'https://rubygems.org',
|
@@ -32,6 +35,6 @@ Gem::Specification.new do |spec|
|
|
32
35
|
spec.version = JekyllOutlineVersion::VERSION
|
33
36
|
|
34
37
|
spec.add_dependency 'jekyll', '>= 3.5.0'
|
35
|
-
spec.add_dependency 'jekyll_draft', '~> 1.1.
|
36
|
-
spec.add_dependency 'jekyll_plugin_support', '~> 0.
|
38
|
+
spec.add_dependency 'jekyll_draft', '~> 1.1.0'
|
39
|
+
spec.add_dependency 'jekyll_plugin_support', '~> 0.6.0'
|
37
40
|
end
|
data/lib/jekyll_outline.rb
CHANGED
@@ -1,112 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'jekyll_draft'
|
4
|
-
require 'jekyll_plugin_logger'
|
5
|
-
require 'jekyll_plugin_support'
|
6
|
-
require 'yaml'
|
7
|
-
require_relative 'jekyll_outline/version'
|
1
|
+
require_relative './outline_js'
|
2
|
+
require_relative './outline_tag'
|
8
3
|
|
9
4
|
module Outline
|
10
|
-
|
11
|
-
|
12
|
-
# Interleaves with docs
|
13
|
-
class Header
|
14
|
-
attr_accessor :order, :title
|
15
|
-
|
16
|
-
def initialize(yaml)
|
17
|
-
@order = yaml[0]
|
18
|
-
@published = true
|
19
|
-
@title = yaml[1]
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_s
|
23
|
-
<<~END_STR
|
24
|
-
<h3 id="title_#{order}">#{title}</h3>
|
25
|
-
END_STR
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class OutlineTag < JekyllSupport::JekyllBlock
|
30
|
-
include JekyllOutlineVersion
|
31
|
-
|
32
|
-
FIXNUM_MAX = (2**((0.size * 8) - 2)) - 1
|
33
|
-
|
34
|
-
def render_impl(text)
|
35
|
-
@collection_name = argument_string.strip
|
36
|
-
abort 'OutlineTag: collection_name was not specified' unless @collection_name
|
37
|
-
|
38
|
-
headers = make_headers(super) # Process the block content.
|
39
|
-
collection = headers + obtain_docs(@collection_name)
|
40
|
-
<<~HEREDOC
|
41
|
-
<div class="posts">
|
42
|
-
#{make_entries(collection).join("\n")}
|
43
|
-
</div>
|
44
|
-
HEREDOC
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def header?(variable)
|
50
|
-
variable.instance_of?(Header)
|
51
|
-
end
|
52
|
-
|
53
|
-
def make_headers(content)
|
54
|
-
yaml = YAML.safe_load content
|
55
|
-
yaml.map { |entry| Header.new entry }
|
56
|
-
end
|
57
|
-
|
58
|
-
def make_entries(collection)
|
59
|
-
sorted = collection.sort_by(&obtain_order)
|
60
|
-
pruned = remove_empty_headers(sorted)
|
61
|
-
pruned.map do |entry|
|
62
|
-
if entry.instance_of? Header
|
63
|
-
<<~END_ENTRY
|
64
|
-
<span></span> <span>#{entry}</span>
|
65
|
-
END_ENTRY
|
66
|
-
else
|
67
|
-
date = entry.data['last_modified_at'] # "%Y-%m-%d"
|
68
|
-
draft = Jekyll::Draft.draft_html(entry)
|
69
|
-
<<~END_ENTRY
|
70
|
-
<span>#{date}</span> <span><a href="#{entry.url}">#{entry.data['title']}</a>#{draft}</span>
|
71
|
-
END_ENTRY
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Ignores files called index.html
|
77
|
-
def obtain_docs(collection_name)
|
78
|
-
abort "#{@collection_name} is not a valid collection." unless @site.collections.key? @collection_name
|
79
|
-
@site
|
80
|
-
.collections[collection_name]
|
81
|
-
.docs
|
82
|
-
.reject { |doc| doc.path.end_with? 'index.html' }
|
83
|
-
end
|
84
|
-
|
85
|
-
# Sort entries without an order property at the end
|
86
|
-
def obtain_order
|
87
|
-
proc do |entry|
|
88
|
-
if entry.respond_to? :data
|
89
|
-
entry.data.key?('order') ? entry.data['order'] : FIXNUM_MAX
|
90
|
-
else
|
91
|
-
entry.order
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def remove_empty_headers(array)
|
97
|
-
i = 0
|
98
|
-
while i < array.length - 1
|
99
|
-
if header?(array[i]) && header?(array[i + 1])
|
100
|
-
array.delete_at(i)
|
101
|
-
else
|
102
|
-
i += 1
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
array.delete_at(array.length - 1) if header?(array.last)
|
107
|
-
array
|
108
|
-
end
|
109
|
-
|
110
|
-
JekyllPluginHelper.register(self, PLUGIN_NAME)
|
111
|
-
end
|
5
|
+
include OutlineTag
|
6
|
+
include OutlineJsTag
|
112
7
|
end
|
data/lib/outline_js.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'jekyll_plugin_support'
|
2
|
+
require_relative 'jekyll_outline/version'
|
3
|
+
|
4
|
+
module OutlineJsTag
|
5
|
+
PLUGIN_JS_NAME = 'outline_js'.freeze
|
6
|
+
|
7
|
+
class OutlineJsTag < JekyllSupport::JekyllTag
|
8
|
+
include JekyllOutlineVersion
|
9
|
+
|
10
|
+
def render_impl
|
11
|
+
wrap_in_script_tag = @helper.parameter_specified?('wrap_in_script_tag')
|
12
|
+
|
13
|
+
gem_path = Gem::Specification.find_by_name('jekyll_outline').full_gem_path
|
14
|
+
js_path = File.join(gem_path, 'demo/assets/js/jekyll_outline.js')
|
15
|
+
js = File.read(js_path)
|
16
|
+
|
17
|
+
if wrap_in_script_tag
|
18
|
+
<<~END_JS
|
19
|
+
<script>
|
20
|
+
#{indent(js)}
|
21
|
+
</script>
|
22
|
+
END_JS
|
23
|
+
else
|
24
|
+
js
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def indent(multiline)
|
31
|
+
multiline
|
32
|
+
.strip
|
33
|
+
.split("\n")
|
34
|
+
.map { |x| " #{x}" }
|
35
|
+
.join("\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
JekyllPluginHelper.register(self, PLUGIN_JS_NAME)
|
39
|
+
end
|
40
|
+
end
|
data/lib/outline_tag.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
# @author Copyright 2022 {https://www.mslinn.com Michael Slinn}
|
2
|
+
|
3
|
+
require 'jekyll_draft'
|
4
|
+
require 'jekyll_plugin_logger'
|
5
|
+
require 'jekyll_plugin_support'
|
6
|
+
require 'yaml'
|
7
|
+
require_relative 'jekyll_outline/version'
|
8
|
+
|
9
|
+
module OutlineTag
|
10
|
+
PLUGIN_NAME = 'outline'.freeze
|
11
|
+
|
12
|
+
# Interleaves with docs
|
13
|
+
class Header
|
14
|
+
attr_accessor :order, :title
|
15
|
+
|
16
|
+
def initialize(yaml)
|
17
|
+
@order = yaml[0]
|
18
|
+
@published = true
|
19
|
+
@title = yaml[1]
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
" <h3 class='post_title clear' id=\"title_#{@order}\">#{@title}</h3>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class OutlineTag < JekyllSupport::JekyllBlock
|
28
|
+
include JekyllOutlineVersion
|
29
|
+
|
30
|
+
FIXNUM_MAX = (2**((0.size * 8) - 2)) - 1
|
31
|
+
|
32
|
+
def render_impl(text)
|
33
|
+
headers = make_headers(super) # Process the block content.
|
34
|
+
|
35
|
+
@helper.gem_file __FILE__
|
36
|
+
@collection_name = @helper.remaining_markup
|
37
|
+
abort 'OutlineTag: collection_name was not specified' unless @collection_name
|
38
|
+
|
39
|
+
collection = headers + obtain_docs(@collection_name)
|
40
|
+
<<~HEREDOC
|
41
|
+
<div class="outer_posts">
|
42
|
+
#{make_entries(collection)&.join("\n")}
|
43
|
+
</div>
|
44
|
+
#{@helper.attribute if @helper.attribution}
|
45
|
+
HEREDOC
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def header?(variable)
|
51
|
+
variable.instance_of?(Header)
|
52
|
+
end
|
53
|
+
|
54
|
+
def make_headers(content)
|
55
|
+
yaml = YAML.safe_load(remove_leading_zeros(content))
|
56
|
+
yaml.map { |entry| Header.new entry }
|
57
|
+
end
|
58
|
+
|
59
|
+
# @section_state can have values: :head, :in_body
|
60
|
+
# @param collection Array of Jekyll::Document and Outline::Header
|
61
|
+
# @return Array of String
|
62
|
+
def make_entries(collection) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
63
|
+
sorted = collection.sort_by(&obtain_order)
|
64
|
+
pruned = remove_empty_headers(sorted)
|
65
|
+
@section_state = :head
|
66
|
+
@section_id = 0
|
67
|
+
result = pruned.map do |entry|
|
68
|
+
if entry.instance_of? Header
|
69
|
+
@header_order = entry.order
|
70
|
+
section_end = " </div>\n" if @section_state == :in_body
|
71
|
+
@section_state = :head
|
72
|
+
entry = section_end + entry.to_s if section_end
|
73
|
+
entry
|
74
|
+
else
|
75
|
+
if @section_state == :head
|
76
|
+
section_start = "<div id='posts_wrapper_#{@header_order}' class='clearfix'>\n " \
|
77
|
+
"<div id='posts_#{@header_order}' class='posts'>\n"
|
78
|
+
end
|
79
|
+
@section_state = :in_body
|
80
|
+
date = entry.data['last_modified_at'] # "%Y-%m-%d"
|
81
|
+
draft = Jekyll::Draft.draft_html(entry)
|
82
|
+
result = " <span>#{date}</span> <span><a href='#{entry.url}'>#{entry.data['title']}</a>#{draft}</span>"
|
83
|
+
result = section_start + result if section_start
|
84
|
+
result
|
85
|
+
end
|
86
|
+
end
|
87
|
+
result << " </div>\n </div>" if @section_state == :in_body
|
88
|
+
result
|
89
|
+
end
|
90
|
+
|
91
|
+
# Ignores files called index.html
|
92
|
+
def obtain_docs(collection_name)
|
93
|
+
abort "#{@collection_name} is not a valid collection." unless @site.collections.key? @collection_name
|
94
|
+
@site
|
95
|
+
.collections[collection_name]
|
96
|
+
.docs
|
97
|
+
.reject { |doc| doc.path.end_with? 'index.html' }
|
98
|
+
end
|
99
|
+
|
100
|
+
# Sort entries without an order property at the end
|
101
|
+
def obtain_order
|
102
|
+
proc do |entry|
|
103
|
+
if entry.respond_to? :data
|
104
|
+
entry.data.key?('order') ? entry.data['order'] : FIXNUM_MAX
|
105
|
+
else
|
106
|
+
entry.order
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def remove_empty_headers(array)
|
112
|
+
i = 0
|
113
|
+
while i < array.length - 1
|
114
|
+
if header?(array[i]) && header?(array[i + 1])
|
115
|
+
array.delete_at(i)
|
116
|
+
else
|
117
|
+
i += 1
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
array.delete_at(array.length - 1) if header?(array.last)
|
122
|
+
array
|
123
|
+
end
|
124
|
+
|
125
|
+
def remove_leading_zeros(multiline)
|
126
|
+
multiline
|
127
|
+
.strip
|
128
|
+
.split("\n")
|
129
|
+
.map { |x| x.gsub(/(?<= |\A)0+(?=\d)/, '') }
|
130
|
+
.join("\n")
|
131
|
+
end
|
132
|
+
|
133
|
+
JekyllPluginHelper.register(self, PLUGIN_NAME)
|
134
|
+
end
|
135
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_outline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Slinn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.1.
|
33
|
+
version: 1.1.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.1.
|
40
|
+
version: 1.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: jekyll_plugin_support
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.6.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.6.0
|
55
55
|
description: 'Jekyll tag plugin that creates a clickable table of contents.
|
56
56
|
|
57
57
|
'
|
@@ -66,19 +66,23 @@ files:
|
|
66
66
|
- LICENSE.txt
|
67
67
|
- README.md
|
68
68
|
- Rakefile
|
69
|
+
- demo/assets/js/jekyll_outline.js
|
69
70
|
- jekyll_outline.gemspec
|
70
71
|
- lib/jekyll_outline.rb
|
71
72
|
- lib/jekyll_outline/version.rb
|
73
|
+
- lib/outline_js.rb
|
74
|
+
- lib/outline_tag.rb
|
72
75
|
- spec/outline_spec.rb
|
73
76
|
- spec/spec_helper.rb
|
74
|
-
|
77
|
+
- spec/status_persistence.txt
|
78
|
+
homepage: https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#outline
|
75
79
|
licenses:
|
76
80
|
- MIT
|
77
81
|
metadata:
|
78
82
|
allowed_push_host: https://rubygems.org
|
79
83
|
bug_tracker_uri: https://github.com/mslinn/jekyll_outline/issues
|
80
84
|
changelog_uri: https://github.com/mslinn/jekyll_outline/CHANGELOG.md
|
81
|
-
homepage_uri: https://www.mslinn.com/
|
85
|
+
homepage_uri: https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#outline
|
82
86
|
source_code_uri: https://github.com/mslinn/jekyll_outline
|
83
87
|
post_install_message: |2+
|
84
88
|
|
@@ -105,4 +109,5 @@ summary: Jekyll tag plugin that creates a clickable table of contents.
|
|
105
109
|
test_files:
|
106
110
|
- spec/outline_spec.rb
|
107
111
|
- spec/spec_helper.rb
|
112
|
+
- spec/status_persistence.txt
|
108
113
|
...
|