jekyll_outline 1.1.1 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 464b66396b0abd3369669875ca6b2be97b51e7823e31d5fa163b4248afc0dc50
4
- data.tar.gz: 1253ef8b8218d0c4f76cb66d5f79ef0bc4fef48cec8d057ef33b0af0411e352f
3
+ metadata.gz: a0c7d0f4a87a49c9f0c019221e7895750d5041eff4b0923f1fe819c79c78fa04
4
+ data.tar.gz: e300cb58e1c5ad4235c8c75792e8e94f2f784cff063dbcf361a0d5f36054b1cb
5
5
  SHA512:
6
- metadata.gz: 96bf42bd9e24050bf05fc9c5d1a2094383f2dd3853c301da97ce5e8276969de31ddc98cc5102f3288e46cb84ae9032a2e8c40813993445d837a5a60ffd4b0559
7
- data.tar.gz: 56facfe2c9305b0945ad1d315018b078f1a0402b1c91655ea01a2741f9f39d2975bce5de31eb84490126f4b19700e98a617a84d61a17fbc27a225cc750b941ba
6
+ metadata.gz: bdea785aa21f80694737f6bed9961cfa6f753bc22fdea25f0d0d20e8c73043a84a25a326e905eeaa51a4ad6b041b583394b1040300d838e9dac32c82552251c6
7
+ data.tar.gz: b8ddcebea943a9a0106d9a86374a8c07fd23d6b6ed1bdd0e6f0690128fde5f7dc5d478ee7fbe56eb8b9e1e44be4eab1379b32f483c057afc2dc4a60e56fe2f09
data/.rubocop.yml CHANGED
@@ -25,14 +25,23 @@ Layout/HashAlignment:
25
25
  Layout/LineLength:
26
26
  Max: 150
27
27
 
28
+ Metrics/AbcSize:
29
+ Max: 30
30
+
28
31
  Metrics/BlockLength:
29
32
  Exclude:
30
33
  - jekyll_outline.gemspec
31
34
  Max: 40
32
35
 
36
+ Metrics/CyclomaticComplexity:
37
+ Max: 20
38
+
33
39
  Metrics/MethodLength:
34
40
  Max: 30
35
41
 
42
+ Metrics/PerceivedComplexity:
43
+ Max: 20
44
+
36
45
  Naming/FileName:
37
46
  Exclude:
38
47
  - Rakefile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 1.2.1 / 2023-06-17
2
+ - Updated dependencies.
3
+ - No longer explodes when a value for `order` is not provided in front matter.
4
+
5
+ ## 1.2.0 / 2023-04-23
6
+ - Added optional `field` parameter.
7
+
1
8
  ## 1.1.1 / 2023-04-02
2
9
  * Added [`attribution` support](https://github.com/mslinn/jekyll_plugin_support#subclass-attribution).
3
10
 
data/README.md CHANGED
@@ -16,21 +16,52 @@ end
16
16
 
17
17
  And then execute:
18
18
 
19
- $ bundle install
19
+ $ bundle
20
+
21
+
22
+ ## Fields
23
+ By default, each displayed entry consists of a document title,
24
+ wrapped within an <a href> HTML tag that links to the page for that entry,
25
+ followed by an indication of whether the document is visible (a draft) or not.
26
+
27
+ Entry can also include following fields:
28
+ `draft`, `categories`, `description`, `date`, `last_modified` or `last_modified_at`, `layout`, `order`, `title`, `slug`, `ext`, `tags`, and `excerpt`.
29
+
30
+ Specify the fields like this:
31
+
32
+ ```
33
+ {% outline fields="title &ndash; <i> description </i>" %}
34
+ 000: Topic 0..19
35
+ 020: Topic 20..39
36
+ 040: Topic 40..
37
+ {% endoutline %}
38
+ ```
39
+
40
+ Words that are not a known field are transcribed into the output.
41
+
42
+ In the above example, notice that the HTML is space delimited from the field names.
43
+ The parser is simple and stupid: each token is matched against the known keywords.
44
+ Tokens are separated by white space.
20
45
 
21
46
 
22
47
  ### CSS
23
48
  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:
49
+ See the sections of [`demo/assets/css/styles.css`](/mslinn/jekyll_outline/blob/master/demo/assets/css/style.css#L252-L315) as shown:
25
50
 
26
51
  ```css
52
+ /* Start of jekyll_plugin_support css */
53
+ ... copy this portion ...
54
+ /* End of jekyll_plugin_support css */
55
+
27
56
  /* Start of jekyll_outline css */
28
57
  ... copy this portion ...
29
58
  /* End of jekyll_outline css */
30
59
  ```
31
60
 
32
61
  ### 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:
62
+ This project's `outline_js` tag returns the Javascript necessary to position images relating to the outline.
63
+ If used without parameters it just returns the JavaScript.
64
+ Use the tag this way:
34
65
 
35
66
  ```html
36
67
  <script>
@@ -38,7 +69,8 @@ This project's `outline_js` tag returns the Javascript necessary to position ima
38
69
  </script>
39
70
  ```
40
71
 
41
- If passed the `wrap_in_script_tag` parameter, it wraps the JavaScript in `<script></script>`:
72
+ If passed the `wrap_in_script_tag` parameter, it wraps the JavaScript in `<script></script>`.
73
+ Use the tag this way:
42
74
 
43
75
  ```html
44
76
  {% outline_js wrap_in_script_tag %}
@@ -57,9 +89,9 @@ Given an outline that looks like this:
57
89
 
58
90
  ...and given pages in the `stuff` collection with the following names:
59
91
 
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**
92
+ - `010-published.html` has title **Published Stuff Post 010**
93
+ - `020-unpublished.html` has title **Unpublished Post 020**
94
+ - `030-unpublished.html` has title **Unpublished Post 030**
63
95
 
64
96
  Then links to the pages in the `stuff` collection's pages are interleaved into the generated outline like this:
65
97
  ```html
@@ -80,13 +112,15 @@ Then links to the pages in the `stuff` collection's pages are interleaved into t
80
112
  </div>
81
113
  ```
82
114
 
83
- The JavaScript searches for images in the current page that were created by the [`img`](https://github.com/mslinn/jekyll_img) tag plugin,
115
+ The JavaScript searches for images in the current page that were created by the
116
+ [`img`](https://github.com/mslinn/jekyll_img) tag plugin,
84
117
  and have `id`s that correspond to outline sections.
85
118
 
86
- Each of following image's `id`s have a `outline_` prefix, followed by a number, which corresponds to one of the sections.
119
+ Each of following image's `id`s have an `outline_` prefix, followed by a number, which corresponds to one of the sections.
87
120
  Note that leading zeros in the first column above are not present in the `id`s below.
88
121
 
89
- The images are wrapped within an invisible `div` so the web page does not jump around as the images are loaded.
122
+ If you want to provide images to embed at appropriate locations within the outline,
123
+ wrap them within an invisible `div` so the web page does not jump around as the images are loaded.
90
124
  ```html
91
125
  <div style="display: none;">
92
126
  {% img align="right"
@@ -118,6 +152,8 @@ The images can be located anywhere on the page; they will be relocated appropria
118
152
  If an image does not correspond to a heading, it is deleted.
119
153
 
120
154
 
155
+
156
+
121
157
  ## Attribution
122
158
  See [`jekyll_plugin_support` for `attribution`](https://github.com/mslinn/jekyll_plugin_support#subclass-attribution)
123
159
 
@@ -129,8 +165,10 @@ More information is available on
129
165
 
130
166
  ## Development
131
167
  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
168
 
169
+ Then you can run `bin/console` for an interactive prompt that will allow you to experiment using `irb`.
170
+
171
+ ### Build and Install Locally
134
172
  To build and install this gem onto your local machine, run:
135
173
  ```shell
136
174
  $ bundle exec rake install
@@ -194,6 +232,11 @@ To release a new version,
194
232
  ## Contributing
195
233
  Bug reports and pull requests are welcome on GitHub at https://github.com/mslinn/jekyll_outline.
196
234
 
235
+ 1. Fork the project
236
+ 2. Create a descriptively named feature branch
237
+ 3. Add your feature
238
+ 4. Submit a pull request
239
+
197
240
 
198
241
  ## License
199
242
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  '.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md',
14
14
  'demo/assets/js/jekyll_outline.js'
15
15
  ]
16
- spec.homepage = 'https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#outline'
16
+ spec.homepage = 'https://www.mslinn.com/jekyll_plugins/jekyll_outline.html'
17
17
  spec.license = 'MIT'
18
18
  spec.metadata = {
19
19
  'allowed_push_host' => 'https://rubygems.org',
@@ -35,6 +35,6 @@ Gem::Specification.new do |spec|
35
35
  spec.version = JekyllOutlineVersion::VERSION
36
36
 
37
37
  spec.add_dependency 'jekyll', '>= 3.5.0'
38
- spec.add_dependency 'jekyll_draft', '~> 1.1.0'
39
- spec.add_dependency 'jekyll_plugin_support', '~> 0.6.0'
38
+ spec.add_dependency 'jekyll_draft', '>= 1.1.2'
39
+ spec.add_dependency 'jekyll_plugin_support', '>= 0.7.0'
40
40
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllOutlineVersion
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.2.1'.freeze
3
3
  end
data/lib/outline_tag.rb CHANGED
@@ -24,7 +24,7 @@ module OutlineTag
24
24
  end
25
25
  end
26
26
 
27
- class OutlineTag < JekyllSupport::JekyllBlock
27
+ class OutlineTag < JekyllSupport::JekyllBlock # rubocop:disable Metrics/ClassLength
28
28
  include JekyllOutlineVersion
29
29
 
30
30
  FIXNUM_MAX = (2**((0.size * 8) - 2)) - 1
@@ -33,13 +33,16 @@ module OutlineTag
33
33
  headers = make_headers(super) # Process the block content.
34
34
 
35
35
  @helper.gem_file __FILE__
36
+ @fields = @helper.parameter_specified?('fields')&.split(' ') || ['title']
36
37
  @collection_name = @helper.remaining_markup
37
38
  abort 'OutlineTag: collection_name was not specified' unless @collection_name
38
39
 
39
- collection = headers + obtain_docs(@collection_name)
40
+ @docs = obtain_docs(@collection_name)
41
+ collection = headers + @docs
42
+
40
43
  <<~HEREDOC
41
44
  <div class="outer_posts">
42
- #{make_entries(collection)&.join("\n")}
45
+ #{make_entries collection}
43
46
  </div>
44
47
  #{@helper.attribute if @helper.attribution}
45
48
  HEREDOC
@@ -59,35 +62,67 @@ module OutlineTag
59
62
  # @section_state can have values: :head, :in_body
60
63
  # @param collection Array of Jekyll::Document and Outline::Header
61
64
  # @return Array of String
62
- def make_entries(collection) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
65
+ def make_entries(collection)
63
66
  sorted = collection.sort_by(&obtain_order)
64
- pruned = remove_empty_headers(sorted)
67
+ pruned = remove_empty_headers sorted
65
68
  @section_state = :head
66
69
  @section_id = 0
67
70
  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"
71
+ handle entry
72
+ end
73
+ result << " </div>\n </div>" if @section_state == :in_body
74
+ result&.join("\n")
75
+ end
76
+
77
+ KNOWN_FIELDS = %w[draft categories description date last_modified_at layout order title slug ext tags excerpt].freeze
78
+
79
+ def handle(entry)
80
+ if entry.instance_of? Header
81
+ @header_order = entry.order
82
+ section_end = " </div>\n" if @section_state == :in_body
83
+ @section_state = :head
84
+ entry = section_end + entry.to_s if section_end
85
+ entry
86
+ else
87
+ if @section_state == :head
88
+ section_start = "<div id='posts_wrapper_#{@header_order}' class='clearfix'>\n " \
89
+ "<div id='posts_#{@header_order}' class='posts'>\n"
90
+ end
91
+ @section_state = :in_body
92
+ date = entry.data['last_modified_at'] # "%Y-%m-%d"
93
+ draft = Jekyll::Draft.draft_html(entry)
94
+ visible_line = handle_entry entry
95
+ result = " <span>#{date}</span> <span><a href='#{entry.url}'>#{visible_line.strip}</a>#{draft}</span>"
96
+ result = section_start + result if section_start
97
+ result
98
+ end
99
+ end
100
+
101
+ def handle_entry(entry)
102
+ result = ''
103
+ @fields.each do |field|
104
+ if KNOWN_FIELDS.include? field
105
+ if entry.data.key? field
106
+ result += "#{entry.data[field]} "
107
+ else
108
+ @logger.warn { "#{field} is a known field, but it was not present in entry #{entry}" }
78
109
  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
110
+ else
111
+ result += "#{field} "
85
112
  end
86
113
  end
87
- result << " </div>\n </div>" if @section_state == :in_body
88
114
  result
89
115
  end
90
116
 
117
+ # Find the given document
118
+ def obtain_doc(doc_name)
119
+ abort "#{@collection_name} is not a valid collection." unless @site.collections.key? @collection_name
120
+ @site
121
+ .collections[@collection_name]
122
+ .docs
123
+ .find { |doc| doc.path.end_with? "#{doc_name}.html" }
124
+ end
125
+
91
126
  # Ignores files called index.html
92
127
  def obtain_docs(collection_name)
93
128
  abort "#{@collection_name} is not a valid collection." unless @site.collections.key? @collection_name
@@ -101,9 +136,9 @@ module OutlineTag
101
136
  def obtain_order
102
137
  proc do |entry|
103
138
  if entry.respond_to? :data
104
- entry.data.key?('order') ? entry.data['order'] : FIXNUM_MAX
139
+ entry.data.key?('order') ? entry.data['order'] || FIXNUM_MAX : FIXNUM_MAX
105
140
  else
106
- entry.order
141
+ entry.order || FIXNUM_MAX
107
142
  end
108
143
  end
109
144
  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.1.1
4
+ version: 1.2.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-04-06 00:00:00.000000000 Z
11
+ date: 2023-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -28,30 +28,30 @@ dependencies:
28
28
  name: jekyll_draft
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.0
33
+ version: 1.1.2
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.0
40
+ version: 1.1.2
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.6.0
47
+ version: 0.7.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.6.0
54
+ version: 0.7.0
55
55
  description: 'Jekyll tag plugin that creates a clickable table of contents.
56
56
 
57
57
  '
@@ -75,14 +75,14 @@ files:
75
75
  - spec/outline_spec.rb
76
76
  - spec/spec_helper.rb
77
77
  - spec/status_persistence.txt
78
- homepage: https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#outline
78
+ homepage: https://www.mslinn.com/jekyll_plugins/jekyll_outline.html
79
79
  licenses:
80
80
  - MIT
81
81
  metadata:
82
82
  allowed_push_host: https://rubygems.org
83
83
  bug_tracker_uri: https://github.com/mslinn/jekyll_outline/issues
84
84
  changelog_uri: https://github.com/mslinn/jekyll_outline/CHANGELOG.md
85
- homepage_uri: https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#outline
85
+ homepage_uri: https://www.mslinn.com/jekyll_plugins/jekyll_outline.html
86
86
  source_code_uri: https://github.com/mslinn/jekyll_outline
87
87
  post_install_message: |2+
88
88