lifer 0.10.0 → 0.10.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: f1d33c1f633f27b80005a2e2e7c1919f43d86a5fdba9f12523dd4dcdb4e47422
4
- data.tar.gz: 37927e9a39b49363ee0de3f34294c4e8ccf82b83a7a73b8d86ebc1bae8243947
3
+ metadata.gz: '0628d28de38f509eb51cc2d2dd65cb794fe3e4e46239bbf11c82decfd28f1d5d'
4
+ data.tar.gz: dcb12aba6fa318f57c3224fed97a6a28233b847ca7399f321c855a739a44543b
5
5
  SHA512:
6
- metadata.gz: db511f0ace1e617851b7e4de0fd12f9a615c283db318d3c05013cdadbae40ab89cd6be06bc429f4c443caf5d1c67f1d385276f4596788eadbfe3d22916e9c20d
7
- data.tar.gz: 917d189530c40b4c15fb57a9d1bfce28a809b00fd07267b5a2485997adcb8c3e557dcf242def3a515297b908a5000902a1e7fcbe4bff29240791a88681b2fa1f
6
+ metadata.gz: 0d74bf3c194492fec78a17ca70045dd107a40ddf33cf154243b33bb0a9d13876b1b0bdc4ea6bbf40c15984bf6a2a86dc898ed55939c9e222cf86d4cadd73b8d3
7
+ data.tar.gz: af6d75bd7b875807c8fc74c69b04c5849d0d5e787a4ae6516f8af5189eb22e668d249660f741802b90209d9c2697909ae69400f364fc80a7dfe703a69490bb78
data/CHANGELOG.md CHANGED
@@ -1,9 +1,31 @@
1
1
  ## Next
2
2
 
3
+ ## v0.10.2
4
+
5
+ This release resolves another bug in `Entry#summary` causing entries without
6
+ full-stops within the truncation threshold to not be truncated with a "..."
7
+ properly.
8
+
9
+ ## v0.10.1
10
+
11
+ This release resolves a bug with `Entry#summary`. When I originally implemented
12
+ summaries as first paragraphs, I didn't realize that using the Kramdown
13
+ representation of the document would result in special characters being
14
+ transformed badly:
15
+
16
+ In the ldquorealmrdquo where dreams dance
17
+
18
+ This change ensures that we don't end up with trash like that, or other HTML
19
+ trash.
20
+
21
+ The summary is meant to be ideal for things like `<meta>` description tags,
22
+ which should only contain plain text.
23
+
24
+
3
25
  ## v0.10.0
4
26
 
5
- These commits collect work to let all layout files (either Liquid or ERB files)
6
- provide a reference to parent, or "root", layout files that should wrap the via
27
+ This release lets all layout files (either Liquid or ERB files) provide a
28
+ reference to parent, or "root", layout files that should wrap the via
7
29
  frontmatter.
8
30
 
9
31
  Previously, we did this for Liquid layouts using the custom `layout` tag. But
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lifer (0.10.0)
4
+ lifer (0.10.2)
5
5
  i18n (< 2)
6
6
  kramdown (~> 2.4)
7
7
  liquid (~> 5.6, < 6)
data/README.md CHANGED
@@ -107,6 +107,10 @@ Then, build and push the gem to RubyGems:
107
107
  $ gem build
108
108
  $ gem push lifer-<new_version_without_the_v_prefix>.gem
109
109
 
110
+ And ensure that the release commit(s) are on the `main` branch:
111
+
112
+ $ git push origin main
113
+
110
114
  ## Contributing
111
115
 
112
116
  I'm not currently accepting unsolicited contributions to Lifer. I'm still
@@ -30,15 +30,17 @@ class Lifer::Entry::Markdown < Lifer::Entry
30
30
  def summary
31
31
  return super if super
32
32
 
33
- return if first_paragraph.nil?
34
- return first_paragraph if first_paragraph.length <= TRUNCATION_THRESHOLD
33
+ return if raw_first_paragraph_text.nil?
35
34
 
36
- truncated_paragraph = first_paragraph[0..TRUNCATION_THRESHOLD]
37
- if (index_of_final_fullstop = truncated_paragraph.rindex ". ")
38
- truncated_paragraph[0..index_of_final_fullstop]
39
- else
40
- "%s..." % truncated_paragraph
41
- end
35
+ text = raw_first_paragraph_text
36
+ return text if text.length <= TRUNCATION_THRESHOLD
37
+
38
+ text = text[0..TRUNCATION_THRESHOLD]
39
+
40
+ # Index of the fullstop from the last complete sentence in the truncated
41
+ # text.
42
+ last_fullstop_index = text.rindex /(\.) /
43
+ last_fullstop_index ? text[0..last_fullstop_index] : "%s..." % text
42
44
  end
43
45
 
44
46
  # The title or a default title.
@@ -57,7 +59,7 @@ class Lifer::Entry::Markdown < Lifer::Entry
57
59
  #
58
60
  # @return [String] The HTML for the body of the entry.
59
61
  def to_html
60
- Kramdown::Document.new(body).to_html
62
+ @to_html ||= Kramdown::Document.new(body).to_html
61
63
  end
62
64
 
63
65
  private
@@ -75,25 +77,20 @@ class Lifer::Entry::Markdown < Lifer::Entry
75
77
  end.uniq
76
78
  end
77
79
 
78
- # Using Kramdown we can detect the first paragraph of the entry.
80
+ # Detects the raw paragraph text from the entry.
79
81
  #
82
+ # @fixme It would be easier and less error prone to do this with Nokogiri. But
83
+ # we currently don't need the dependency for any other reason, so let's
84
+ # defer adding it until then.
80
85
  # @private
81
- def first_paragraph
82
- @first_paragraph ||=
83
- kramdown_paragraph_text(
84
- Kramdown::Document.new(body).root
85
- .children
86
- .detect { |child| child.type == :p }
87
- )
88
- end
86
+ def raw_first_paragraph_text
87
+ paragraphs = to_html.match %r{<p[^>]*>(.*?)</p>}im
88
+ paragraph = paragraphs ? paragraphs[1].strip : nil
89
89
 
90
- # @private
91
- def kramdown_paragraph_text(kramdown_element)
92
- return if kramdown_element.nil?
90
+ return unless paragraph
93
91
 
94
- kramdown_element.children
95
- .flat_map { |child| child.value || kramdown_paragraph_text(child) }
96
- .join
97
- .gsub(/\n/, " ")
92
+ paragraph = paragraph.gsub /<\/?[^>]*>/, ""
93
+ paragraph = CGI.unescapeHTML paragraph
94
+ paragraph.gsub(/[\s\n\t]+/, " ").strip
98
95
  end
99
96
  end
data/lib/lifer/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lifer
2
- VERSION = "0.10.0"
2
+ VERSION = "0.10.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lifer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - benjamin wil
@@ -210,8 +210,8 @@ licenses:
210
210
  - MIT
211
211
  metadata:
212
212
  allowed_push_host: https://rubygems.org
213
- homepage_uri: https://github.com/benjaminwil/lifer/blob/v0.10.0/README.md
214
- source_code_uri: https://github.com/benjaminwil/lifer/tree/v0.10.0
213
+ homepage_uri: https://github.com/benjaminwil/lifer/blob/v0.10.2/README.md
214
+ source_code_uri: https://github.com/benjaminwil/lifer/tree/v0.10.2
215
215
  changelog_uri: https://github.com/benjaminwil/lifer/blob/main/CHANGELOG.md
216
216
  post_install_message:
217
217
  rdoc_options: []