jekyll_outline 1.3.1 → 1.3.2

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: 96e9568e3415361a58aa520184727fb695bc086ad8b061283ecb7a2401db15c5
4
- data.tar.gz: 6992878d57e19e5c74a8571e6c3ac1b4777a46ad2a7bdfe7707cbb18247f347d
3
+ metadata.gz: 7fcc3d9115329aa5d6738f7bbfa233c339fffcf281d58dd80c67f61e65725d85
4
+ data.tar.gz: b4df5d9482c97b3cb73b2e0e8d7dd289181a4bbd8d87abe0c3f79d9c9d8e51f2
5
5
  SHA512:
6
- metadata.gz: e386afa2f295ac6343a5775e5404414f5d4966cc546b0e0aba7924b89ffd488f4d0b4345128813d9fe0de572ce5e883537f19ecfdfd258fad85c4f42f514ae16
7
- data.tar.gz: b004df43f78d12167d471a9670cd0656e4d612dc18b00928b0e3a32ae99fa9e287d8a61da037b9a940e1e0a2cd0d2743653a9860f28658a9830bd3047f50e865
6
+ metadata.gz: 9650d9694b205195f0d19691d8f804d402024f9207f0783ec694ddf03b49004dd7c9809e967e73067144265b96b8ccd27c55ce02d6ac567061750a77397a5ece
7
+ data.tar.gz: 63341482413e58d356d217957c44dd61eac42f65c92a049cad2af58b5b021e5c4410b5debc09e5c941494198d84316d563f017a6b459ca3a8013d14191aae7bf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.3.2 / 2026-11-18
4
+
5
+ * Added `msls` command.
6
+
7
+
3
8
  ## 1.3.1 / 2025-07-14
4
9
 
5
10
  * Now warns of pages that do not have `order` defined in front matter.
data/README.md CHANGED
@@ -221,9 +221,15 @@ end
221
221
  And then execute:
222
222
 
223
223
  ```shell
224
- $ bundle
224
+ $ bundle install
225
225
  ```
226
226
 
227
+ Linux users could also add this to `~/.bashrc`:
228
+
229
+ ```script
230
+ jekyll_outline="/path/to/this/project"
231
+ PATH="$jekyll_outline/bin:$PATH"
232
+ ```
227
233
 
228
234
  ## Fields
229
235
 
@@ -374,6 +380,49 @@ More information is available on
374
380
  [Mike Slinn’s website](https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#outline).
375
381
 
376
382
 
383
+ ## Listing The Outline
384
+
385
+ The first task one must face when starting a new article in a collection is
386
+ provide front matter. This plugin requires the `order` key to have a value, or
387
+ the articles cannot be sorted. Deciding on the best `order` value for a new
388
+ article can be frustrating when you have a lot of articles with many sections in
389
+ the collection.
390
+
391
+ The `msls` command was designed to solve that problem. It is installed when you
392
+ install this gem as described above.
393
+
394
+ Here is a portion of the `msls` output when run on the Jekyll repository for
395
+ mslinn.com (color for draft articles is not shown here):
396
+
397
+ ```shell
398
+ $ msls llm
399
+ _llm (68 articles, 18 drafts)
400
+
401
+ [0] End User Experience
402
+ 500 whisper.html OpenAI Whisper 2024-04-21
403
+ 750 chat-transcripts.html Recording Chat Transcripts 2025-12-14
404
+ 755 session_resume.html Resuming a Claude Code Session on Another Computer 2026-10-31
405
+
406
+ [1000] Math Background
407
+ 1000 latex.html LaTeX Notes 2026-02-02
408
+ 1100 html-math.html Writing Math For Web Pages 2026-02-02
409
+ 1200 probablility-theory.html Quick Review of Probability Theory 2024-01-27
410
+
411
+ [1500] LLM Theory
412
+ 1500 llm-notes.html Large Language Model Notes 2025-09-12
413
+ 1550 diffusion-implementation.html Diffusion Model Implementation From Scratch. 2024-02-11
414
+ 1553 edit_format.html LLM Edit Formats 2026-04-21
415
+ 1555 system-prompts.html LLM System Prompts 2025-11-25
416
+ 1560 rag.html Retrieval Augmented Generation (RAG) 2025-12-12
417
+ 1565 planning-vs-waterfall.html AI Planning vs. Waterfall Project Management 2025-10-12
418
+ 1566 social-llms.html LLM Societies 2025-12-13
419
+ 1570 deterministic_plan.html Deterministic Plans for LLMs 2026-08-10
420
+ <i>... snip ...</i>
421
+ ```
422
+
423
+ When invoked with no arguments, `msls` lists all articles in all collections.
424
+
425
+
377
426
  ## Development
378
427
 
379
428
  After checking out the repo, run `bin/setup` to install development dependencies.
data/exe/msls ADDED
@@ -0,0 +1,284 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # List the articles of a Jekyll collection: filename, order parameter, title
4
+ # and date last modified.
5
+ #
6
+ # The order: parameter in an article's front matter positions the article
7
+ # within its collection's index page. collections/<collection>/index.html
8
+ # defines the boundary numbers for those parameters, so the articles are
9
+ # grouped by the section their order number falls into, and each section is
10
+ # labelled with its boundary.
11
+ #
12
+ # Usage:
13
+ # msls # every collection, in name order
14
+ # msls llm # one collection
15
+ # msls _llm # same collection
16
+ # msls _llm _ruby # several collections
17
+ # msls llm ruby # several collections
18
+ #
19
+ # Options:
20
+ # --order sort each section by order parameter (the default)
21
+ # --filename sort each section by file name
22
+ # --title sort each section by title
23
+ # --modified sort each section by date last modified
24
+ # --no-color omit the color that dims the drafts
25
+
26
+ require 'date'
27
+ require 'optparse'
28
+ require 'yaml'
29
+
30
+ RESET = "\e[0m".freeze
31
+ BOLD = "\e[1m".freeze
32
+ GREY = "\e[90m".freeze
33
+
34
+ root = Dir.pwd
35
+ @collections_dir = File.join(root, 'collections')
36
+ @config_file = File.join(root, '_config.yml')
37
+
38
+ # An article of a collection.
39
+ Article = Struct.new(:file, :order, :title, :draft, :modified, :mtime)
40
+
41
+ # @return [Boolean] whether the output should be colorized
42
+ def colorize?
43
+ return @colorize unless @colorize.nil?
44
+
45
+ @colorize = $stdout.tty? && ENV['NO_COLOR'].nil?
46
+ end
47
+
48
+ module StringPrefix
49
+ refine String do
50
+ # @param name [String] a collection name, with or without its leading underscore
51
+ # @return [String, nil] the path of the collection directory, nil if there is none
52
+ def ensure_prefix(prefix)
53
+ start_with?(prefix) ? self : "#{prefix}#{self}"
54
+ end
55
+ end
56
+ end
57
+
58
+ using StringPrefix
59
+
60
+ def collection_dir(name)
61
+ dir = File.join(@collections_dir, name.ensure_prefix('_'))
62
+ abort "Error in collection_dir: #{dir} is not a directory" unless File.directory?(dir)
63
+ dir
64
+ end
65
+
66
+ # @return [Array<String>] the names of the collections, in name order
67
+ def configured_collections
68
+ config = YAML.safe_load(File.read(@config_file), permitted_classes: [Date, Time], aliases: true)
69
+ config.fetch('collections', {}).keys.sort
70
+ rescue StandardError => e
71
+ warn "cannot read #{@config_file}: #{e.message}"
72
+ []
73
+ end
74
+
75
+ # @param path [String] the path of an article
76
+ # @return [Hash] the front matter of the article, empty if it cannot be read
77
+ def front_matter(path)
78
+ text = File.read(path, encoding: 'UTF-8')
79
+ match = text.match(/\A---[ \t]*\r?\n(.*?)\r?\n---[ \t]*\r?\n/m)
80
+ return {} unless match
81
+
82
+ data = YAML.safe_load(match[1], permitted_classes: [Date, Time], aliases: true)
83
+ data.is_a?(Hash) ? data : {}
84
+ rescue StandardError
85
+ {}
86
+ end
87
+
88
+ # @param data [Hash] the front matter of an article
89
+ # @return [Boolean] whether the article is a draft
90
+ def draft?(data)
91
+ return !data['published'] if data.key?('published')
92
+ return data['draft'] if data.key?('draft')
93
+
94
+ false
95
+ end
96
+
97
+ # The date an article was last modified, resolved as the site resolves it:
98
+ # the last_modified field, else last_modified_at, else the date of publication.
99
+ #
100
+ # @param data [Hash] the front matter of an article
101
+ # @return [Date, nil] the date of the last modification
102
+ def modified_date(data)
103
+ value = data['last_modified'] || data['last_modified_at'] || data['date']
104
+ case value
105
+ when Date then value
106
+ when Time then value.to_date
107
+ when String then Date.parse(value)
108
+ end
109
+ rescue ArgumentError
110
+ nil
111
+ end
112
+
113
+ # The outline of a collection lists every article of it, except those whose
114
+ # name starts with index and those that opt out with exclude_from_outline.
115
+ #
116
+ # @param dir [String] the path of a collection directory
117
+ # @return [Array<Article>] the articles of the collection, in file name order
118
+ def articles(dir)
119
+ Dir[File.join(dir, '*.html')].sort.filter_map do |path|
120
+ next if File.basename(path).start_with?('index')
121
+
122
+ data = front_matter(path)
123
+ next if data['exclude_from_outline']
124
+
125
+ Article.new(File.basename(path), data['order'], data['title'].to_s, draft?(data),
126
+ modified_date(data), File.mtime(path))
127
+ end
128
+ end
129
+
130
+ # The boundary numbers of a collection are defined by the {% outline %} block of
131
+ # its index.html, as YAML mapping a boundary number to the name of a section.
132
+ #
133
+ # @param dir [String] the path of a collection directory
134
+ # @return [Array<Array>] the sections, as [boundary, name] pairs in boundary order
135
+ def sections(dir)
136
+ path = File.join(dir, 'index.html')
137
+ return [] unless File.exist?(path)
138
+
139
+ text = File.read(path, encoding: 'UTF-8')
140
+ match = text.match(/\{%-?\s*outline\b.*?%}(.*?)\{%-?\s*endoutline\s*%}/m)
141
+ return [] unless match
142
+
143
+ body = match[1].strip.split("\n").map { |line| line.sub(/\A\s+/, '') }.join("\n")
144
+ body = body.gsub(/(?<= |\A)0+(?=\d)/, '')
145
+ parsed = YAML.safe_load(body)
146
+ return [] unless parsed.is_a?(Hash)
147
+
148
+ parsed.map { |boundary, name| [boundary.to_i, name.to_s] }.sort
149
+ rescue StandardError
150
+ []
151
+ end
152
+
153
+ # @param order [Integer, nil] the order parameter of an article
154
+ # @param sections [Array<Array>] the sections of a collection
155
+ # @return [Array, nil] the section the article falls into, as a [boundary, name] pair
156
+ def section_for(order, sections)
157
+ return nil if order.nil? || sections.empty?
158
+
159
+ sections.reverse.find { |boundary, _| boundary <= order } || sections.first
160
+ end
161
+
162
+ # The sort key of an article. The time of the last modification breaks ties
163
+ # between articles modified on the same day, but is not displayed.
164
+ #
165
+ # @param article [Article] the article to sort
166
+ # @return [Array] the key to sort by
167
+ def sort_key(article)
168
+ case @sort
169
+ when 'filename' then [article.file]
170
+ when 'title' then [article.title.downcase]
171
+ when 'modified' then [article.modified || Date.new(0), article.mtime]
172
+ else [article.order.nil? ? 1 : 0, article.order || 0]
173
+ end
174
+ end
175
+
176
+ # @param articles [Array<Article>] the articles to sort
177
+ # @return [Array<Article>] the articles by the sort key, then by file name
178
+ def sorted(articles)
179
+ articles.sort_by { |a| sort_key(a) + [a.file] }
180
+ end
181
+
182
+ # The sections of a collection are the groups its articles fall into. Sections
183
+ # are keyed by their boundary, not their name, because a collection may reuse
184
+ # a name for more than one section.
185
+ #
186
+ # @param articles [Array<Article>] the articles of a collection
187
+ # @param sections [Array<Array>] the sections of a collection
188
+ # @return [Array<Array>] the groups of articles, as [section, articles] pairs
189
+ def groups_for(articles, sections)
190
+ return [[nil, sorted(articles)]] if sections.empty?
191
+
192
+ by_section = Hash.new { |hash, key| hash[key] = [] }
193
+ unsectioned = []
194
+ articles.each do |article|
195
+ section = section_for(article.order, sections)
196
+ section ? by_section[section] << article : unsectioned << article
197
+ end
198
+
199
+ groups = sections.map { |section| [section, sorted(by_section[section])] }
200
+ groups << [:unsectioned, sorted(unsectioned)] unless unsectioned.empty?
201
+ groups
202
+ end
203
+
204
+ # A collection with no outline in its index.html has no sections to group by,
205
+ # so its articles are listed without a heading.
206
+ #
207
+ # @param section [Array, nil] the section, nil for an ungrouped list
208
+ # @return [String, nil] the heading of the group, nil if it needs none
209
+ def group_heading(section)
210
+ return nil if section.nil?
211
+ return '(no order)' if section == :unsectioned
212
+
213
+ "[#{section.first}] #{section.last}"
214
+ end
215
+
216
+ # @param text [String] the text to print
217
+ # @param draft [Boolean] whether the text belongs to a draft
218
+ # @return [String] the text, dimmed if it belongs to a draft
219
+ def styled(text, draft)
220
+ return text unless draft && colorize?
221
+
222
+ "#{GREY}#{text}#{RESET}"
223
+ end
224
+
225
+ # @param text [String] the text of a heading
226
+ # @return [String] the text, bold
227
+ def heading(text)
228
+ return text unless colorize?
229
+
230
+ "#{BOLD}#{text}#{RESET}"
231
+ end
232
+
233
+ # @param articles [Array<Article>] the articles of a collection
234
+ # @return [String] the heading of the collection
235
+ def collection_heading(name, articles)
236
+ drafts = articles.count(&:draft)
237
+ summary = "#{articles.length} article#{'s' unless articles.length == 1}"
238
+ summary += ", #{drafts} draft#{'s' unless drafts == 1}" if drafts.positive?
239
+ "#{name} (#{summary})"
240
+ end
241
+
242
+ # @param articles [Array<Article>] the articles of a collection
243
+ # @param sections [Array<Array>] the sections of a collection
244
+ # @return [String] the listing of the collection
245
+ def render(name, articles, sections)
246
+ out = [heading(collection_heading(name, articles)), '']
247
+ width = [articles.map { |a| a.order.to_s.length }.max || 0, 4].max
248
+ name_width = articles.map { |a| a.file.length }.max || 0
249
+
250
+ groups_for(articles, sections).each do |section, group|
251
+ label = group_heading(section)
252
+ out << " #{heading(label)}" if label
253
+ sorted(group).each do |article|
254
+ order = article.order.to_s.rjust(width)
255
+ modified = article.modified&.strftime('%Y-%m-%d').to_s
256
+ out << " #{styled(order, article.draft)} " \
257
+ "#{styled(article.file.ljust(name_width), article.draft)} " \
258
+ "#{styled(article.title, article.draft)} " \
259
+ "#{styled(modified, article.draft)}"
260
+ end
261
+ out << ''
262
+ end
263
+ out.join("\n")
264
+ end
265
+
266
+ options = { color: nil, sort: 'order' }
267
+ parser = OptionParser.new do |opts|
268
+ opts.banner = 'Usage:msls [options] [COLLECTION_NAME]...'
269
+ opts.on('--order', 'sort each section by order parameter (the default)') { options[:sort] = 'order' }
270
+ opts.on('--filename', 'sort each section by file name') { options[:sort] = 'filename' }
271
+ opts.on('--title', 'sort each section by title') { options[:sort] = 'title' }
272
+ opts.on('--modified', 'sort each section by date last modified') { options[:sort] = 'modified' }
273
+ opts.on('--no-color', 'omit the color that dims the drafts') { options[:color] = false }
274
+ end
275
+
276
+ parser.parse!
277
+ names = ARGV.empty? ? configured_collections : ARGV
278
+ renderings = names.map do |name|
279
+ dir = collection_dir(name)
280
+ collection = articles(dir)
281
+ render("_#{name.delete_prefix('_')}", collection, sections(dir))
282
+ end
283
+
284
+ puts renderings.join("\n")
@@ -9,6 +9,9 @@ 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.executables = %w[
13
+ msls
14
+ ]
12
15
  spec.files = Dir[
13
16
  '.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md',
14
17
  'demo/assets/js/jekyll_outline.js'
@@ -1,3 +1,3 @@
1
1
  module JekyllOutlineVersion
2
- VERSION = '1.3.1'.freeze
2
+ VERSION = '1.3.2'.freeze
3
3
  end
@@ -109,7 +109,7 @@ module JekyllSupport
109
109
 
110
110
  result = []
111
111
  result << "<div class='outer_posts'>"
112
- result << (@sections.map { |section| " #{section}" })
112
+ result << @sections.map { |section| " #{section}" }
113
113
  result << '</div>'
114
114
  result << @options.attribution if @options.enable_attribution
115
115
  result.join "\n"
@@ -119,8 +119,8 @@ module JekyllSupport
119
119
 
120
120
  def add_apage(apage)
121
121
  unless apage
122
+ # Defeat formatter
122
123
  raise ::OutlineError, 'add_apage called with nil apage'
123
- puts
124
124
  end
125
125
  raise ::OutlineError, 'add_apage called without first calling add_sections' unless @add_sections_called
126
126
 
@@ -150,7 +150,7 @@ module JekyllSupport
150
150
  # Only called when entries are organized into multiple sections
151
151
  # @param apage must have a property called `order`
152
152
  def section_for(apage)
153
- return @sections.first if @sections.count == 1
153
+ return @sections.first if @sections.one?
154
154
 
155
155
  last = @sections.length - 1
156
156
  (0..last).each do |i|
@@ -16,11 +16,13 @@ module JekyllSupport
16
16
  end
17
17
 
18
18
  def to_s
19
- return '' if @children.count.zero?
19
+ return '' if @children.empty?
20
20
 
21
21
  unless @children.first.instance_of?(JekyllSupport::APage)
22
+ # defeat formatter
22
23
  raise "First child of Section was a #{@children.first.class}, not an APage"
23
24
  end
25
+
24
26
  apages = @children
25
27
  .map { |x| x.render_outline_apage @outline_options.pattern }
26
28
  .join("\n ")
@@ -1,3 +1,11 @@
1
- example_id | status | run_time |
2
- ---------------------------------- | ------ | --------------- |
3
- ./spec/jekyll_outline_spec.rb[1:1] | passed | 0.00023 seconds |
1
+ example_id | status | run_time |
2
+ ------------------------------- | ------ | --------------- |
3
+ ./spec/outline_spec.rb[1:1] | passed | 0.00105 seconds |
4
+ ./spec/outline_spec.rb[1:2] | passed | 0.00006 seconds |
5
+ ./spec/outline_spec.rb[1:3] | passed | 0.00003 seconds |
6
+ ./spec/outline_spec.rb[1:4] | passed | 0.00014 seconds |
7
+ ./spec/outline_spec.rb[1:5] | passed | 0.00009 seconds |
8
+ ./spec/outline_spec.rb[1:6] | passed | 0.00012 seconds |
9
+ ./spec/yaml_parser_spec.rb[1:1] | passed | 0.00081 seconds |
10
+ ./spec/yaml_parser_spec.rb[1:2] | passed | 0.00018 seconds |
11
+ ./spec/yaml_parser_spec.rb[1:3] | passed | 0.00108 seconds |
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_outline
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
@@ -56,7 +56,8 @@ description: 'Jekyll tag plugin that creates a clickable table of contents.
56
56
  '
57
57
  email:
58
58
  - mslinn@mslinn.com
59
- executables: []
59
+ executables:
60
+ - msls
60
61
  extensions: []
61
62
  extra_rdoc_files: []
62
63
  files:
@@ -66,6 +67,7 @@ files:
66
67
  - README.md
67
68
  - Rakefile
68
69
  - demo/assets/js/jekyll_outline.js
70
+ - exe/msls
69
71
  - jekyll_outline.gemspec
70
72
  - lib/jekyll_outline.rb
71
73
  - lib/jekyll_outline/version.rb
@@ -106,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
108
  - !ruby/object:Gem::Version
107
109
  version: '0'
108
110
  requirements: []
109
- rubygems_version: 3.7.1
111
+ rubygems_version: 4.0.24
110
112
  specification_version: 4
111
113
  summary: Jekyll tag plugin that creates a clickable table of contents.
112
114
  test_files: