octopress 3.0.0.alpha2 → 3.0.0.alpha3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/.gitignore +15 -18
- data/Gemfile +3 -1
- data/LICENSE +20 -0
- data/README.md +66 -0
- data/Rakefile +1 -76
- data/bin/octopress +14 -58
- data/lib/octopress.rb +40 -79
- data/lib/octopress/command.rb +10 -4
- data/lib/octopress/commands/new.rb +50 -12
- data/lib/octopress/commands/publish.rb +18 -0
- data/lib/octopress/core_ext.rb +1 -0
- data/lib/octopress/draft.rb +43 -0
- data/lib/octopress/page.rb +109 -0
- data/lib/octopress/post.rb +30 -0
- data/lib/octopress/version.rb +1 -1
- data/octopress.gemspec +7 -32
- metadata +31 -437
- data/.editorconfig +0 -22
- data/.gitattributes +0 -1
- data/.powrc +0 -4
- data/.rspec +0 -5
- data/.rubocop.yml +0 -119
- data/.slugignore +0 -3
- data/.travis.yml +0 -6
- data/CHANGELOG.markdown +0 -46
- data/CONTRIBUTING.markdown +0 -17
- data/README.markdown +0 -37
- data/lib/console +0 -17
- data/lib/guard/jekyll.rb +0 -33
- data/lib/octopress/commands.rb +0 -14
- data/lib/octopress/commands/build.rb +0 -17
- data/lib/octopress/commands/build_javascripts.rb +0 -11
- data/lib/octopress/commands/build_jekyll.rb +0 -42
- data/lib/octopress/commands/build_stylesheets.rb +0 -13
- data/lib/octopress/commands/install.rb +0 -44
- data/lib/octopress/commands/scaffold.rb +0 -102
- data/lib/octopress/commands/serve.rb +0 -25
- data/lib/octopress/configuration.rb +0 -237
- data/lib/octopress/dependency_installer.rb +0 -287
- data/lib/octopress/errors.rb +0 -3
- data/lib/octopress/filters/content.rb +0 -66
- data/lib/octopress/filters/date.rb +0 -46
- data/lib/octopress/filters/post.rb +0 -175
- data/lib/octopress/filters/url.rb +0 -34
- data/lib/octopress/formatters.rb +0 -9
- data/lib/octopress/formatters/base_formatter.rb +0 -17
- data/lib/octopress/formatters/simple_formatter.rb +0 -9
- data/lib/octopress/formatters/verbose_formatter.rb +0 -9
- data/lib/octopress/generators/category_generator.rb +0 -196
- data/lib/octopress/generators/sitemap_generator.rb +0 -308
- data/lib/octopress/guardfile +0 -43
- data/lib/octopress/helpers/titlecase.rb +0 -37
- data/lib/octopress/ink.rb +0 -12
- data/lib/octopress/inquirable_string.rb +0 -12
- data/lib/octopress/installer.rb +0 -96
- data/lib/octopress/js_assets_manager.rb +0 -97
- data/lib/octopress/liquid_helpers/conditional.rb +0 -36
- data/lib/octopress/liquid_helpers/config.rb +0 -58
- data/lib/octopress/liquid_helpers/include.rb +0 -33
- data/lib/octopress/liquid_helpers/url.rb +0 -29
- data/lib/octopress/liquid_helpers/vars.rb +0 -30
- data/lib/octopress/plugin.rb +0 -33
- data/lib/octopress/rake.rb +0 -16
- data/lib/octopress/scaffold/.gitignore +0 -18
- data/lib/octopress/scaffold/site/Gemfile +0 -3
- data/lib/octopress/scaffold/site/config.ru +0 -25
- data/lib/octopress/scaffold/site/config/compass.rb +0 -27
- data/lib/octopress/scaffold/site/config/rack.rb +0 -25
- data/lib/octopress/scaffold/site/config/site.yml +0 -0
- data/lib/octopress/scaffold/site/javascripts/lib/ios-rotate-scaling-fix.js +0 -19
- data/lib/octopress/scaffold/site/javascripts/lib/jquery-1.9.1.js +0 -9598
- data/lib/octopress/scaffold/site/javascripts/lib/jquery.cookie.js +0 -93
- data/lib/octopress/scaffold/site/stylesheets/_config.scss +0 -1
- data/lib/octopress/scaffold/site/stylesheets/_style.scss +0 -1
- data/lib/octopress/scaffold/site/stylesheets/site.scss +0 -16
- data/lib/octopress/tags/assign.rb +0 -34
- data/lib/octopress/tags/capture.rb +0 -31
- data/lib/octopress/tags/config-tag.rb +0 -23
- data/lib/octopress/tags/include.rb +0 -63
- data/lib/octopress/tags/js-assets.rb +0 -23
- data/lib/octopress/tags/puts.rb +0 -39
- data/lib/octopress/tags/render-partial.rb +0 -89
- data/lib/octopress/tags/return.rb +0 -21
- data/lib/rake/clean.rake +0 -8
- data/lib/rake/clobber.rake +0 -5
- data/lib/rake/console.rake +0 -5
- data/lib/rake/deploy.rake +0 -4
- data/lib/rake/gen_deploy.rake +0 -2
- data/lib/rake/generate.rake +0 -4
- data/lib/rake/generate_only.rake +0 -14
- data/lib/rake/hygiene.rake +0 -29
- data/lib/rake/install.rake +0 -8
- data/lib/rake/integrate.rake +0 -4
- data/lib/rake/isolate.rake +0 -13
- data/lib/rake/list_drafts.rake +0 -7
- data/lib/rake/new.rake +0 -7
- data/lib/rake/new_page.rake +0 -49
- data/lib/rake/new_post.rake +0 -32
- data/lib/rake/nuke.rake +0 -4
- data/lib/rake/preview.rake +0 -4
- data/lib/rake/push.rake +0 -37
- data/lib/rake/rsync.rake +0 -20
- data/lib/rake/set_root_dir.rake +0 -35
- data/lib/rake/setup_github_pages.rake +0 -115
- data/lib/rake/watch.rake +0 -11
- data/lib/scaffold/Rakefile +0 -142
- data/lib/scaffold/plugin-name.gemspec +0 -43
- data/lib/spec/fixtures/env/defaults/classic.yml +0 -2
- data/lib/spec/fixtures/no_override/defaults/classic.yml +0 -11
- data/lib/spec/fixtures/override/defaults/classic.yml +0 -11
- data/lib/spec/fixtures/override/site.yml +0 -11
- data/lib/spec/octopress/configuration_spec.rb +0 -67
- data/lib/spec/octopress/dependency_installer_spec.rb +0 -66
- data/lib/spec/octopress/ink_spec.rb +0 -10
- data/lib/spec/octopress/octopress_spec.rb +0 -97
- data/lib/spec/spec_helper.rb +0 -22
- data/lib/spec/support/env.rb +0 -36
- data/lib/spec/support/simplecov.rb +0 -52
data/lib/octopress/errors.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path("../helpers/titlecase.rb", File.dirname(__FILE__))
|
4
|
-
module Octopress
|
5
|
-
module ContentFilters
|
6
|
-
|
7
|
-
# Escapes CDATA sections in post content
|
8
|
-
|
9
|
-
def cdata_escape(input)
|
10
|
-
input.gsub(/<!\[CDATA\[/, '<![CDATA[').gsub(/\]\]>/, ']]>')
|
11
|
-
end
|
12
|
-
|
13
|
-
# Used on the blog index to split posts on the <!--more--> marker
|
14
|
-
|
15
|
-
def excerpt(input)
|
16
|
-
if input.index(/<!--\s*more\s*-->/i)
|
17
|
-
input.split(/<!--\s*more\s*-->/i)[0]
|
18
|
-
else
|
19
|
-
input
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Checks for excerpts (helpful for template conditionals)
|
24
|
-
|
25
|
-
def has_excerpt(input)
|
26
|
-
input =~ /<!--\s*more\s*-->/i ? true : false
|
27
|
-
end
|
28
|
-
|
29
|
-
# Summary is used on the Archive pages to return the first block of content from a post.
|
30
|
-
|
31
|
-
def summary(input)
|
32
|
-
if input.index(/\n\n/)
|
33
|
-
input.split(/\n\n/)[0]
|
34
|
-
else
|
35
|
-
input
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Improved version of Liquid's truncate:
|
40
|
-
# - Doesn't cut in the middle of a word.
|
41
|
-
# - Uses typographically correct ellipsis (…) insted of '...'
|
42
|
-
|
43
|
-
def truncate(input, length)
|
44
|
-
if input.length > length && input[0..(length-1)] =~ /(.+)\b.+$/im
|
45
|
-
$1.strip + ' …'
|
46
|
-
else
|
47
|
-
input
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# Improved version of Liquid's truncatewords:
|
52
|
-
# - Uses typographically correct ellipsis (…) insted of '...'
|
53
|
-
|
54
|
-
def truncatewords(input, length)
|
55
|
-
truncate = input.split(' ')
|
56
|
-
if truncate.length > length
|
57
|
-
truncate[0..length-1].join(' ').strip + ' …'
|
58
|
-
else
|
59
|
-
input
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
Liquid::Template.register_filter Octopress::ContentFilters
|
66
|
-
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Octopress
|
2
|
-
module Date
|
3
|
-
# Returns a datetime if the input is a string
|
4
|
-
def datetime(date)
|
5
|
-
if date.class == String
|
6
|
-
date = Time.parse(date)
|
7
|
-
end
|
8
|
-
date
|
9
|
-
end
|
10
|
-
|
11
|
-
# Returns an ordidinal date eg July 22 2007 -> July 22nd 2007
|
12
|
-
def ordinalize(date)
|
13
|
-
date = datetime(date)
|
14
|
-
"#{date.strftime('%b')} #{ordinal(date.strftime('%e').to_i)}, #{date.strftime('%Y')}"
|
15
|
-
end
|
16
|
-
|
17
|
-
# Returns an ordinal number. 13 -> 13th, 21 -> 21st etc.
|
18
|
-
def ordinal(number)
|
19
|
-
if (11..13).include?(number.to_i % 100)
|
20
|
-
"#{number}<span>th</span>"
|
21
|
-
else
|
22
|
-
case number.to_i % 10
|
23
|
-
when 1; "#{number}<span>st</span>"
|
24
|
-
when 2; "#{number}<span>nd</span>"
|
25
|
-
when 3; "#{number}<span>rd</span>"
|
26
|
-
else "#{number}<span>th</span>"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Formats date either as ordinal or by given date format
|
32
|
-
# Adds %o as ordinal representation of the day
|
33
|
-
def format_date(date, format)
|
34
|
-
date = datetime(date)
|
35
|
-
if format.nil? || format.empty? || format == "ordinal"
|
36
|
-
date_formatted = ordinalize(date)
|
37
|
-
else
|
38
|
-
date_formatted = date.strftime(format)
|
39
|
-
date_formatted.gsub!(/%o/, ordinal(date.strftime('%e').to_i))
|
40
|
-
end
|
41
|
-
date_formatted
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
Liquid::Template.register_filter Octopress::Date
|
@@ -1,175 +0,0 @@
|
|
1
|
-
module Jekyll
|
2
|
-
|
3
|
-
# Extended plugin type that allows the plugin
|
4
|
-
# to be called on varous callback methods.
|
5
|
-
#
|
6
|
-
# Examples:
|
7
|
-
# https://github.com/tedkulp/octopress/blob/master/plugins/post_metaweblog.rb
|
8
|
-
class PostFilter < Plugin
|
9
|
-
|
10
|
-
#Called before post is sent to the converter. Allows
|
11
|
-
#you to modify the post object before the converter
|
12
|
-
#does it's thing
|
13
|
-
def pre_render(post)
|
14
|
-
end
|
15
|
-
|
16
|
-
#Called after the post is rendered with the converter.
|
17
|
-
#Use the post object to modify it's contents before the
|
18
|
-
#post is inserted into the template.
|
19
|
-
def post_render(post)
|
20
|
-
end
|
21
|
-
|
22
|
-
#Called after the post is written to the disk.
|
23
|
-
#Use the post object to read it's contents to do something
|
24
|
-
#after the post is safely written.
|
25
|
-
def post_write(post)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Monkey patch for the Jekyll Site class. For the original class,
|
30
|
-
# see: https://github.com/mojombo/jekyll/blob/master/lib/jekyll/site.rb
|
31
|
-
class Site
|
32
|
-
|
33
|
-
# Instance variable to store the various post_filter
|
34
|
-
# plugins that are loaded.
|
35
|
-
attr_accessor :post_filters
|
36
|
-
|
37
|
-
# Instantiates all of the post_filter plugins. This is basically
|
38
|
-
# a duplication of the other loaders in Site#setup.
|
39
|
-
def load_post_filters
|
40
|
-
self.post_filters = instantiate_subclasses(Jekyll::PostFilter)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# Monkey patch for the Jekyll Post class. For the original class,
|
45
|
-
# see: https://github.com/mojombo/jekyll/blob/master/lib/jekyll/post.rb
|
46
|
-
class Post
|
47
|
-
|
48
|
-
# Copy the #write method to #old_write, so we can redefine #write
|
49
|
-
# method.
|
50
|
-
alias_method :old_write, :write
|
51
|
-
|
52
|
-
# Write the generated post file to the destination directory. It
|
53
|
-
# then calls any post_write methods that may exist.
|
54
|
-
# +dest+ is the String path to the destination dir
|
55
|
-
#
|
56
|
-
# Returns nothing
|
57
|
-
def write(dest)
|
58
|
-
old_write(dest)
|
59
|
-
post_write if respond_to?(:post_write)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# Monkey patch for the Jekyll Page class. For the original class,
|
64
|
-
# see: https://github.com/mojombo/jekyll/blob/master/lib/jekyll/page.rb
|
65
|
-
class Page
|
66
|
-
|
67
|
-
# Copy the #write method to #old_write, so we can redefine #write
|
68
|
-
# method.
|
69
|
-
alias_method :old_write, :write
|
70
|
-
|
71
|
-
# Write the generated post file to the destination directory. It
|
72
|
-
# then calls any post_write methods that may exist.
|
73
|
-
# +dest+ is the String path to the destination dir
|
74
|
-
#
|
75
|
-
# Returns nothing
|
76
|
-
def write(dest)
|
77
|
-
old_write(dest)
|
78
|
-
post_write if respond_to?(:post_write)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
# Monkey patch for the Jekyll Convertible module. For the original class,
|
83
|
-
# see: https://github.com/mojombo/jekyll/blob/master/lib/jekyll/convertible.rb
|
84
|
-
module Convertible
|
85
|
-
|
86
|
-
def is_post?
|
87
|
-
self.class.to_s == 'Jekyll::Post'
|
88
|
-
end
|
89
|
-
|
90
|
-
def is_page?
|
91
|
-
self.class.to_s == 'Jekyll::Page'
|
92
|
-
end
|
93
|
-
|
94
|
-
def is_convertible_page?
|
95
|
-
self.class.to_s == 'Jekyll::ConvertiblePage'
|
96
|
-
end
|
97
|
-
|
98
|
-
def is_filterable?
|
99
|
-
is_post? or is_page? or is_convertible_page?
|
100
|
-
end
|
101
|
-
|
102
|
-
# Call the #pre_render methods on all of the loaded
|
103
|
-
# post_filter plugins.
|
104
|
-
#
|
105
|
-
# Returns nothing
|
106
|
-
def pre_render
|
107
|
-
self.site.load_post_filters unless self.site.post_filters
|
108
|
-
|
109
|
-
if self.site.post_filters and is_filterable?
|
110
|
-
self.site.post_filters.each do |filter|
|
111
|
-
filter.pre_render(self)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
# Call the #post_render methods on all of the loaded
|
117
|
-
# post_filter plugins.
|
118
|
-
#
|
119
|
-
# Returns nothing
|
120
|
-
def post_render
|
121
|
-
if self.site.post_filters and is_filterable?
|
122
|
-
self.site.post_filters.each do |filter|
|
123
|
-
filter.post_render(self)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
# Call the #post_write methods on all of the loaded
|
129
|
-
# post_filter plugins.
|
130
|
-
#
|
131
|
-
# Returns nothing
|
132
|
-
def post_write
|
133
|
-
if self.site.post_filters and is_filterable?
|
134
|
-
self.site.post_filters.each do |filter|
|
135
|
-
filter.post_write(self)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# Copy the #transform method to #old_transform, so we can
|
141
|
-
# redefine #transform method.
|
142
|
-
alias_method :old_transform, :transform
|
143
|
-
|
144
|
-
# Transform the contents based on the content type. Then calls the
|
145
|
-
# #post_render method if it exists
|
146
|
-
#
|
147
|
-
# Returns nothing.
|
148
|
-
def transform
|
149
|
-
old_transform
|
150
|
-
post_render if respond_to?(:post_render)
|
151
|
-
end
|
152
|
-
|
153
|
-
# Copy the #do_layout method to #old_do_layout, so we can
|
154
|
-
# redefine #do_layout method.
|
155
|
-
alias_method :old_do_layout, :do_layout
|
156
|
-
|
157
|
-
# Calls the pre_render method if it exists and then adds any necessary
|
158
|
-
# layouts to this convertible document.
|
159
|
-
#
|
160
|
-
# payload - The site payload Hash.
|
161
|
-
# layouts - A Hash of {"name" => "layout"}.
|
162
|
-
#
|
163
|
-
# Returns nothing.
|
164
|
-
def do_layout(payload, layouts)
|
165
|
-
pre_render if respond_to?(:pre_render)
|
166
|
-
old_do_layout(payload, layouts)
|
167
|
-
end
|
168
|
-
|
169
|
-
# Returns the full url of the post, including the
|
170
|
-
# configured url
|
171
|
-
def full_url
|
172
|
-
self.site.config['url'] + self.url
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# Liquid filters for Octopress
|
2
|
-
|
3
|
-
module Octopress
|
4
|
-
module UrlFilters
|
5
|
-
include UrlHelpers
|
6
|
-
|
7
|
-
# Replaces relative urls with full urls
|
8
|
-
|
9
|
-
def expand_urls(input, url='')
|
10
|
-
url ||= '/'
|
11
|
-
input.gsub /(\s+(href|src)\s*=\s*["|']{1})(\/(?!\/)[^\"'>]*)/ do
|
12
|
-
$1+url+$3
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# Removes trailing forward slash from a string for easily appending url segments
|
17
|
-
|
18
|
-
def strip_slash(input)
|
19
|
-
input.sub(/\/\s*$/, '')
|
20
|
-
end
|
21
|
-
|
22
|
-
# Returns a url without the protocol (http://)
|
23
|
-
|
24
|
-
def shorthand_url(input)
|
25
|
-
input.gsub /(https?:\/\/)(\S+)/ do
|
26
|
-
$2
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
Liquid::Template.register_filter Octopress::UrlFilters
|
34
|
-
|
data/lib/octopress/formatters.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module Octopress
|
2
|
-
module Formatters
|
3
|
-
class BaseFormatter < Logger::Formatter
|
4
|
-
|
5
|
-
COLORS = {
|
6
|
-
"ERROR" => "red",
|
7
|
-
"WARN" => "yellow",
|
8
|
-
"INFO" => "green",
|
9
|
-
"DEBUG" => "white"
|
10
|
-
}
|
11
|
-
|
12
|
-
def call(severity, timestamp, progname, msg)
|
13
|
-
(progname || msg).to_s.send(COLORS[severity]) + "\n"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,196 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# Jekyll category page generator.
|
4
|
-
# http://recursive-design.com/projects/jekyll-plugins/
|
5
|
-
#
|
6
|
-
# Version: 0.1.4 (201101061053)
|
7
|
-
#
|
8
|
-
# Copyright (c) 2010 Dave Perrett, http://recursive-design.com/
|
9
|
-
# Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
|
10
|
-
#
|
11
|
-
# A generator that creates category pages for jekyll sites.
|
12
|
-
#
|
13
|
-
# Included filters :
|
14
|
-
# - category_links: Outputs the list of categories as comma-separated <a> links.
|
15
|
-
# - date_to_html_string: Outputs the post.date as formatted html, with hooks for CSS styling.
|
16
|
-
#
|
17
|
-
# Available _config.yml settings :
|
18
|
-
# - category_dir: The subfolder to build category pages in (default is 'categories').
|
19
|
-
# - category_title_prefix: The string used before the category name in the page title (default is
|
20
|
-
# 'Category: ').
|
21
|
-
|
22
|
-
require 'stringex'
|
23
|
-
|
24
|
-
module Jekyll
|
25
|
-
|
26
|
-
# The CategoryIndex class creates a single category page for the specified category.
|
27
|
-
class CategoryIndex < Page
|
28
|
-
|
29
|
-
# Initializes a new CategoryIndex.
|
30
|
-
#
|
31
|
-
# +base+ is the String path to the <source>.
|
32
|
-
# +category_dir+ is the String path between <source> and the category folder.
|
33
|
-
# +category+ is the category currently being processed.
|
34
|
-
def initialize(site, base, category_dir, category, title)
|
35
|
-
@site = site
|
36
|
-
@base = base
|
37
|
-
@dir = category_dir
|
38
|
-
@name = 'index.html'
|
39
|
-
self.process(@name)
|
40
|
-
# Read the YAML data from the layout page.
|
41
|
-
return unless self.read_yaml(File.join(base, '_layouts'), 'category-index.html')
|
42
|
-
self.data['category'] = category
|
43
|
-
# Set the title for this page.
|
44
|
-
title_prefix = site.config['category_title_prefix'] || 'Category: '
|
45
|
-
self.data['title'] = "#{title_prefix}#{title}"
|
46
|
-
# Set the meta-description for this page.
|
47
|
-
meta_description_prefix = site.config['category_meta_description_prefix'] || 'Category: '
|
48
|
-
self.data['description'] = "#{meta_description_prefix}#{title}"
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
# The CategoryFeed class creates an Atom feed for the specified category.
|
54
|
-
class CategoryFeed < Page
|
55
|
-
|
56
|
-
# Initializes a new CategoryFeed.
|
57
|
-
#
|
58
|
-
# +base+ is the String path to the <source>.
|
59
|
-
# +category_dir+ is the String path between <source> and the category folder.
|
60
|
-
# +category+ is the category currently being processed.
|
61
|
-
def initialize(site, base, category_dir, category, title)
|
62
|
-
@site = site
|
63
|
-
@base = base
|
64
|
-
@dir = category_dir
|
65
|
-
@name = 'atom.xml'
|
66
|
-
self.process(@name)
|
67
|
-
# Read the YAML data from the layout page.
|
68
|
-
self.read_yaml(File.join(base, '_includes/custom'), 'category-feed.xml')
|
69
|
-
self.data['category'] = category
|
70
|
-
# Set the title for this page.
|
71
|
-
title_prefix = site.config['category_title_prefix'] || 'Category: '
|
72
|
-
self.data['title'] = "#{title_prefix}#{title}"
|
73
|
-
# Set the meta-description for this page.
|
74
|
-
meta_description_prefix = site.config['category_meta_description_prefix'] || 'Category: '
|
75
|
-
self.data['description'] = "#{meta_description_prefix}#{title}"
|
76
|
-
|
77
|
-
# Set the correct feed URL.
|
78
|
-
self.data['feed_url'] = "#{category_dir}/#{name}"
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
# The Site class is a built-in Jekyll class with access to global site config information.
|
84
|
-
class Site
|
85
|
-
|
86
|
-
# Creates an instance of CategoryIndex for each category page, renders it, and
|
87
|
-
# writes the output to a file.
|
88
|
-
#
|
89
|
-
# +category_dir+ is the String path to the category folder.
|
90
|
-
# +category+ is the category currently being processed.
|
91
|
-
def write_category_index(category_dir, category, title)
|
92
|
-
index = CategoryIndex.new(self, self.source, category_dir, category, title)
|
93
|
-
index.render(self.layouts, site_payload)
|
94
|
-
index.write(self.dest)
|
95
|
-
# Record the fact that this page has been added, otherwise Site::cleanup will remove it.
|
96
|
-
self.pages << index
|
97
|
-
|
98
|
-
# Create an Atom-feed for each index.
|
99
|
-
if self.config['category_feeds']
|
100
|
-
feed = CategoryFeed.new(self, self.source, category_dir, category, title)
|
101
|
-
feed.render(self.layouts, site_payload)
|
102
|
-
feed.write(self.dest)
|
103
|
-
# Record the fact that this page has been added, otherwise Site::cleanup will remove it.
|
104
|
-
self.pages << feed
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
# Loops through the list of category pages and processes each one.
|
110
|
-
def write_category_indexes
|
111
|
-
return unless self.layouts.key? 'category_index'
|
112
|
-
dir = self.config['category_dir']
|
113
|
-
self.categories.keys.each do |category|
|
114
|
-
if category =~ /(.+)\[(.+)\]/
|
115
|
-
slug = $1.strip
|
116
|
-
title = $2.strip
|
117
|
-
else
|
118
|
-
slug = title = category
|
119
|
-
end
|
120
|
-
cat_dir = slug.to_url
|
121
|
-
cat_dir = File.join(dir, cat_dir) unless dir.nil? or dir.empty?
|
122
|
-
self.write_category_index(cat_dir, category, title)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
|
128
|
-
# Jekyll hook - the generate method is called by jekyll, and generates all of the category pages.
|
129
|
-
class GenerateCategories < Generator
|
130
|
-
safe true
|
131
|
-
priority :low
|
132
|
-
|
133
|
-
def generate(site)
|
134
|
-
site.write_category_indexes
|
135
|
-
end
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
# Adds some extra filters used during the category creation process.
|
141
|
-
module Filters
|
142
|
-
|
143
|
-
# Outputs a list of categories as comma-separated <a> links. This is used
|
144
|
-
# to output the category list for each post on a category page.
|
145
|
-
#
|
146
|
-
# +categories+ is the list of categories to format.
|
147
|
-
#
|
148
|
-
# Returns string
|
149
|
-
#
|
150
|
-
def category_links(categories)
|
151
|
-
categories = categories.sort!.map { |c| category_link c }
|
152
|
-
case categories.length
|
153
|
-
when 0
|
154
|
-
""
|
155
|
-
when 1
|
156
|
-
categories[0].to_s
|
157
|
-
else
|
158
|
-
"#{categories[0...-1].join(', ')}, #{categories[-1]}"
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
# Outputs a single category as an <a> link.
|
163
|
-
#
|
164
|
-
# +category+ is a category string to format as an <a> link
|
165
|
-
#
|
166
|
-
# Returns string
|
167
|
-
#
|
168
|
-
def category_link(category)
|
169
|
-
if category =~ /(.+)\[(.+)\]/
|
170
|
-
slug = $1.strip
|
171
|
-
title = $2.strip
|
172
|
-
else
|
173
|
-
slug = title = category
|
174
|
-
end
|
175
|
-
dir = @context.registers[:site].config['category_dir']
|
176
|
-
url = slug.to_url
|
177
|
-
url = "#{dir}/#{url}" unless dir.nil? or dir.empty?
|
178
|
-
"<a class='category' href='/#{url}/'>#{title}</a>"
|
179
|
-
end
|
180
|
-
|
181
|
-
# Outputs the post.date as formatted html, with hooks for CSS styling.
|
182
|
-
#
|
183
|
-
# +date+ is the date object to format as HTML.
|
184
|
-
#
|
185
|
-
# Returns string
|
186
|
-
def date_to_html_string(date)
|
187
|
-
string = <<HTML.strip
|
188
|
-
<span class='month'>#{date.strftime('%b').upcase}</span>
|
189
|
-
#{date.strftime('<span class="day">%d</span>')}
|
190
|
-
#{date.strftime('<span class="year">%Y</span>')}
|
191
|
-
HTML
|
192
|
-
end
|
193
|
-
|
194
|
-
end
|
195
|
-
|
196
|
-
end
|