Class: Alula::Archive
- Defined in:
- lib/alula/generators/archive.rb
Instance Attribute Summary
Attributes inherited from Generator
Instance Method Summary collapse
Methods inherited from Generator
#allow_compressing?, generators, #generators, #initialize, load, register
Constructor Details
This class inherits a constructor from Alula::Generator
Instance Method Details
#generate ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/alula/generators/archive.rb', line 3 def generate # Loop all languages and count posts per language @languages = fetch_languages # @languages = {} # self.site.content.posts.each do |post| # post.languages.each do |lang| # @languages[lang] ||= [] # @languages[lang] << post # end # end titles = Hash[@languages.collect {|lang, x| [lang, I18n.t("archive.title", locale: lang)]}] archives = {} @languages.each do |lang, posts| .templates.collect do |template| posts.collect do |post| archives[post.substitude(template, lang)] ||= {} title_key = "archive.title." + template.scan(/:(\w+)*/).flatten.join('-') description_key = "archive.description." + template.scan(/:(\w+)*/).flatten.join('-') archives[post.substitude(template, lang)][:title] ||= I18n.t(title_key, Hash[post.substitutes(lang).map{|k,v|[k.to_sym,v]}].merge(locale: lang)) archives[post.substitude(template, lang)][:description] ||= I18n.t(description_key, Hash[post.substitutes(lang).map{|k,v|[k.to_sym,v]}].merge(locale: lang)) archives[post.substitude(template, lang)][:key] ||= title_key archives[post.substitude(template, lang)][:content] ||= {} archives[post.substitude(template, lang)][:content][lang] ||= [] archives[post.substitude(template, lang)][:content][lang] << post end end end archives.each do |name, archive| self.site.content.pages << Alula::Content::Page.new({ generator: self, posts: archive[:content], title: archive[:title], priority: 0.2, description: archive[:description], name: name, slug: name, sidebar: false, template: "/:locale/:name/", site: self.site, view: "archive", key: archive[:key], }, :navigation => ->(hook, locale = nil) { locale ||= self.current_locale || self.site.config.locale @navigation[locale] ||= self.site.content.pages.select { |item| item..generator == self.generator and item..key == self..key } } ) end end |
#substitutes(locale, item) ⇒ Object
59 60 61 62 63 |
# File 'lib/alula/generators/archive.rb', line 59 def substitutes(locale, item) { "page" => item..pagenum.to_s, } end |