module Nanoc::Helpers::Blogging
Public Instance Methods
Source
# File lib/nanoc/helpers/blogging.rb, line 7 def articles blk = -> { @items.select { |item| item[:kind] == 'article' } } if @items.frozen? @article_items ||= blk.call else blk.call end end
@return [Array]
Source
# File lib/nanoc/helpers/blogging.rb, line 193 def atom_feed(params = {}) require 'builder' # Create builder builder = AtomFeedBuilder.new(@config, @item) # Fill builder builder.alt_link = params[:alt_link] builder.id = params[:id] builder.limit = params[:limit] || 5 builder.relevant_articles = params[:articles] || articles || [] builder.preserve_order = params.fetch(:preserve_order, false) builder.content_proc = params[:content_proc] || ->(a) { a.compiled_content(snapshot: :pre) } builder.excerpt_proc = params[:excerpt_proc] || ->(a) { a[:excerpt] } builder.title_proc = params[:title_proc] || ->(a) { a[:title] } builder.id_proc = params[:id_proc] || ->(a) { atom_tag_for(a) } builder.title = params[:title] || @item[:title] || @config[:title] builder.author_name = params[:author_name] || @item[:author_name] || @config[:author_name] builder.author_uri = params[:author_uri] || @item[:author_uri] || @config[:author_uri] builder.icon = params[:icon] builder.logo = params[:logo] # Run builder.validate builder.build end
@option params [Number] :limit @option params [Array] :articles @option params [Boolean] :preserve_order @option params [Proc] :content_proc @option params [Proc] :excerpt_proc @option params [Proc] :title_proc @option params [Proc] :id_proc @option params [String] :alt_link @option params [String] :id @option params [String] :title @option params [String] :author_name @option params [String] :author_uri @option params [String] :icon @option params [String] :logo
@return [String]
Source
# File lib/nanoc/helpers/blogging.rb, line 248 def atom_tag_for(item) hostname, base_dir = %r{^.+?://([^/]+)(.*)$}.match(@config[:base_url])[1..2] formatted_date = attribute_to_time(item[:created_at]).__nanoc_to_iso8601_date 'tag:' + hostname + ',' + formatted_date + ':' + base_dir + (item.path || item.identifier.to_s) end
@return [String]
Source
# File lib/nanoc/helpers/blogging.rb, line 259 def attribute_to_time(arg) case arg when DateTime arg.to_time when Date Time.utc(arg.year, arg.month, arg.day) when String Time.parse(arg) else arg end end
@param [String, Time
, Date, DateTime] arg
@return [Time]
Source
# File lib/nanoc/helpers/blogging.rb, line 238 def feed_url # Check attributes if @config[:base_url].nil? raise Nanoc::Core::TrivialError.new('Cannot build Atom feed: site configuration has no base_url') end @item[:feed_url] || @config[:base_url] + @item.path end
@return [String]
Source
# File lib/nanoc/helpers/blogging.rb, line 17 def sorted_articles blk = -> { articles.sort_by { |a| attribute_to_time(a[:created_at]) }.reverse } if @items.frozen? @sorted_article_items ||= blk.call else blk.call end end
@return [Array]
Source
# File lib/nanoc/helpers/blogging.rb, line 221 def url_for(item) # Check attributes if @config[:base_url].nil? raise Nanoc::Core::TrivialError.new('Cannot build Atom feed: site configuration has no base_url') end # Build URL if item[:custom_url_in_feed] item[:custom_url_in_feed] elsif item[:custom_path_in_feed] @config[:base_url] + item[:custom_path_in_feed] elsif item.path @config[:base_url] + item.path end end
@return [String]