aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--plugins/date.rb98
-rw-r--r--plugins/gist_tag.rb8
-rw-r--r--plugins/octopress_filters.rb57
-rw-r--r--plugins/preview_unpublished.rb48
-rw-r--r--plugins/pygments_code.rb4
-rw-r--r--plugins/titlecase.rb4
6 files changed, 187 insertions, 32 deletions
diff --git a/plugins/date.rb b/plugins/date.rb
new file mode 100644
index 00000000..b864f3e9
--- /dev/null
+++ b/plugins/date.rb
@@ -0,0 +1,98 @@
+module Octopress
+ module Date
+
+ # Returns a datetime if the input is a string
+ def datetime(date)
+ if date.class == String
+ date = Time.parse(date)
+ end
+ date
+ end
+
+ # Returns an ordidinal date eg July 22 2007 -> July 22nd 2007
+ def ordinalize(date)
+ date = datetime(date)
+ "#{date.strftime('%b')} #{ordinal(date.strftime('%e').to_i)}, #{date.strftime('%Y')}"
+ end
+
+ # Returns an ordinal number. 13 -> 13th, 21 -> 21st etc.
+ def ordinal(number)
+ if (11..13).include?(number.to_i % 100)
+ "#{number}<span>th</span>"
+ else
+ case number.to_i % 10
+ when 1; "#{number}<span>st</span>"
+ when 2; "#{number}<span>nd</span>"
+ when 3; "#{number}<span>rd</span>"
+ else "#{number}<span>th</span>"
+ end
+ end
+ end
+
+ # Formats date either as ordinal or by given date format
+ # Adds %o as ordinal representation of the day
+ def format_date(date, format)
+ date = datetime(date)
+ if format.nil? || format.empty? || format == "ordinal"
+ date_formatted = ordinalize(date)
+ else
+ date_formatted = date.strftime(format)
+ date_formatted.gsub!(/%o/, ordinal(date.strftime('%e').to_i))
+ end
+ date_formatted
+ end
+
+ end
+end
+
+
+module Jekyll
+
+ class Post
+ include Octopress::Date
+
+ # Convert this post into a Hash for use in Liquid templates.
+ #
+ # Returns <Hash>
+ def to_liquid
+ date_format = self.site.config['date_format']
+ self.data.deep_merge({
+ "title" => self.data['title'] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '),
+ "url" => self.url,
+ "date" => self.date,
+ # Monkey patch
+ "date_formatted" => format_date(self.date, date_format),
+ "updated_formatted" => self.data.has_key?('updated') ? format_date(self.data['updated'], date_format) : nil,
+ "id" => self.id,
+ "categories" => self.categories,
+ "next" => self.next,
+ "previous" => self.previous,
+ "tags" => self.tags,
+ "content" => self.content })
+ end
+ end
+
+ class Page
+ include Octopress::Date
+
+ # Initialize a new Page.
+ #
+ # site - The Site object.
+ # base - The String path to the source.
+ # dir - The String path between the source and the file.
+ # name - The String filename of the file.
+ def initialize(site, base, dir, name)
+ @site = site
+ @base = base
+ @dir = dir
+ @name = name
+
+ self.process(name)
+ self.read_yaml(File.join(base, dir), name)
+ # Monkey patch
+ date_format = self.site.config['date_format']
+ self.data['date_formatted'] = format_date(self.data['date'], date_format) if self.data.has_key?('date')
+ self.data['updated_formatted'] = format_date(self.data['updated'], date_format) if self.data.has_key?('updated')
+ end
+ end
+end \ No newline at end of file
diff --git a/plugins/gist_tag.rb b/plugins/gist_tag.rb
index ac5ee3c6..74dd3b37 100644
--- a/plugins/gist_tag.rb
+++ b/plugins/gist_tag.rb
@@ -71,7 +71,13 @@ module Jekyll
def get_gist_from_web(gist, file)
gist_url = get_gist_url_for gist, file
raw_uri = URI.parse gist_url
- https = Net::HTTP.new raw_uri.host, raw_uri.port
+ proxy = ENV['http_proxy']
+ if proxy
+ proxy_uri = URI.parse(proxy)
+ https = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port).new raw_uri.host, raw_uri.port
+ else
+ https = Net::HTTP.new raw_uri.host, raw_uri.port
+ end
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new raw_uri.request_uri
diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb
index ef8c1fb2..a5bb235c 100644
--- a/plugins/octopress_filters.rb
+++ b/plugins/octopress_filters.rb
@@ -2,6 +2,7 @@
require './plugins/backtick_code_block'
require './plugins/post_filters'
require './plugins/raw'
+require './plugins/date'
require 'rubypants'
module OctopressFilters
@@ -33,6 +34,8 @@ end
module OctopressLiquidFilters
+ include Octopress::Date
+
# Used on the blog index to split posts on the <!--more--> marker
def excerpt(input)
if input.index(/<!--\s*more\s*-->/i)
@@ -76,6 +79,33 @@ module OctopressLiquidFilters
end
end
+ # Improved version of Liquid's truncate:
+ # - Doesn't cut in the middle of a word.
+ # - Uses typographically correct ellipsis (…) insted of '...'
+ def truncate(input, length)
+ if input.length > length && input[0..(length-1)] =~ /(.+)\b.+$/im
+ $1.strip + ' &hellip;'
+ else
+ input
+ end
+ end
+
+ # Improved version of Liquid's truncatewords:
+ # - Uses typographically correct ellipsis (…) insted of '...'
+ def truncatewords(input, length)
+ truncate = input.split(' ')
+ if truncate.length > length
+ truncate[0..length-1].join(' ').strip + ' &hellip;'
+ else
+ input
+ end
+ end
+
+ # Condenses multiple spaces and tabs into a single space
+ def condense_spaces(input)
+ input.gsub(/\s{2,}/, ' ')
+ end
+
# Removes trailing forward slash from a string for easily appending url segments
def strip_slash(input)
if input =~ /(.+)\/$|^\/$/
@@ -96,33 +126,6 @@ module OctopressLiquidFilters
input.titlecase
end
- # Returns a datetime if the input is a string
- def datetime(date)
- if date.class == String
- date = Time.parse(date)
- end
- date
- end
-
- # Returns an ordidinal date eg July 22 2007 -> July 22nd 2007
- def ordinalize(date)
- date = datetime(date)
- "#{date.strftime('%b')} #{ordinal(date.strftime('%e').to_i)}, #{date.strftime('%Y')}"
- end
-
- # Returns an ordinal number. 13 -> 13th, 21 -> 21st etc.
- def ordinal(number)
- if (11..13).include?(number.to_i % 100)
- "#{number}<span>th</span>"
- else
- case number.to_i % 10
- when 1; "#{number}<span>st</span>"
- when 2; "#{number}<span>nd</span>"
- when 3; "#{number}<span>rd</span>"
- else "#{number}<span>th</span>"
- end
- end
- end
end
Liquid::Template.register_filter OctopressLiquidFilters
diff --git a/plugins/preview_unpublished.rb b/plugins/preview_unpublished.rb
new file mode 100644
index 00000000..321ffd6f
--- /dev/null
+++ b/plugins/preview_unpublished.rb
@@ -0,0 +1,48 @@
+# Monkeypatch for Jekyll
+# Introduce distinction between preview/productive site generation
+# so posts with YAML attribute `published: false` can be previewed
+# on localhost without being published to the productive environment.
+
+module Jekyll
+
+ class Site
+ # Read all the files in <source>/<dir>/_posts and create a new Post
+ # object with each one.
+ #
+ # dir - The String relative path of the directory to read.
+ #
+ # Returns nothing.
+ def read_posts(dir)
+ base = File.join(self.source, dir, '_posts')
+ return unless File.exists?(base)
+ entries = Dir.chdir(base) { filter_entries(Dir['**/*']) }
+
+ # first pass processes, but does not yet render post content
+ entries.each do |f|
+ if Post.valid?(f)
+ post = Post.new(self, self.source, dir, f)
+
+ # Monkeypatch:
+ # On preview environment (localhost), publish all posts
+ if ENV.has_key?('OCTOPRESS_ENV') && ENV['OCTOPRESS_ENV'] == 'preview' && post.data.has_key?('published') && post.data['published'] == false
+ post.published = true
+ # Set preview mode flag (if necessary), `rake generate` will check for it
+ # to prevent pushing preview posts to productive environment
+ File.open(".preview-mode", "w") {}
+ end
+
+ if post.published && (self.future || post.date <= self.time)
+ self.posts << post
+ post.categories.each { |c| self.categories[c] << post }
+ post.tags.each { |c| self.tags[c] << post }
+ end
+ end
+ end
+
+ self.posts.sort!
+
+ # limit the posts if :limit_posts option is set
+ self.posts = self.posts[-limit_posts, limit_posts] if limit_posts
+ end
+ end
+end \ No newline at end of file
diff --git a/plugins/pygments_code.rb b/plugins/pygments_code.rb
index c009df9f..1676a3e0 100644
--- a/plugins/pygments_code.rb
+++ b/plugins/pygments_code.rb
@@ -21,11 +21,11 @@ module HighlightCode
if File.exist?(path)
highlighted_code = File.read(path)
else
- highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html')
+ highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
File.open(path, 'w') {|f| f.print(highlighted_code) }
end
else
- highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html')
+ highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
end
highlighted_code
end
diff --git a/plugins/titlecase.rb b/plugins/titlecase.rb
index 3ad39b1f..7648932c 100644
--- a/plugins/titlecase.rb
+++ b/plugins/titlecase.rb
@@ -11,8 +11,8 @@ class String
# capitalize first and last words
x.first.to_s.smart_capitalize!
x.last.to_s.smart_capitalize!
- # small words after colons or periods are capitalized
- x.join(" ").gsub(/(:|\.)\s?(\W*#{small_words.join("|")}\W*)\s/) { "#{$1} #{$2.smart_capitalize} " }
+ # small words are capitalized after colon, period, exclamation mark, question mark
+ x.join(" ").gsub(/(:|\.|!|\?)\s?(\W*#{small_words.join("|")}\W*)\s/) { "#{$1} #{$2.smart_capitalize} " }
end
def titlecase!