Support octopress-hooks and octopress-date-format #1622

main
Brandon Mathis 10 years ago
parent 18784a4cb0
commit 73e540409c

@ -1,15 +1,5 @@
{% capture date %}{{ page.date }}{{ post.date }}{% endcapture %}
{% capture date_formatted %}{{ page.date_formatted }}{{ post.date_formatted }}{% endcapture %}
{% capture has_date %}{{ date | size }}{% endcapture %}
{% if page.date %}{% capture time %}{{ page.date_time_html }}{% endcapture %}{% endif %}
{% if post.date %}{% capture time %}{{ post.date_time_html }}{% endcapture %}{% endif %}
{% capture updated %}{{ page.updated }}{{ post.updated }}{% endcapture %}
{% capture updated_formatted %}{{ page.updated_formatted }}{{ post.updated_formatted }}{% endcapture %}
{% capture was_updated %}{{ updated | size }}{% endcapture %}
{% if has_date != '0' %}
{% capture time %}<time datetime="{{ date | datetime | date_to_xmlschema }}" pubdate{% if updated %} data-updated="true"{% endif %}>{{ date_formatted }}</time>{% endcapture %}
{% endif %}
{% if was_updated != '0' %}
{% capture updated %}<time datetime="{{ updated | datetime | date_to_xmlschema }}" class="updated">Updated {{ updated_formatted }}</time>{% endcapture %}
{% else %}{% assign updated = false %}{% endif %}
{% if page.updated %}{% capture updated %}{{ page.date_time_updated_html }}{% endcapture %}{% endif %}
{% if post.updated %}{% capture updated %}{{ post.date_time_updated_html }}{% endcapture %}{% endif %}

@ -9,7 +9,7 @@ single: true
<footer>
<p class="meta">
{% include post/author.html %}
{% include post/date.html %}{% if updated %}{{ updated }}{% else %}{{ time }}{% endif %}
{% include post/date.html %}{{ time }}{% if updated %} {{ updated }}{% endif %}
{% include post/categories.html %}
</p>
{% unless page.sharing == false %}

@ -1,5 +1,4 @@
---
layout: nil
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

@ -1,7 +1,6 @@
---
layout: nil
---
User-agent: *
Disallow:
Sitemap: {{ site.url }}/sitemap.xml
Sitemap: {{ site.url }}/sitemap.xml

@ -3,8 +3,8 @@ source "https://rubygems.org"
group :development do
gem 'rake', '~> 10.0'
gem 'jekyll', '~> 2.0'
gem 'jekyll-page-hooks', '~> 1.2'
gem 'jekyll-date-format', '~> 1.0'
gem 'octopress-hooks', '~> 2.2'
gem 'octopress-date-format', '~> 2.0'
gem 'jekyll-sitemap'
gem 'rdiscount', '~> 2.0'
gem 'RedCloth', '~> 4.2.9'

@ -1,10 +1,9 @@
require './plugins/pygments_code'
module BacktickCodeBlock
include HighlightCode
AllOptions = /([^\s]+)\s+(.+?)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/i
LangCaption = /([^\s]+)\s*(.+)?/i
def render_code_block(input)
def self.render_code_block(input)
@options = nil
@caption = nil
@lang = nil
@ -26,7 +25,7 @@ module BacktickCodeBlock
str = str.gsub(/^( {4}|\t)/, '')
end
if @lang.nil? || @lang == 'plain'
code = tableize_code(str.gsub('<','&lt;').gsub('>','&gt;'))
code = HighlightCode::tableize_code(str.gsub('<','&lt;').gsub('>','&gt;'))
"<figure class='code'>#{@caption}#{code}</figure>"
else
if @lang.include? "-raw"
@ -34,7 +33,7 @@ module BacktickCodeBlock
raw += str
raw += "\n```\n"
else
code = highlight(str, @lang)
code = HighlightCode::highlight(str, @lang)
"<figure class='code'>#{@caption}#{code}</figure>"
end
end

@ -47,8 +47,6 @@ require './plugins/raw'
module Jekyll
class CodeBlock < Liquid::Block
include HighlightCode
include TemplateWrapper
CaptionUrlTitle = /(\S[\S\s]*)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/i
Caption = /(\S[\S\s]*)/
def initialize(tag_name, markup, tokens)
@ -79,11 +77,11 @@ module Jekyll
source = "<figure class='code'>"
source += @caption if @caption
if @filetype
source += "#{highlight(code, @filetype)}</figure>"
source += "#{HighlightCode::highlight(code, @filetype)}</figure>"
else
source += "#{tableize_code(code.lstrip.rstrip.gsub(/</,'&lt;'))}</figure>"
source += "#{HighlightCode::tableize_code(code.lstrip.rstrip.gsub(/</,'&lt;'))}</figure>"
end
source = safe_wrap(source)
source = TemplateWrapper::safe_wrap(source)
source = context['pygments_prefix'] + source if context['pygments_prefix']
source = source + context['pygments_suffix'] if context['pygments_suffix']
source

@ -27,8 +27,6 @@ require 'pathname'
module Jekyll
class IncludeCodeTag < Liquid::Tag
include HighlightCode
include TemplateWrapper
def initialize(tag_name, markup, tokens)
@title = nil
@file = nil
@ -62,8 +60,8 @@ module Jekyll
title = @title ? "#{@title} (#{file.basename})" : file.basename
url = "/#{code_dir}/#{@file}"
source = "<figure class='code'><figcaption><span>#{title}</span> <a href='#{url}'>download</a></figcaption>\n"
source += "#{highlight(code, @filetype)}</figure>"
safe_wrap(source)
source += "#{HighlightCode::highlight(code, @filetype)}</figure>"
TemplateWrapper::safe_wrap(source)
end
end
end

@ -7,32 +7,38 @@ require './plugins/raw'
require 'rubypants'
module OctopressFilters
include BacktickCodeBlock
include TemplateWrapper
def pre_filter(input)
input = render_code_block(input)
input.gsub /(<figure.+?>.+?<\/figure>)/m do
safe_wrap($1)
def self.pre_filter(page)
if page.ext.match('html|textile|markdown|md|haml|slim|xml')
input = BacktickCodeBlock::render_code_block(page.content)
page.content = input.gsub /(<figure.+?>.+?<\/figure>)/m do
TemplateWrapper::safe_wrap($1)
end
end
end
def post_filter(input)
input = unwrap(input)
RubyPants.new(input).to_html
def self.post_filter(page)
if page.ext.match('html|textile|markdown|md|haml|slim|xml')
input = TemplateWrapper::unwrap(page.content)
page.content = RubyPants.new(input).to_html
end
end
end
module Jekyll
class ContentFilters < PageHooks
include OctopressFilters
class PageFilters < Octopress::Hooks::Page
def pre_render(page)
OctopressFilters::pre_filter(page)
end
def post_render(page)
OctopressFilters::post_filter(page)
end
end
class PostFilters < Octopress::Hooks::Post
def pre_render(post)
if post.ext.match('html|textile|markdown|md|haml|slim|xml')
post.content = pre_filter(post.content)
end
OctopressFilters::pre_filter(post)
end
def post_render(post)
if post.ext.match('html|textile|markdown|md|haml|slim|xml')
post.content = post_filter(post.content)
end
OctopressFilters::post_filter(post)
end
end
end

@ -6,7 +6,7 @@ PYGMENTS_CACHE_DIR = File.expand_path('../../.pygments-cache', __FILE__)
FileUtils.mkdir_p(PYGMENTS_CACHE_DIR)
module HighlightCode
def highlight(str, lang)
def self.highlight(str, lang)
lang = 'ruby' if lang == 'ru'
lang = 'objc' if lang == 'm'
lang = 'perl' if lang == 'pl'
@ -15,7 +15,7 @@ module HighlightCode
tableize_code(str, lang)
end
def pygments(code, lang)
def self.pygments(code, lang)
if defined?(PYGMENTS_CACHE_DIR)
path = File.join(PYGMENTS_CACHE_DIR, "#{lang}-#{Digest::MD5.hexdigest(code)}.html")
if File.exist?(path)
@ -33,7 +33,7 @@ module HighlightCode
end
highlighted_code
end
def tableize_code (str, lang = '')
def self.tableize_code (str, lang = '')
table = '<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers">'
code = ''
str.lines.each_with_index do |line,index|

@ -3,11 +3,11 @@
# Purpose: This is useful for preventing Markdown and Textile from being too aggressive and incorrectly parsing in-line HTML.
module TemplateWrapper
# Wrap input with a <div>
def safe_wrap(input)
def self.safe_wrap(input)
"<div class='bogus-wrapper'><notextile>#{input}</notextile></div>"
end
# This must be applied after the
def unwrap(input)
def self.unwrap(input)
input.gsub /<div class='bogus-wrapper'><notextile>(.+?)<\/notextile><\/div>/m do
$1
end

Loading…
Cancel
Save