class Miyano::Site

Public Class Methods

new() click to toggle source
# File lib/miyano/site.rb, line 4
def initialize
  @posts = []
  @tags = {}
end

Public Instance Methods

_tags() click to toggle source
# File lib/miyano/site.rb, line 29
def _tags
  @tags
end
add_post(post) click to toggle source
# File lib/miyano/site.rb, line 13
def add_post(post)
  @posts << post
  @posts.sort_by! {|p| [p.mod_date, p.cre_date]}
  @posts.reverse!

  post.tags.each do |tag|
    if @tags.include? tag
      @tags[tag] += 1
    else
      @tags[tag] = 1
    end
  end
  @tags = @tags.sort_by {|key, value| [-value, key.length]}
               .to_h
end
current_tag() click to toggle source
# File lib/miyano/site.rb, line 57
def current_tag
  @current_tag
end
current_tag=(tag) click to toggle source
# File lib/miyano/site.rb, line 61
def current_tag=(tag)
  @current_tag = tag
end
posts() click to toggle source
# File lib/miyano/site.rb, line 9
def posts
  @posts
end
tags() click to toggle source
# File lib/miyano/site.rb, line 33
def tags
  prefix = @current_tag
  ret_tags = []

  if prefix.nil?
    @tags.each do |_t, _|
      t = _t.split("/").first
      ret_tags << t unless ret_tags.include? t
    end
    return ret_tags
  end

  @tags.each do |_t, _|
    next if _t.length <= prefix.length
    if _t.start_with? prefix
      t = _t.delete_prefix prefix
      t = t.delete_prefix! "/"
      t = t.split("/").first if t
      ret_tags << t unless t.nil? or ret_tags.include? t
    end
  end
  return  ret_tags
end