alula 0.4.12 → 0.4.13
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/alula/contents/item.rb +16 -27
- data/lib/alula/generators/archive.rb +34 -6
- data/lib/alula/version.rb +1 -1
- metadata +1 -1
data/lib/alula/contents/item.rb
CHANGED
@@ -147,11 +147,6 @@ module Alula
|
|
147
147
|
_old_locale = self.current_locale
|
148
148
|
self.current_locale = locale
|
149
149
|
|
150
|
-
# Flush if we have generator
|
151
|
-
# if @hooks[:render]
|
152
|
-
# instance_exec(locale, &@hooks[:render])
|
153
|
-
# end
|
154
|
-
|
155
150
|
# Make sure our content is parsed
|
156
151
|
parse_liquid(locale)
|
157
152
|
parse_markdown(locale)
|
@@ -268,9 +263,6 @@ module Alula
|
|
268
263
|
else
|
269
264
|
template = @metadata.template || (self.class.to_s == "Alula::Content::Page" ? @site.config.pagelinks : @site.config.permalinks)
|
270
265
|
substitude(template, locale)
|
271
|
-
# self.substitutes(locale).inject(template) { |result, token|
|
272
|
-
# result.gsub(/:#{Regexp.escape token.first}/, token.last)
|
273
|
-
# }.gsub(/\/\//, '/')
|
274
266
|
end
|
275
267
|
# Add .html only if we don't have extension already
|
276
268
|
if ::File.extname(url).empty?
|
@@ -335,24 +327,29 @@ module Alula
|
|
335
327
|
end
|
336
328
|
end
|
337
329
|
|
338
|
-
#
|
330
|
+
# Substitudes for URL
|
339
331
|
def substitude(template, locale = nil)
|
340
|
-
self.substitutes(locale).inject(template) { |result, token|
|
332
|
+
s = self.substitutes(locale).inject(template) { |result, token|
|
341
333
|
result.gsub(/:#{Regexp.escape token.first}/, token.last)
|
342
|
-
}
|
334
|
+
}
|
335
|
+
s.gsub(/\/{2,}/, '/')
|
343
336
|
end
|
344
337
|
|
345
338
|
def substitutes(locale = nil)
|
346
339
|
locale ||= self.current_locale || self.site.config.locale
|
347
340
|
@substitutes[locale] ||= begin
|
348
341
|
subs = {
|
349
|
-
"year"
|
350
|
-
"month"
|
351
|
-
"
|
352
|
-
"
|
353
|
-
"
|
354
|
-
"
|
355
|
-
"
|
342
|
+
"year" => @metadata.date.strftime('%Y'),
|
343
|
+
"month" => @metadata.date.strftime('%m'),
|
344
|
+
"monthname" => @metadata.date.strftime('%B'),
|
345
|
+
"monthabbr" => @metadata.date.strftime('%b'),
|
346
|
+
"day" => @metadata.date.strftime('%d'),
|
347
|
+
"weekday" => @metadata.date.strftime('%A'),
|
348
|
+
"weekdayabbr" => @metadata.date.strftime('%a'),
|
349
|
+
"locale" => (@site.config.locale == locale && @site.config.hides_base_locale ? "" : locale),
|
350
|
+
"name" => CGI.escape(name).gsub('%2F', '/'),
|
351
|
+
"slug" => CGI.escape(@metadata.slug(locale)).gsub('%2F', '/'),
|
352
|
+
"title" => @metadata.title(locale).to_url,
|
356
353
|
}
|
357
354
|
if self.metadata.generator
|
358
355
|
subs.merge!(self.metadata.generator.substitutes(locale, self))
|
@@ -363,19 +360,11 @@ module Alula
|
|
363
360
|
|
364
361
|
private
|
365
362
|
def _last_modified
|
366
|
-
# if @hooks[:last_modified]
|
367
|
-
# return instance_exec(locale, &@hooks[:next])
|
368
|
-
# end
|
369
|
-
#
|
370
363
|
return unless self.class.to_s[/Page|Post/]
|
364
|
+
|
371
365
|
mtime = nil
|
372
366
|
unless @item.nil?
|
373
367
|
mtime = @item.mtime
|
374
|
-
# if self.site.git
|
375
|
-
# rev = %x{git rev-list -n 1 HEAD #{Shellwords.escape(@item.filepath)}}.strip
|
376
|
-
# time = %x{git show --pretty=format:%ai --abbrev-commit #{rev}|head -1}.strip
|
377
|
-
# mtime = Time.parse(time) rescue nil
|
378
|
-
# end
|
379
368
|
end
|
380
369
|
mtime
|
381
370
|
end
|
@@ -17,8 +17,12 @@ module Alula
|
|
17
17
|
options.templates.collect do |template|
|
18
18
|
posts.collect do |post|
|
19
19
|
archives[post.substitude(template, lang)] ||= {}
|
20
|
-
|
21
|
-
archives[post.substitude(template, lang)][
|
20
|
+
key = "archive.title." + template.scan(/:(\w+)*/).flatten.join('-')
|
21
|
+
archives[post.substitude(template, lang)][:title] ||= I18n.t(key, Hash[post.substitutes(lang).map{|k,v|[k.to_sym,v]}].merge(locale: lang))
|
22
|
+
archives[post.substitude(template, lang)][:key] ||= key
|
23
|
+
archives[post.substitude(template, lang)][:content] ||= {}
|
24
|
+
archives[post.substitude(template, lang)][:content][lang] ||= []
|
25
|
+
archives[post.substitude(template, lang)][:content][lang] << post
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
@@ -26,15 +30,39 @@ module Alula
|
|
26
30
|
archives.each do |name, archive|
|
27
31
|
self.site.content.pages << Alula::Content::Page.new({
|
28
32
|
generator: self,
|
29
|
-
posts: archive,
|
30
|
-
title: titles.select {|lang, title| archive.keys.include?(lang)},
|
33
|
+
posts: archive[:content],
|
34
|
+
title: archive[:title],#titles.select {|lang, title| archive.keys.include?(lang)},
|
31
35
|
name: name,
|
32
36
|
slug: name,
|
33
37
|
sidebar: false,
|
34
38
|
template: "/:locale/:name/",
|
35
39
|
site: self.site,
|
36
|
-
view: "archive"
|
37
|
-
|
40
|
+
view: "archive",
|
41
|
+
key: archive[:key],
|
42
|
+
},
|
43
|
+
:previous => ->(hook, locale = nil) {
|
44
|
+
pos = self.navigation(locale).index(self)
|
45
|
+
if pos and pos < (self.navigation(locale).count - 1)
|
46
|
+
self.navigation(locale)[pos + 1]
|
47
|
+
else
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
},
|
51
|
+
:next => ->(hook, locale = nil) {
|
52
|
+
pos = self.navigation(locale).index(self)
|
53
|
+
if pos and pos > 0
|
54
|
+
self.navigation(locale)[pos - 1]
|
55
|
+
else
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
},
|
59
|
+
:navigation => ->(hook, locale = nil) {
|
60
|
+
locale ||= self.current_locale || self.site.config.locale
|
61
|
+
@navigation[locale] ||= self.site.content.pages.select { |item|
|
62
|
+
item.metadata.generator == self.generator and item.metadata.key == self.metadata.key
|
63
|
+
}
|
64
|
+
}
|
65
|
+
)
|
38
66
|
end
|
39
67
|
end
|
40
68
|
|
data/lib/alula/version.rb
CHANGED