mirror of
https://github.com/WatchOutNewsAgency/wona.github.com.git
synced 2026-01-01 01:16:26 +00:00
1. Added Category support
2. Designed blog archives pages 3. Restructured Sass 4. Added Categories to rake post metadata 5. Some general style improvements
This commit is contained in:
@ -1,65 +0,0 @@
|
||||
module Jekyll
|
||||
|
||||
class CategoryIndex < Page
|
||||
def initialize(site, base, dir, category)
|
||||
@site = site
|
||||
@base = base
|
||||
@dir = dir
|
||||
@name = 'index.html'
|
||||
|
||||
self.process(@name)
|
||||
self.read_yaml(File.join(base, '_layouts'), 'category_index.html')
|
||||
self.data['category'] = category
|
||||
|
||||
category_title_prefix = site.config['category_title_prefix'] || 'Category: '
|
||||
self.data['title'] = "#{category_title_prefix}#{category}"
|
||||
end
|
||||
end
|
||||
|
||||
class CategoryList < Page
|
||||
def initialize(site, base, dir, categories)
|
||||
@site = site
|
||||
@base = base
|
||||
@dir = dir
|
||||
@name = 'index.html'
|
||||
|
||||
self.process(@name)
|
||||
self.read_yaml(File.join(base, '_layouts'), 'category_list.html')
|
||||
self.data['categories'] = categories
|
||||
end
|
||||
end
|
||||
|
||||
class CategoryGenerator < Generator
|
||||
safe true
|
||||
|
||||
def generate(site)
|
||||
if site.layouts.key? 'category_index'
|
||||
dir = site.config['category_dir'] || 'categories'
|
||||
site.categories.keys.each do |category|
|
||||
write_category_index(site, File.join(dir, category.gsub(/\s/, "-").gsub(/[^\w-]/, '').downcase), category)
|
||||
end
|
||||
end
|
||||
|
||||
if site.layouts.key? 'category_list'
|
||||
dir = site.config['category_dir'] || 'categories'
|
||||
write_category_list(site, dir, site.categories.keys.sort)
|
||||
end
|
||||
end
|
||||
|
||||
def write_category_index(site, dir, category)
|
||||
index = CategoryIndex.new(site, site.source, dir, category)
|
||||
index.render(site.layouts, site.site_payload)
|
||||
index.write(site.dest)
|
||||
site.static_files << index
|
||||
end
|
||||
|
||||
def write_category_list(site, dir, categories)
|
||||
index = CategoryList.new(site, site.source, dir, categories)
|
||||
index.render(site.layouts, site.site_payload)
|
||||
index.write(site.dest)
|
||||
site.static_files << index
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -1,13 +1,7 @@
|
||||
#custom filters for Octopress
|
||||
|
||||
module OctopressFilters
|
||||
def auto_exerpt(input, url, url_text="Read more …")
|
||||
if input.index(/<!--\s?more\s?-->/i)
|
||||
input.split(/<!--\s?more\s?-->/i)[0] + "<p><a rel='full-article' href='#{url}'>#{url_text}</a></p>"
|
||||
else
|
||||
input
|
||||
end
|
||||
end
|
||||
# Used on the blog index to split posts on the <!--more--> marker
|
||||
def exerpt(input)
|
||||
if input.index(/<!--\s*more\s*-->/i)
|
||||
input.split(/<!--\s*more\s*-->/i)[0]
|
||||
@ -15,33 +9,56 @@ module OctopressFilters
|
||||
input
|
||||
end
|
||||
end
|
||||
|
||||
# Summary is used on the Archive pages to return the first block of content from a post.
|
||||
def summary(input)
|
||||
if input.index(/\n\n/)
|
||||
input.split(/\n\n/)[0]
|
||||
else
|
||||
input
|
||||
end
|
||||
end
|
||||
|
||||
# Replaces relative urls with full urls
|
||||
def full_urls(input, url='')
|
||||
input.gsub /(\s+(href|src)\s*=\s*["|']{1})(\/[^\"'>]+)/ do
|
||||
$1+url+$3
|
||||
end
|
||||
end
|
||||
|
||||
# Returns a url without the http:// for use in as a search modifier eg. 'search terms site:website.com'
|
||||
def search_url(input)
|
||||
input.gsub /(http:\/\/)(\S+)/ do
|
||||
input.gsub /(https?:\/\/)(\S+)/ do
|
||||
$2
|
||||
end
|
||||
end
|
||||
|
||||
# replaces primes with smartquotes using RubyPants
|
||||
def smart_quotes(input)
|
||||
require 'rubypants'
|
||||
RubyPants.new(input).to_html
|
||||
end
|
||||
|
||||
# Returns a title cased string based on John Gruber's title case http://daringfireball.net/2008/08/title_case_update
|
||||
def titlecase(input)
|
||||
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>"
|
||||
@ -54,10 +71,5 @@ module OctopressFilters
|
||||
end
|
||||
end
|
||||
end
|
||||
#YearlyPost = Struct.new('YearlyPost', :year, :posts)
|
||||
def yearly_posts(site)
|
||||
#site.posts.reverse.group_by { |p| p.date.strftime("%Y") }.map { |k,v| YearlyPost.new(k,v) }
|
||||
site
|
||||
end
|
||||
end
|
||||
Liquid::Template.register_filter OctopressFilters
|
||||
|
||||
Reference in New Issue
Block a user