jekyll-titles-from-headings 0.5.1 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e49e70668e584d947d32235592a93364948dd57b0069a122c359059430fb150
4
- data.tar.gz: cb19ed6d75fb697500454b9deaca2363cc3958f3ea03afef8cdd36b3725baabb
3
+ metadata.gz: 2a36789e56728be11eb6c911bd0158e7f176ff946ca0681fbde8e60b5ce5e9a5
4
+ data.tar.gz: e40ce5d4d52c051a1b17b318a183cd2f762006cd04fea731f08f16a225b80230
5
5
  SHA512:
6
- metadata.gz: 99e5a5316e15c49aea7b8b879ed0d0bc0757a46690dafa50abebf048c97c93cd41fdc38863a127cc6706de7d6f397ce610ad968a7b3d3de20b4c137c9705f08e
7
- data.tar.gz: '090e697203ced69aa950d2a9c9d4321463cd4f22f2dc765c4eb7db060e1b12a0699f0a129572ebe4d10a5d78233e26464a1156c07a3b8366dd615523840c3396'
6
+ metadata.gz: b50626d58bddf7137498404b38c2d5eec3c0ccac30cac171cbedcbf5db50affe1c387280c3becb7954f90a99af58a60cdb2c24f385d81e9f3cd8e13f90ed0c0e
7
+ data.tar.gz: b36324e303a38e1a567d0c70fc1ec9b98a8100968345ca123699165ccb0e4a3de3eae16a9e319d63a6082fb48f6e45cb9b681e36490318d0fef0886998cbec63
data/README.md CHANGED
@@ -27,9 +27,10 @@ Additionally, this allows you to store the title semantically, in the document i
27
27
  2. Add the following to your site's config file:
28
28
 
29
29
  ```yml
30
- gems:
30
+ plugins:
31
31
  - jekyll-titles-from-headings
32
32
  ```
33
+ Note: If you are using a Jekyll version less than 3.5.0, use the `gems` key instead of `plugins`.
33
34
 
34
35
  ## Configuration
35
36
 
@@ -3,31 +3,27 @@
3
3
  module JekyllTitlesFromHeadings
4
4
  class Generator < Jekyll::Generator
5
5
  attr_accessor :site
6
-
7
- # rubocop:disable Lint/InterpolationCheck
8
6
  TITLE_REGEX =
9
7
  %r!
10
- \A\s* # Beginning and whitespace
11
- (?: # either
12
- \#{1,3}\s+(.*) # atx-style header
13
- | # or
14
- (.*)\r?\n[-=]+\s* # Setex-style header
15
- )$ # end of line
16
- !x
17
- # rubocop:enable Lint/InterpolationCheck
8
+ \A\s* # Beginning and whitespace
9
+ (?: # either
10
+ \#{1,3}\s+(.*)(?:\s+\#{1,3})? # atx-style header
11
+ | # or
12
+ (.*)\r?\n[-=]+\s* # Setex-style header
13
+ )$ # end of line
14
+ !x.freeze
15
+
18
16
  CONVERTER_CLASS = Jekyll::Converters::Markdown
19
- STRIP_MARKUP_FILTERS = %i[
20
- markdownify strip_html normalize_whitespace
21
- ].freeze
17
+ STRIP_MARKUP_FILTERS = [:markdownify, :strip_html, :normalize_whitespace].freeze
22
18
 
23
19
  # Regex to strip extra markup still present after markdownify
24
20
  # (footnotes at the moment).
25
- EXTRA_MARKUP_REGEX = %r!\[\^[^\]]*\]!
21
+ EXTRA_MARKUP_REGEX = %r!\[\^[^\]]*\]!.freeze
26
22
 
27
- CONFIG_KEY = "titles_from_headings".freeze
28
- ENABLED_KEY = "enabled".freeze
29
- STRIP_TITLE_KEY = "strip_title".freeze
30
- COLLECTIONS_KEY = "collections".freeze
23
+ CONFIG_KEY = "titles_from_headings"
24
+ ENABLED_KEY = "enabled"
25
+ STRIP_TITLE_KEY = "strip_title"
26
+ COLLECTIONS_KEY = "collections"
31
27
 
32
28
  safe true
33
29
  priority :lowest
@@ -46,6 +42,7 @@ module JekyllTitlesFromHeadings
46
42
  documents.each do |document|
47
43
  next unless should_add_title?(document)
48
44
  next if document.is_a?(Jekyll::StaticFile)
45
+
49
46
  document.data["title"] = title_for(document)
50
47
  strip_title!(document) if strip_title?(document)
51
48
  end
@@ -69,8 +66,10 @@ module JekyllTitlesFromHeadings
69
66
 
70
67
  def title_for(document)
71
68
  return document.data["title"] if title?(document)
69
+
72
70
  matches = document.content.to_s.match(TITLE_REGEX)
73
71
  return strip_markup(matches[1] || matches[2]) if matches
72
+
74
73
  document.data["title"] # If we cant match a title, we use the inferred one.
75
74
  rescue ArgumentError => e
76
75
  raise e unless e.to_s.start_with?("invalid byte sequence in UTF-8")
@@ -100,6 +99,12 @@ module JekyllTitlesFromHeadings
100
99
  end
101
100
  end
102
101
 
102
+ def strip_title_excerpt?(document)
103
+ document.is_a?(Jekyll::Document) &&
104
+ document.collection.label == "posts" &&
105
+ document.generate_excerpt?
106
+ end
107
+
103
108
  def collections?
104
109
  option(COLLECTIONS_KEY) == true
105
110
  end
@@ -111,7 +116,14 @@ module JekyllTitlesFromHeadings
111
116
  end
112
117
 
113
118
  def strip_title!(document)
114
- document.content.gsub!(TITLE_REGEX, "") if document.content
119
+ if document.content
120
+ document.content = document.content.gsub(TITLE_REGEX, "").strip
121
+ strip_title_excerpt!(document) if strip_title_excerpt?(document)
122
+ end
123
+ end
124
+
125
+ def strip_title_excerpt!(document)
126
+ document.data["excerpt"] = Jekyll::Excerpt.new(document)
115
127
  end
116
128
 
117
129
  def filters
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllTitlesFromHeadings
4
- VERSION = "0.5.1".freeze
4
+ VERSION = "0.5.3"
5
5
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-titles-from-headings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-06 00:00:00.000000000 Z
11
+ date: 2019-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.3'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.3'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rspec
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +50,28 @@ dependencies:
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '0.43'
53
+ version: '0.71'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.71'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rubocop-jekyll
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.10'
48
68
  type: :development
49
69
  prerelease: false
50
70
  version_requirements: !ruby/object:Gem::Requirement
51
71
  requirements:
52
72
  - - "~>"
53
73
  - !ruby/object:Gem::Version
54
- version: '0.43'
74
+ version: '0.10'
55
75
  description:
56
76
  email:
57
77
  - ben.balter@github.com
@@ -85,8 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
105
  - !ruby/object:Gem::Version
86
106
  version: '0'
87
107
  requirements: []
88
- rubyforge_project:
89
- rubygems_version: 2.7.5
108
+ rubygems_version: 3.0.6
90
109
  signing_key:
91
110
  specification_version: 4
92
111
  summary: A Jekyll plugin to pull the page title from the first Markdown heading when