tigefa 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.markdown +91 -0
  3. data/Gemfile +2 -0
  4. data/History.markdown +871 -0
  5. data/LICENSE +15 -14
  6. data/README.markdown +59 -0
  7. data/Rakefile +298 -0
  8. data/bin/tigefa +158 -0
  9. data/cucumber.yml +3 -0
  10. data/features/create_sites.feature +141 -0
  11. data/features/data.feature +65 -0
  12. data/features/drafts.feature +25 -0
  13. data/features/embed_filters.feature +60 -0
  14. data/features/include_tag.feature +57 -0
  15. data/features/markdown.feature +67 -0
  16. data/features/pagination.feature +82 -0
  17. data/features/permalinks.feature +85 -0
  18. data/features/post_data.feature +214 -0
  19. data/features/post_excerpts.feature +50 -0
  20. data/features/site_configuration.feature +235 -0
  21. data/features/site_data.feature +107 -0
  22. data/features/step_definitions/tigefa_steps.rb +189 -0
  23. data/features/support/env.rb +75 -0
  24. data/lib/site_template/.gitignore +1 -0
  25. data/lib/site_template/_config.yml +3 -0
  26. data/lib/site_template/_layouts/default.html +44 -0
  27. data/lib/site_template/_layouts/post.html +9 -0
  28. data/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb +24 -0
  29. data/lib/site_template/css/main.css +160 -0
  30. data/lib/site_template/css/syntax.css +60 -0
  31. data/lib/site_template/index.html +13 -0
  32. data/lib/tigefa/cleaner.rb +73 -0
  33. data/lib/tigefa/command.rb +27 -0
  34. data/lib/tigefa/commands/build.rb +70 -0
  35. data/lib/tigefa/commands/doctor.rb +67 -0
  36. data/lib/tigefa/commands/new.rb +67 -0
  37. data/lib/tigefa/commands/serve.rb +65 -0
  38. data/lib/tigefa/configuration.rb +238 -0
  39. data/lib/tigefa/converter.rb +48 -0
  40. data/lib/tigefa/converters/identity.rb +21 -0
  41. data/lib/tigefa/converters/markdown/kramdown_parser.rb +29 -0
  42. data/lib/tigefa/converters/markdown/maruku_parser.rb +56 -0
  43. data/lib/tigefa/converters/markdown/rdiscount_parser.rb +37 -0
  44. data/lib/tigefa/converters/markdown/redcarpet_parser.rb +70 -0
  45. data/lib/tigefa/converters/markdown.rb +43 -0
  46. data/lib/tigefa/converters/textile.rb +50 -0
  47. data/lib/tigefa/convertible.rb +174 -0
  48. data/lib/tigefa/core_ext.rb +90 -0
  49. data/lib/tigefa/deprecator.rb +36 -0
  50. data/lib/tigefa/draft.rb +35 -0
  51. data/lib/tigefa/entry_filter.rb +35 -0
  52. data/lib/tigefa/errors.rb +4 -0
  53. data/lib/tigefa/excerpt.rb +113 -0
  54. data/lib/tigefa/filters.rb +174 -0
  55. data/lib/tigefa/generator.rb +4 -0
  56. data/lib/tigefa/generators/pagination.rb +217 -0
  57. data/lib/tigefa/layout.rb +45 -0
  58. data/lib/tigefa/mime.types +85 -0
  59. data/lib/tigefa/page.rb +160 -0
  60. data/lib/tigefa/plugin.rb +75 -0
  61. data/lib/tigefa/post.rb +312 -0
  62. data/lib/tigefa/related_posts.rb +59 -0
  63. data/lib/tigefa/site.rb +427 -0
  64. data/lib/tigefa/static_file.rb +70 -0
  65. data/lib/tigefa/stevenson.rb +89 -0
  66. data/lib/tigefa/tags/gist.rb +48 -0
  67. data/lib/tigefa/tags/highlight.rb +85 -0
  68. data/lib/tigefa/tags/include.rb +134 -0
  69. data/lib/tigefa/tags/post_url.rb +63 -0
  70. data/lib/tigefa/url.rb +69 -0
  71. data/lib/tigefa.rb +98 -4
  72. data/script/bootstrap +2 -0
  73. data/site/.gitignore +4 -0
  74. data/site/CNAME +1 -0
  75. data/site/README +1 -0
  76. data/site/_config.yml +6 -0
  77. data/site/_includes/analytics.html +32 -0
  78. data/site/_includes/docs_contents.html +16 -0
  79. data/site/_includes/docs_contents_mobile.html +23 -0
  80. data/site/_includes/docs_option.html +11 -0
  81. data/site/_includes/docs_ul.html +20 -0
  82. data/site/_includes/footer.html +15 -0
  83. data/site/_includes/header.html +18 -0
  84. data/site/_includes/news_contents.html +23 -0
  85. data/site/_includes/news_contents_mobile.html +11 -0
  86. data/site/_includes/news_item.html +24 -0
  87. data/site/_includes/primary-nav-items.html +14 -0
  88. data/site/_includes/section_nav.html +22 -0
  89. data/site/_includes/top.html +17 -0
  90. data/site/_layouts/default.html +12 -0
  91. data/site/_layouts/docs.html +23 -0
  92. data/site/_layouts/news.html +19 -0
  93. data/site/_layouts/news_item.html +27 -0
  94. data/site/_posts/2013-05-06-jekyll-1-0-0-released.markdown +23 -0
  95. data/site/_posts/2013-05-08-jekyll-1-0-1-released.markdown +27 -0
  96. data/site/_posts/2013-05-12-jekyll-1-0-2-released.markdown +28 -0
  97. data/site/_posts/2013-06-07-jekyll-1-0-3-released.markdown +25 -0
  98. data/site/_posts/2013-07-14-jekyll-1-1-0-released.markdown +27 -0
  99. data/site/_posts/2013-07-24-jekyll-1-1-1-released.markdown +31 -0
  100. data/site/_posts/2013-07-25-jekyll-1-0-4-released.markdown +20 -0
  101. data/site/_posts/2013-07-25-jekyll-1-1-2-released.markdown +20 -0
  102. data/site/_posts/2013-09-06-jekyll-1-2-0-released.markdown +23 -0
  103. data/site/_posts/2013-09-14-jekyll-1-2-1-released.markdown +19 -0
  104. data/site/_posts/2013-10-28-jekyll-1-3-0-rc1-released.markdown +19 -0
  105. data/site/_posts/2013-11-04-jekyll-1-3-0-released.markdown +43 -0
  106. data/site/_posts/2013-11-26-jekyll-1-3-1-released.markdown +21 -0
  107. data/site/_posts/2013-12-07-jekyll-1-4-0-released.markdown +30 -0
  108. data/site/_posts/2013-12-16-jekyll-1-4-2-released.markdown +18 -0
  109. data/site/_posts/2014-01-13-jekyll-1-4-3-released.markdown +27 -0
  110. data/site/css/gridism.css +110 -0
  111. data/site/css/normalize.css +1 -0
  112. data/site/css/pygments.css +70 -0
  113. data/site/css/style.css +946 -0
  114. data/site/docs/configuration.md +375 -0
  115. data/site/docs/contributing.md +128 -0
  116. data/site/docs/datafiles.md +63 -0
  117. data/site/docs/deployment-methods.md +109 -0
  118. data/site/docs/drafts.md +21 -0
  119. data/site/docs/extras.md +56 -0
  120. data/site/docs/frontmatter.md +180 -0
  121. data/site/docs/github-pages.md +91 -0
  122. data/site/docs/heroku.md +9 -0
  123. data/site/docs/history.md +866 -0
  124. data/site/docs/index.md +52 -0
  125. data/site/docs/installation.md +76 -0
  126. data/site/docs/migrations.md +11 -0
  127. data/site/docs/pages.md +86 -0
  128. data/site/docs/pagination.md +211 -0
  129. data/site/docs/permalinks.md +180 -0
  130. data/site/docs/plugins.md +534 -0
  131. data/site/docs/posts.md +181 -0
  132. data/site/docs/quickstart.md +32 -0
  133. data/site/docs/resources.md +46 -0
  134. data/site/docs/sites.md +29 -0
  135. data/site/docs/structure.md +190 -0
  136. data/site/docs/templates.md +339 -0
  137. data/site/docs/troubleshooting.md +150 -0
  138. data/site/docs/upgrading.md +146 -0
  139. data/site/docs/usage.md +63 -0
  140. data/site/docs/variables.md +322 -0
  141. data/site/favicon.png +0 -0
  142. data/site/feed.xml +36 -0
  143. data/site/freenode.txt +1 -0
  144. data/site/img/article-footer.png +0 -0
  145. data/site/img/footer-arrow.png +0 -0
  146. data/site/img/footer-logo.png +0 -0
  147. data/site/img/logo-2x.png +0 -0
  148. data/site/img/octojekyll.png +0 -0
  149. data/site/img/tube.png +0 -0
  150. data/site/img/tube1x.png +0 -0
  151. data/site/index.html +90 -0
  152. data/site/js/modernizr-2.5.3.min.js +4 -0
  153. data/site/news/index.html +10 -0
  154. data/site/news/releases/index.html +10 -0
  155. data/test/fixtures/broken_front_matter1.erb +5 -0
  156. data/test/fixtures/broken_front_matter2.erb +4 -0
  157. data/test/fixtures/broken_front_matter3.erb +7 -0
  158. data/test/fixtures/exploit_front_matter.erb +4 -0
  159. data/test/fixtures/front_matter.erb +4 -0
  160. data/test/helper.rb +65 -0
  161. data/test/source/+/foo.md +7 -0
  162. data/test/source/.htaccess +8 -0
  163. data/test/source/_config.dev.toml +2 -0
  164. data/test/source/_data/languages.yml +2 -0
  165. data/test/source/_data/members.yaml +7 -0
  166. data/test/source/_data/products.yml +1 -0
  167. data/test/source/_includes/params.html +7 -0
  168. data/test/source/_includes/sig.markdown +3 -0
  169. data/test/source/_includes/tmp +1 -0
  170. data/test/source/_layouts/default.html +27 -0
  171. data/test/source/_layouts/post/simple.html +1 -0
  172. data/test/source/_layouts/simple.html +1 -0
  173. data/test/source/_plugins/dummy.rb +8 -0
  174. data/test/source/_posts/2008-02-02-not-published.textile +8 -0
  175. data/test/source/_posts/2008-02-02-published.textile +8 -0
  176. data/test/source/_posts/2008-10-18-foo-bar.textile +8 -0
  177. data/test/source/_posts/2008-11-21-complex.textile +8 -0
  178. data/test/source/_posts/2008-12-03-permalinked-post.textile +9 -0
  179. data/test/source/_posts/2008-12-13-include.markdown +8 -0
  180. data/test/source/_posts/2009-01-27-array-categories.textile +10 -0
  181. data/test/source/_posts/2009-01-27-categories.textile +7 -0
  182. data/test/source/_posts/2009-01-27-category.textile +7 -0
  183. data/test/source/_posts/2009-01-27-empty-categories.textile +7 -0
  184. data/test/source/_posts/2009-01-27-empty-category.textile +7 -0
  185. data/test/source/_posts/2009-03-12-hash-#1.markdown +6 -0
  186. data/test/source/_posts/2009-05-18-empty-tag.textile +6 -0
  187. data/test/source/_posts/2009-05-18-empty-tags.textile +6 -0
  188. data/test/source/_posts/2009-05-18-tag.textile +6 -0
  189. data/test/source/_posts/2009-05-18-tags.textile +9 -0
  190. data/test/source/_posts/2009-06-22-empty-yaml.textile +3 -0
  191. data/test/source/_posts/2009-06-22-no-yaml.textile +1 -0
  192. data/test/source/_posts/2010-01-08-triple-dash.markdown +5 -0
  193. data/test/source/_posts/2010-01-09-date-override.textile +7 -0
  194. data/test/source/_posts/2010-01-09-time-override.textile +7 -0
  195. data/test/source/_posts/2010-01-09-timezone-override.textile +7 -0
  196. data/test/source/_posts/2010-01-16-override-data.textile +4 -0
  197. data/test/source/_posts/2011-04-12-md-extension.md +7 -0
  198. data/test/source/_posts/2011-04-12-text-extension.text +0 -0
  199. data/test/source/_posts/2013-01-02-post-excerpt.markdown +14 -0
  200. data/test/source/_posts/2013-01-12-nil-layout.textile +6 -0
  201. data/test/source/_posts/2013-01-12-no-layout.textile +5 -0
  202. data/test/source/_posts/2013-03-19-not-a-post.markdown/.gitkeep +0 -0
  203. data/test/source/_posts/2013-04-11-custom-excerpt.markdown +10 -0
  204. data/test/source/_posts/2013-05-10-number-category.textile +7 -0
  205. data/test/source/_posts/2013-07-22-post-excerpt-with-layout.markdown +23 -0
  206. data/test/source/_posts/2013-08-01-mkdn-extension.mkdn +0 -0
  207. data/test/source/_posts/2014-01-06-permalink-traversal.md +5 -0
  208. data/test/source/_posts/es/2008-11-21-nested.textile +8 -0
  209. data/test/source/about.html +6 -0
  210. data/test/source/category/_posts/2008-9-23-categories.textile +6 -0
  211. data/test/source/contacts/bar.html +5 -0
  212. data/test/source/contacts/index.html +5 -0
  213. data/test/source/contacts.html +5 -0
  214. data/test/source/css/screen.css +76 -0
  215. data/test/source/deal.with.dots.html +7 -0
  216. data/test/source/exploit.md +5 -0
  217. data/test/source/foo/_posts/bar/2008-12-12-topical-post.textile +8 -0
  218. data/test/source/index.html +22 -0
  219. data/test/source/products.yml +4 -0
  220. data/test/source/sitemap.xml +32 -0
  221. data/test/source/symlink-test/_data +1 -0
  222. data/test/source/symlink-test/symlinked-dir +1 -0
  223. data/test/source/symlink-test/symlinked-file +1 -0
  224. data/test/source/win/_posts/2009-05-24-yaml-linebreak.markdown +7 -0
  225. data/test/source/z_category/_posts/2008-9-23-categories.textile +6 -0
  226. data/test/suite.rb +11 -0
  227. data/test/test_command.rb +39 -0
  228. data/test/test_configuration.rb +181 -0
  229. data/test/test_convertible.rb +51 -0
  230. data/test/test_core_ext.rb +88 -0
  231. data/test/test_entry_filter.rb +74 -0
  232. data/test/test_excerpt.rb +78 -0
  233. data/test/test_filters.rb +113 -0
  234. data/test/test_generated_site.rb +83 -0
  235. data/test/test_kramdown.rb +62 -0
  236. data/test/test_new_command.rb +104 -0
  237. data/test/test_page.rb +212 -0
  238. data/test/test_pager.rb +116 -0
  239. data/test/test_post.rb +592 -0
  240. data/test/test_rdiscount.rb +22 -0
  241. data/test/test_redcarpet.rb +61 -0
  242. data/test/test_redcloth.rb +86 -0
  243. data/test/test_related_posts.rb +47 -0
  244. data/test/test_site.rb +333 -0
  245. data/test/test_tags.rb +490 -0
  246. data/test/test_url.rb +28 -0
  247. data/tigefa.gemspec +306 -0
  248. metadata +575 -45
  249. data/README.md +0 -4
@@ -0,0 +1,75 @@
1
+ module Tigefa
2
+ class Plugin
3
+ PRIORITIES = { :lowest => -100,
4
+ :low => -10,
5
+ :normal => 0,
6
+ :high => 10,
7
+ :highest => 100 }
8
+
9
+ # Install a hook so that subclasses are recorded. This method is only
10
+ # ever called by Ruby itself.
11
+ #
12
+ # base - The Class subclass.
13
+ #
14
+ # Returns nothing.
15
+ def self.inherited(base)
16
+ subclasses << base
17
+ subclasses.sort!
18
+ end
19
+
20
+ # The list of Classes that have been subclassed.
21
+ #
22
+ # Returns an Array of Class objects.
23
+ def self.subclasses
24
+ @subclasses ||= []
25
+ end
26
+
27
+ # Get or set the priority of this plugin. When called without an
28
+ # argument it returns the priority. When an argument is given, it will
29
+ # set the priority.
30
+ #
31
+ # priority - The Symbol priority (default: nil). Valid options are:
32
+ # :lowest, :low, :normal, :high, :highest
33
+ #
34
+ # Returns the Symbol priority.
35
+ def self.priority(priority = nil)
36
+ @priority ||= nil
37
+ if priority && PRIORITIES.has_key?(priority)
38
+ @priority = priority
39
+ end
40
+ @priority || :normal
41
+ end
42
+
43
+ # Get or set the safety of this plugin. When called without an argument
44
+ # it returns the safety. When an argument is given, it will set the
45
+ # safety.
46
+ #
47
+ # safe - The Boolean safety (default: nil).
48
+ #
49
+ # Returns the safety Boolean.
50
+ def self.safe(safe = nil)
51
+ if safe
52
+ @safe = safe
53
+ end
54
+ @safe || false
55
+ end
56
+
57
+ # Spaceship is priority [higher -> lower]
58
+ #
59
+ # other - The class to be compared.
60
+ #
61
+ # Returns -1, 0, 1.
62
+ def self.<=>(other)
63
+ PRIORITIES[other.priority] <=> PRIORITIES[self.priority]
64
+ end
65
+
66
+ # Initialize a new plugin. This should be overridden by the subclass.
67
+ #
68
+ # config - The Hash of configuration options.
69
+ #
70
+ # Returns a new instance.
71
+ def initialize(config = {})
72
+ # no-op for default
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,312 @@
1
+ module Tigefa
2
+ class Post
3
+ include Comparable
4
+ include Convertible
5
+
6
+ # Valid post name regex.
7
+ MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)(\.[^.]+)$/
8
+
9
+ EXCERPT_ATTRIBUTES_FOR_LIQUID = %w[
10
+ title
11
+ url
12
+ date
13
+ id
14
+ categories
15
+ next
16
+ previous
17
+ tags
18
+ path
19
+ ]
20
+
21
+ # Attributes for Liquid templates
22
+ ATTRIBUTES_FOR_LIQUID = EXCERPT_ATTRIBUTES_FOR_LIQUID + %w[
23
+ content
24
+ excerpt
25
+ ]
26
+
27
+ # Post name validator. Post filenames must be like:
28
+ # 2008-11-05-my-awesome-post.textile
29
+ #
30
+ # Returns true if valid, false if not.
31
+ def self.valid?(name)
32
+ name =~ MATCHER
33
+ end
34
+
35
+ attr_accessor :site
36
+ attr_accessor :data, :extracted_excerpt, :content, :output, :ext
37
+ attr_accessor :date, :slug, :published, :tags, :categories
38
+
39
+ attr_reader :name
40
+
41
+ # Initialize this Post instance.
42
+ #
43
+ # site - The Site.
44
+ # base - The String path to the dir containing the post file.
45
+ # name - The String filename of the post file.
46
+ #
47
+ # Returns the new Post.
48
+ def initialize(site, source, dir, name)
49
+ @site = site
50
+ @dir = dir
51
+ @base = self.containing_dir(source, dir)
52
+ @name = name
53
+
54
+ self.categories = dir.downcase.split('/').reject { |x| x.empty? }
55
+ self.process(name)
56
+ self.read_yaml(@base, name)
57
+
58
+ if self.data.has_key?('date')
59
+ self.date = Time.parse(self.data["date"].to_s)
60
+ end
61
+
62
+ self.published = self.published?
63
+
64
+ self.populate_categories
65
+ self.populate_tags
66
+ end
67
+
68
+ def published?
69
+ if self.data.has_key?('published') && self.data['published'] == false
70
+ false
71
+ else
72
+ true
73
+ end
74
+ end
75
+
76
+ def populate_categories
77
+ if self.categories.empty?
78
+ self.categories = self.data.pluralized_array('category', 'categories').map {|c| c.to_s.downcase}
79
+ end
80
+ self.categories.flatten!
81
+ end
82
+
83
+ def populate_tags
84
+ self.tags = self.data.pluralized_array("tag", "tags").flatten
85
+ end
86
+
87
+ # Get the full path to the directory containing the post files
88
+ def containing_dir(source, dir)
89
+ return File.join(source, dir, '_posts')
90
+ end
91
+
92
+ # Read the YAML frontmatter.
93
+ #
94
+ # base - The String path to the dir containing the file.
95
+ # name - The String filename of the file.
96
+ #
97
+ # Returns nothing.
98
+ def read_yaml(base, name)
99
+ super(base, name)
100
+ self.extracted_excerpt = self.extract_excerpt
101
+ end
102
+
103
+ # The post excerpt. This is either a custom excerpt
104
+ # set in YAML front matter or the result of extract_excerpt.
105
+ #
106
+ # Returns excerpt string.
107
+ def excerpt
108
+ self.data.fetch('excerpt', self.extracted_excerpt.to_s)
109
+ end
110
+
111
+ # Public: the Post title, from the YAML Front-Matter or from the slug
112
+ #
113
+ # Returns the post title
114
+ def title
115
+ self.data.fetch("title", self.titleized_slug)
116
+ end
117
+
118
+ # Turns the post slug into a suitable title
119
+ def titleized_slug
120
+ self.slug.split('-').select {|w| w.capitalize! || w }.join(' ')
121
+ end
122
+
123
+ # Public: the path to the post relative to the site source,
124
+ # from the YAML Front-Matter or from a combination of
125
+ # the directory it's in, "_posts", and the name of the
126
+ # post file
127
+ #
128
+ # Returns the path to the file relative to the site source
129
+ def path
130
+ self.data.fetch('path', self.relative_path.sub(/\A\//, ''))
131
+ end
132
+
133
+ # The path to the post source file, relative to the site source
134
+ def relative_path
135
+ File.join(@dir, '_posts', @name)
136
+ end
137
+
138
+ # Compares Post objects. First compares the Post date. If the dates are
139
+ # equal, it compares the Post slugs.
140
+ #
141
+ # other - The other Post we are comparing to.
142
+ #
143
+ # Returns -1, 0, 1
144
+ def <=>(other)
145
+ cmp = self.date <=> other.date
146
+ if 0 == cmp
147
+ cmp = self.slug <=> other.slug
148
+ end
149
+ return cmp
150
+ end
151
+
152
+ # Extract information from the post filename.
153
+ #
154
+ # name - The String filename of the post file.
155
+ #
156
+ # Returns nothing.
157
+ def process(name)
158
+ m, cats, date, slug, ext = *name.match(MATCHER)
159
+ self.date = Time.parse(date)
160
+ self.slug = slug
161
+ self.ext = ext
162
+ rescue ArgumentError
163
+ raise FatalException.new("Post #{name} does not have a valid date.")
164
+ end
165
+
166
+ # The generated directory into which the post will be placed
167
+ # upon generation. This is derived from the permalink or, if
168
+ # permalink is absent, set to the default date
169
+ # e.g. "/2008/11/05/" if the permalink style is :date, otherwise nothing.
170
+ #
171
+ # Returns the String directory.
172
+ def dir
173
+ File.dirname(url)
174
+ end
175
+
176
+ # The full path and filename of the post. Defined in the YAML of the post
177
+ # body (optional).
178
+ #
179
+ # Returns the String permalink.
180
+ def permalink
181
+ self.data && self.data['permalink']
182
+ end
183
+
184
+ def template
185
+ case self.site.permalink_style
186
+ when :pretty
187
+ "/:categories/:year/:month/:day/:title/"
188
+ when :none
189
+ "/:categories/:title.html"
190
+ when :date
191
+ "/:categories/:year/:month/:day/:title.html"
192
+ when :ordinal
193
+ "/:categories/:year/:y_day/:title.html"
194
+ else
195
+ self.site.permalink_style.to_s
196
+ end
197
+ end
198
+
199
+ # The generated relative url of this post.
200
+ #
201
+ # Returns the String url.
202
+ def url
203
+ @url ||= URL.new({
204
+ :template => template,
205
+ :placeholders => url_placeholders,
206
+ :permalink => permalink
207
+ }).to_s
208
+ end
209
+
210
+ # Returns a hash of URL placeholder names (as symbols) mapping to the
211
+ # desired placeholder replacements. For details see "url.rb"
212
+ def url_placeholders
213
+ {
214
+ :year => date.strftime("%Y"),
215
+ :month => date.strftime("%m"),
216
+ :day => date.strftime("%d"),
217
+ :title => CGI.escape(slug),
218
+ :i_day => date.strftime("%d").to_i.to_s,
219
+ :i_month => date.strftime("%m").to_i.to_s,
220
+ :categories => (categories || []).map { |c| URI.escape(c.to_s) }.join('/'),
221
+ :short_month => date.strftime("%b"),
222
+ :y_day => date.strftime("%j"),
223
+ :output_ext => self.output_ext
224
+ }
225
+ end
226
+
227
+ # The UID for this post (useful in feeds).
228
+ # e.g. /2008/11/05/my-awesome-post
229
+ #
230
+ # Returns the String UID.
231
+ def id
232
+ File.join(self.dir, self.slug)
233
+ end
234
+
235
+ # Calculate related posts.
236
+ #
237
+ # Returns an Array of related Posts.
238
+ def related_posts(posts)
239
+ Jekyll::RelatedPosts.new(self).build
240
+ end
241
+
242
+ # Add any necessary layouts to this post.
243
+ #
244
+ # layouts - A Hash of {"name" => "layout"}.
245
+ # site_payload - The site payload hash.
246
+ #
247
+ # Returns nothing.
248
+ def render(layouts, site_payload)
249
+ # construct payload
250
+ payload = {
251
+ "site" => { "related_posts" => related_posts(site_payload["site"]["posts"]) },
252
+ "page" => self.to_liquid(EXCERPT_ATTRIBUTES_FOR_LIQUID)
253
+ }.deep_merge(site_payload)
254
+
255
+ if generate_excerpt?
256
+ self.extracted_excerpt.do_layout(payload, {})
257
+ end
258
+
259
+ do_layout(payload.merge({"page" => self.to_liquid}), layouts)
260
+ end
261
+
262
+ # Obtain destination path.
263
+ #
264
+ # dest - The String path to the destination dir.
265
+ #
266
+ # Returns destination file path String.
267
+ def destination(dest)
268
+ # The url needs to be unescaped in order to preserve the correct filename
269
+ path = File.join(dest, File.expand_path(CGI.unescape(self.url), "/"))
270
+ path = File.join(path, "index.html") if path[/\.html$/].nil?
271
+ path
272
+ end
273
+
274
+ # Returns the shorthand String identifier of this Post.
275
+ def inspect
276
+ "<Post: #{self.id}>"
277
+ end
278
+
279
+ def next
280
+ pos = self.site.posts.index(self)
281
+
282
+ if pos && pos < self.site.posts.length-1
283
+ self.site.posts[pos+1]
284
+ else
285
+ nil
286
+ end
287
+ end
288
+
289
+ def previous
290
+ pos = self.site.posts.index(self)
291
+ if pos && pos > 0
292
+ self.site.posts[pos-1]
293
+ else
294
+ nil
295
+ end
296
+ end
297
+
298
+ protected
299
+
300
+ def extract_excerpt
301
+ if generate_excerpt?
302
+ Jekyll::Excerpt.new(self)
303
+ else
304
+ ""
305
+ end
306
+ end
307
+
308
+ def generate_excerpt?
309
+ !(site.config['excerpt_separator'].to_s.empty?)
310
+ end
311
+ end
312
+ end
@@ -0,0 +1,59 @@
1
+ module Tigefa
2
+ class RelatedPosts
3
+
4
+ class << self
5
+ attr_accessor :lsi
6
+ end
7
+
8
+ attr_reader :post, :site
9
+
10
+ def initialize(post)
11
+ @post = post
12
+ @site = post.site
13
+ require 'classifier' if site.lsi
14
+ end
15
+
16
+ def build
17
+ return [] unless self.site.posts.size > 1
18
+
19
+ if self.site.lsi
20
+ build_index
21
+ lsi_related_posts
22
+ else
23
+ most_recent_posts
24
+ end
25
+ end
26
+
27
+
28
+ def build_index
29
+ self.class.lsi ||= begin
30
+ lsi = Classifier::LSI.new(:auto_rebuild => false)
31
+ display("Populating LSI...")
32
+
33
+ self.site.posts.each do |x|
34
+ lsi.add_item(x)
35
+ end
36
+
37
+ display("Rebuilding index...")
38
+ lsi.build_index
39
+ display("")
40
+ lsi
41
+ end
42
+ end
43
+
44
+ def lsi_related_posts
45
+ self.class.lsi.find_related(post.content, 11) - [self.post]
46
+ end
47
+
48
+ def most_recent_posts
49
+ recent_posts = self.site.posts.reverse - [self.post]
50
+ recent_posts.first(10)
51
+ end
52
+
53
+ def display(output)
54
+ $stdout.print("\n")
55
+ $stdout.print(Jekyll.logger.formatted_topic(output))
56
+ $stdout.flush
57
+ end
58
+ end
59
+ end