Created
May 17, 2013 16:41
-
-
Save blockloop/5600341 to your computer and use it in GitHub Desktop.
Plain text Jekyll excerpt plugin. How it works: - Reads markdown into html - Converts the html to plain text - grabs the first X characters (default 160) - adds to the post (use post.excerpt) Reasons I wrote it: - supports the ability to add your own excerpt in the front matter (does not override) - creates text-only excerpt for a footer message…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'maruku' | |
require 'nokogiri' | |
module Jekyll | |
class ExcerptBuilder < Generator | |
safe true | |
priority :high | |
EXCERPT_LENGTH = 160 | |
def generate(site) | |
site.posts.map! do |post| | |
unless post.data['excerpt'] | |
html = ::Maruku.new(post.content).to_html | |
excerpt = ::Nokogiri::HTML(html).text[0..EXCERPT_LENGTH].gsub(/\n/, ' ') | |
post.data['excerpt'] = excerpt.strip | |
end | |
post.data['excerpt'] += '…' | |
post | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment