Skip to content

Commit

Permalink
Support octopress-hooks and octopress-date-format home-assistant#1622
Browse files Browse the repository at this point in the history
  • Loading branch information
imathis committed Aug 12, 2014
1 parent 18784a4 commit 73e5404
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 57 deletions.
18 changes: 4 additions & 14 deletions .themes/classic/source/_includes/post/date.html
Original file line number Diff line number Diff line change
@@ -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 %}
2 changes: 1 addition & 1 deletion .themes/classic/source/_layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<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 %}
Expand Down
1 change: 0 additions & 1 deletion .themes/classic/source/atom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
layout: nil
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
Expand Down
3 changes: 1 addition & 2 deletions .themes/classic/source/robots.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
layout: nil
---
User-agent: *
Disallow:

Sitemap: {{ site.url }}/sitemap.xml
Sitemap: {{ site.url }}/sitemap.xml
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 3 additions & 4 deletions plugins/backtick_code_block.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,15 +25,15 @@ def render_code_block(input)
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"
raw = "``` #{@options.sub('-raw', '')}\n"
raw += str
raw += "\n```\n"
else
code = highlight(str, @lang)
code = HighlightCode::highlight(str, @lang)
"<figure class='code'>#{@caption}#{code}</figure>"
end
end
Expand Down
8 changes: 3 additions & 5 deletions plugins/code_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
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)
Expand Down Expand Up @@ -79,11 +77,11 @@ def render(context)
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
Expand Down
6 changes: 2 additions & 4 deletions plugins/include_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
module Jekyll

class IncludeCodeTag < Liquid::Tag
include HighlightCode
include TemplateWrapper
def initialize(tag_name, markup, tokens)
@title = nil
@file = nil
Expand Down Expand Up @@ -62,8 +60,8 @@ def render(context)
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
Expand Down
44 changes: 25 additions & 19 deletions plugins/octopress_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,38 @@
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
Expand Down
6 changes: 3 additions & 3 deletions plugins/pygments_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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'
Expand All @@ -15,7 +15,7 @@ def highlight(str, lang)
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)
Expand All @@ -33,7 +33,7 @@ def pygments(code, lang)
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|
Expand Down
4 changes: 2 additions & 2 deletions plugins/raw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 73e5404

Please sign in to comment.