Skip to content

Commit e4f3368

Browse files
mkasberggeerlingguy
authored andcommitted
Replace smart_truncate with Gem
In d86e1a2, we introduced post previews on the homepage (so you get a preview on the homepage, but have to visit the post itself to continue reading). To do so, we added a Jekyll "plugin" which is actually just a single ruby file -- `smart_truncate.rb`. (This plugin is open source and came from https://yingtongli.me/git/smart_truncate/tree/smart_truncate.rb.) That plugin works, but I was disappointed there wasn't an easier way to do this (a built-in Jekyll feature or a plugin distributed as a gem). So, I built my own [jekyll_html_truncatewords](https://github.com/mkasberg/jekyll_html_trunctewords) plugin. This plugin is distributed as a gem and has better unit test coverage than the `smart_truncate.rb` file (which had no apparent unit tests), so I feel better about using it. My intent is to make this a reliable and well-maintained Jekyll plugin for use here and for anyone else who wants to use it. In this commit, I remove the `_plugins/smart_truncate.rb` file and replace it with my `jekyll_html_truncatewords` gem. The functionality is identical, and I spot-checked several rendered HTML pages which look identical with either plugin. The end result is that we don't have to maintain a copy of that `smart_truncate.rb` file and instead we can update the gem like we would for any other Jekyll gem/plugin.
1 parent aaf0e7e commit e4f3368

4 files changed

Lines changed: 14 additions & 150 deletions

File tree

Gemfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ source 'https://rubygems.org/'
33
gem 'jekyll', '~> 4.1'
44
gem 'jekyll-redirect-from', '~> 0.16'
55
gem 'jekyll-paginate', '~> 1.1'
6-
gem 'nokogiri', '~> 1.10'
6+
7+
group :jekyll_plugins do
8+
gem 'jekyll_html_truncatewords', '~> 0.1.2'
9+
end

Gemfile.lock

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ GEM
3636
sassc (> 2.0.1, < 3.0)
3737
jekyll-watch (2.2.1)
3838
listen (~> 3.0)
39+
jekyll_html_truncatewords (0.1.2)
40+
liquid
41+
nokogiri
3942
kramdown (2.3.0)
4043
rexml
4144
kramdown-parser-gfm (1.1.0)
@@ -45,12 +48,14 @@ GEM
4548
rb-fsevent (~> 0.10, >= 0.10.3)
4649
rb-inotify (~> 0.9, >= 0.9.10)
4750
mercenary (0.4.0)
48-
mini_portile2 (2.4.0)
49-
nokogiri (1.10.10)
50-
mini_portile2 (~> 2.4.0)
51+
mini_portile2 (2.5.0)
52+
nokogiri (1.11.1)
53+
mini_portile2 (~> 2.5.0)
54+
racc (~> 1.4)
5155
pathutil (0.16.2)
5256
forwardable-extended (~> 2.6)
5357
public_suffix (4.0.6)
58+
racc (1.5.2)
5459
rb-fsevent (0.10.4)
5560
rb-inotify (0.10.1)
5661
ffi (~> 1.0)
@@ -70,7 +75,7 @@ DEPENDENCIES
7075
jekyll (~> 4.1)
7176
jekyll-paginate (~> 1.1)
7277
jekyll-redirect-from (~> 0.16)
73-
nokogiri (~> 1.10)
78+
jekyll_html_truncatewords (~> 0.1.2)
7479

7580
BUNDLED WITH
7681
2.1.4

_includes/post_preview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ <h2>
77
</h2>
88

99
<div class="post-content" itemprop="articleBody">
10-
{{ post.content | markdownify | smart_truncate: site.post_preview_words }}
10+
{{ post.content | markdownify | html_truncatewords: site.post_preview_words }}
1111
<a href="{{ post.url | prepend: site.baseurl }}">Continue reading</a>
1212
</div>
1313

_plugins/smart_truncate.rb

Lines changed: 0 additions & 144 deletions
This file was deleted.

0 commit comments

Comments
 (0)