Skip to content

Instantly share code, notes, and snippets.

@yetti
Created March 20, 2013 13:18
Show Gist options
  • Save yetti/5204572 to your computer and use it in GitHub Desktop.
Save yetti/5204572 to your computer and use it in GitHub Desktop.
Provides a {% lead %} block to define lead-in text. Adds text inside block to post data's 'lead' field and wraps text inside a paragraph with a style class for customisation.
# Title: Lead-in Text Block
# Author: Yetrina Battad (http://aether.nu)
# Description: Provides a block for lead-in text. Inspired by this plugin: http://blog.darkrefraction.com/2012/jekyll-excerpt-plugin.html
#
# Captures the text between the 'lead' block and places it in the post data's 'lead' property.
# Also wraps the text between the 'lead' tags into a paragraph with CSS hook for styling.
#
# Usage:
# {% lead %}
# Wheeee!
# {% endlead %}
#
require 'nokogiri'
require 'rdiscount'
module Jekyll
class AetherLeadIn < Liquid::Block
def render(context)
id = context["page"]["id"]
site = context.registers[:site]
output = ''
site.posts.each do |post|
if post.id && post.id == id
post.data["lead"] = super
break
end
end
html = RDiscount.new(super).to_html
paragraphize(html)
end
def paragraphize(input)
"<p class=\"lead\">#{input.strip_html_tags(false)}</p>"
end
end
end
Liquid::Template.register_tag('lead', Jekyll::AetherLeadIn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment