Class: Miyano::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/miyano/site.rb

Instance Method Summary collapse

Constructor Details

#initializeSite

Returns a new instance of Site.



4
5
6
7
# File 'lib/miyano/site.rb', line 4

def initialize
  @posts = []
  @tags = {}
end

Instance Method Details

#_tagsObject



29
30
31
# File 'lib/miyano/site.rb', line 29

def _tags
  @tags
end

#add_post(post) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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_tagObject



57
58
59
# File 'lib/miyano/site.rb', line 57

def current_tag
  @current_tag
end

#current_tag=(tag) ⇒ Object



61
62
63
# File 'lib/miyano/site.rb', line 61

def current_tag=(tag)
  @current_tag = tag
end

#postsObject



9
10
11
# File 'lib/miyano/site.rb', line 9

def posts
  @posts
end

#tagsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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