jekyll-tally-tags 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-tally-tags.rb +205 -0
  3. data/lib/jekyll-tally-tags/docs_to_items.rb +151 -0
  4. data/lib/jekyll-tally-tags/item.rb +90 -0
  5. data/lib/jekyll-tally-tags/items_to_page.rb +128 -0
  6. data/lib/jekyll-tally-tags/methods.rb +44 -0
  7. data/lib/jekyll-tally-tags/pages/base_page.rb +284 -0
  8. data/lib/jekyll-tally-tags/pages/day_page.rb +14 -0
  9. data/lib/jekyll-tally-tags/pages/month_page.rb +14 -0
  10. data/lib/jekyll-tally-tags/pages/multiple_page.rb +14 -0
  11. data/lib/jekyll-tally-tags/pages/single_page.rb +14 -0
  12. data/lib/jekyll-tally-tags/pages/week_page.rb +14 -0
  13. data/lib/jekyll-tally-tags/pages/weeks_page.rb +14 -0
  14. data/lib/jekyll-tally-tags/pages/year_page.rb +70 -0
  15. data/lib/jekyll-tally-tags/{counter.rb → utils.rb} +173 -152
  16. data/lib/jekyll-tally-tags/version.rb +72 -54
  17. metadata +16 -25
  18. data/.gitignore +0 -8
  19. data/.idea/.gitignore +0 -8
  20. data/.idea/inspectionProfiles/Project_Default.xml +0 -6
  21. data/.idea/jekyll-tally-tags.iml +0 -44
  22. data/.idea/misc.xml +0 -4
  23. data/.idea/modules.xml +0 -8
  24. data/.idea/vcs.xml +0 -6
  25. data/.rubocop.yml +0 -13
  26. data/CHANGELOG.md +0 -5
  27. data/CODE_OF_CONDUCT.md +0 -84
  28. data/Gemfile +0 -12
  29. data/Gemfile.lock +0 -74
  30. data/LICENSE.txt +0 -21
  31. data/README.md +0 -43
  32. data/Rakefile +0 -5
  33. data/bin/console +0 -15
  34. data/bin/setup +0 -8
  35. data/jekyll-tally-tags.gemspec +0 -28
  36. data/lib/jekyll-tally-tags/classify.rb +0 -196
  37. data/lib/jekyll-tally-tags/hooks_doc.rb +0 -134
  38. data/lib/jekyll-tally-tags/hooks_logs.rb +0 -57
  39. data/lib/jekyll-tally-tags/subject.rb +0 -143
@@ -1,57 +0,0 @@
1
- module Jekyll
2
- DEBUG = false
3
- Jekyll::Hooks.register :site, :after_init do |data|
4
- puts 'site after_init 在网站初始化时,但是在设置和渲染之前,适合用来修改网站的配置项' if DEBUG
5
- end
6
- Jekyll::Hooks.register :site, :after_reset do |data|
7
- puts 'site after_reset 网站重置之后' if DEBUG
8
- end
9
- Jekyll::Hooks.register :site, :post_read do |site|
10
- puts 'site post_read 在网站数据从磁盘中读取并加载之后' if DEBUG
11
- end
12
- Jekyll::Hooks.register :site, :pre_render do |data|
13
- puts 'site pre_render 在渲染整个网站之前' if DEBUG
14
- end
15
- Jekyll::Hooks.register :site, :post_render do |data|
16
- puts 'site post_render 在渲染整个网站之后,但是在写入任何文件之前' if DEBUG
17
- end
18
- Jekyll::Hooks.register :site, :post_write do |data|
19
- puts 'site post_write 在将整个网站写入磁盘之后' if DEBUG
20
- end
21
- Jekyll::Hooks.register :pages, :post_init do |data|
22
- puts 'pages post_init 每次页面被初始化的时候' if DEBUG
23
- end
24
- Jekyll::Hooks.register :pages, :pre_render do |data|
25
- puts 'pages pre_render 在渲染页面之前' if DEBUG
26
- end
27
- Jekyll::Hooks.register :pages, :post_render do |data|
28
- puts 'pages post_render 在页面渲染之后,但是在页面写入磁盘之前' if DEBUG
29
- end
30
- Jekyll::Hooks.register :pages, :post_write do |data|
31
- puts 'pages post_write 在页面写入磁盘之后' if DEBUG
32
- end
33
- Jekyll::Hooks.register :posts, :post_init do |data|
34
- puts 'posts post_init 每次博客被初始化的时候' if DEBUG
35
- end
36
- Jekyll::Hooks.register :posts, :pre_render do |data|
37
- puts 'posts pre_render 在博客被渲染之前' if DEBUG
38
- end
39
- Jekyll::Hooks.register :posts, :post_render do |data|
40
- puts 'posts post_render 在博客渲染之后,但是在被写入磁盘之前' if DEBUG
41
- end
42
- Jekyll::Hooks.register :posts, :post_write do |data|
43
- puts 'posts post_write 在博客被写入磁盘之后' if DEBUG
44
- end
45
- Jekyll::Hooks.register :documents, :post_init do |data|
46
- puts 'documents post_init 每次文档被初始化的时候' if DEBUG
47
- end
48
- Jekyll::Hooks.register :documents, :pre_render do |data|
49
- puts 'documents pre_render 在渲染文档之前' if DEBUG
50
- end
51
- Jekyll::Hooks.register :documents, :post_render do |data|
52
- puts 'documents post_render 在渲染文档之后,但是在被写入磁盘之前' if DEBUG
53
- end
54
- Jekyll::Hooks.register :documents, :post_write do |data|
55
- puts 'documents post_write 在文档被写入磁盘之后' if DEBUG
56
- end
57
- end
@@ -1,143 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'jekyll'
4
-
5
- module Jekyll
6
- module TallyTags
7
- class Subject < Jekyll::Page
8
- attr_accessor :docs, :type, :slug
9
-
10
- ATTRIBUTES_FOR_LIQUID = %w(
11
- docs
12
- filters
13
- type
14
- title
15
- date
16
- name
17
- path
18
- url
19
- permalink
20
- sum
21
- ).freeze
22
-
23
- # 初始化
24
- # @param [Site] site
25
- # @param [Hash{Symbol => String}] titles
26
- # @param [String] type
27
- # @param [Array<String>] filters
28
- # @param [Array<Document>] docs
29
- def initialize(site, titles, type, filters, docs)
30
- @site = site
31
- @docs = docs
32
- @filters = filters
33
- @type = type
34
- @title = titles
35
- @config = site.config[CLASSIFY]
36
- @slug = slugify_string_title
37
-
38
- @ext = File.extname(relative_path)
39
- @path = relative_path
40
- @name = File.basename(relative_path, @ext)
41
-
42
- @data = {
43
- LAYOUT => layout,
44
- PERMALINK => @config[PERMALINKS][type]
45
- }
46
- @content = ""
47
-
48
- end
49
-
50
- # @return [Array<Float>]
51
- def sum
52
- sum = []
53
- @docs.each do |doc|
54
- (0..doc[COUNT].size - 1).each do |index|
55
- count = doc[COUNT][index].to_f
56
- if !sum[index]
57
- sum[index] = 0
58
- end
59
- sum[index] = sum[index] + count
60
- end
61
- end
62
- sum
63
- end
64
-
65
- # @return [String]
66
- def template
67
- @config.dig(PERMALINKS, type)
68
- end
69
-
70
- # @return [String]
71
- def layout
72
- @config.dig(LAYOUTS, type) || @config[LAYOUT]
73
- end
74
-
75
- # @return [Hash{ String => String}] eg: {:categories => "ruby", :title => "something"}
76
- def url_placeholders
77
- if @title.is_a? Hash
78
- @title.merge(:type => @type)
79
- else
80
- { :name => @slug, :type => @type }
81
- end
82
- end
83
-
84
- # @return [String]
85
- def url
86
- u = @url ||= URL.new(
87
- :template => template,
88
- :placeholders => url_placeholders,
89
- :permalink => nil
90
- ).to_s
91
- rescue ArgumentError
92
- raise ArgumentError, "提供的模板 \"#{template}\" 无效."
93
- end
94
-
95
- def filters
96
- @filters
97
- end
98
-
99
- # @return [String]
100
- def permalink
101
- data.is_a?(Hash) && data[PERMALINK]
102
- end
103
-
104
- # @return [String]
105
- def title
106
- @title if @title.is_a?(String)
107
- end
108
-
109
- # @return [Date]
110
- def date
111
- # if @title.is_a?(Hash)
112
- # args = @title.values.map(&:to_i)
113
- # Date.new(*args)
114
- # end
115
- # TODO: 修复日期
116
- "2011/01/11"
117
- end
118
-
119
- # @return [String]
120
- def relative_path
121
- @relative_path ||=
122
- begin
123
- path = URL.unescape_path(url).gsub(%r!^/!, "")
124
- path = File.join(path, INDEX_HTML) if url.end_with?("/")
125
- path
126
- end
127
- end
128
-
129
- # @return [String]
130
- def inspect
131
- "#<TagsLib:Subject @type=#{@type} @title=#{@title} @data=#{@data.inspect}>"
132
- end
133
-
134
- private
135
-
136
- def slugify_string_title
137
- return unless title.is_a?(String)
138
- Utils.slugify(title, :mode => @config[SLUG_MODE])
139
- end
140
-
141
- end
142
- end
143
- end