jekyll-plugin-gkarchive 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-plugin-gkarchive/version.rb +1 -1
- data/lib/jekyll-plugin-gkarchive.rb +24 -80
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e851c901f4153d8048540ef2f01414939e6028f4a4f6383d3633bccb43cb183
|
4
|
+
data.tar.gz: 14d57bb3565a154d271906730dd75c719ce04098c8877ceb1f7554d8b494712c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abd63284b1ed9df21f324f587a9c4d8fefb95f89aaf57fa6c320ce4898d270222e901a0feffefc3b9af1ede66e098542493b630736bcc80c29be6b734063f5ca
|
7
|
+
data.tar.gz: 89c24461be6410b0dcb1ff4fef6c23b46f03c71341075d06deeda4a0f0cb62a729db83cbbfa6911a45c89810f50b077d38ee76e99284f49e61b40acf20f058d4
|
@@ -6,6 +6,15 @@
|
|
6
6
|
#
|
7
7
|
# Download: https://github.com/jekyll/jekyll-archives
|
8
8
|
#
|
9
|
+
# Sample Config
|
10
|
+
# jekyll-archives:
|
11
|
+
# layout: hc-archive
|
12
|
+
# category:
|
13
|
+
# - account-settings
|
14
|
+
# - deployment
|
15
|
+
# permalinks:
|
16
|
+
# category: '/hc-category/:name/'
|
17
|
+
#
|
9
18
|
# See the documentation for full configuration and usage instructions.
|
10
19
|
# frozen_string_literal: true
|
11
20
|
|
@@ -14,20 +23,16 @@ require "jekyll"
|
|
14
23
|
module Jekyll
|
15
24
|
module Archives
|
16
25
|
# Internal requires
|
17
|
-
autoload :Archive, "jekyll-
|
18
|
-
autoload :VERSION, "jekyll-plugin-gkarchive/version"
|
26
|
+
# autoload :Archive, "jekyll-archives/archive"
|
27
|
+
# autoload :VERSION, "jekyll-plugin-gkarchive/version"
|
19
28
|
|
20
29
|
class Archives < Jekyll::Generator
|
21
30
|
safe true
|
22
31
|
|
23
32
|
DEFAULTS = {
|
24
33
|
"layout" => "archive",
|
25
|
-
"
|
34
|
+
"categories" => [],
|
26
35
|
"permalinks" => {
|
27
|
-
"year" => "/:year/",
|
28
|
-
"month" => "/:year/:month/",
|
29
|
-
"day" => "/:year/:month/:day/",
|
30
|
-
"tag" => "/tag/:name/",
|
31
36
|
"category" => "/category/:name/",
|
32
37
|
},
|
33
38
|
}.freeze
|
@@ -38,94 +43,33 @@ module Jekyll
|
|
38
43
|
|
39
44
|
def generate(site)
|
40
45
|
@site = site
|
41
|
-
|
42
|
-
|
46
|
+
#@posts = site.posts
|
47
|
+
site.collections.each do |coll_name, coll_data|
|
48
|
+
if( !coll_data.nil? && coll_name == 'articles')
|
49
|
+
@posts = coll_data
|
50
|
+
end
|
51
|
+
end
|
43
52
|
|
53
|
+
@archives = []
|
44
54
|
@site.config["jekyll-archives"] = @config
|
45
55
|
|
46
|
-
|
56
|
+
read_categories
|
47
57
|
@site.pages.concat(@archives)
|
48
58
|
|
49
59
|
@site.config["archives"] = @archives
|
50
60
|
end
|
51
61
|
|
52
|
-
# Read archive data from posts
|
53
|
-
def read
|
54
|
-
read_tags
|
55
|
-
read_categories
|
56
|
-
read_dates
|
57
|
-
end
|
58
|
-
|
59
|
-
def read_tags
|
60
|
-
if enabled? "tags"
|
61
|
-
tags.each do |title, posts|
|
62
|
-
@archives << Archive.new(@site, title, "tag", posts)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
62
|
|
67
63
|
def read_categories
|
68
|
-
if enabled? "categories"
|
69
|
-
categories.each do |title, posts|
|
70
|
-
@archives << Archive.new(@site, title, "category", posts)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
64
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
months(posts).each do |month, posts|
|
79
|
-
@archives << Archive.new(@site, { :year => year, :month => month }, "month", posts) if enabled? "month"
|
80
|
-
days(posts).each do |day, posts|
|
81
|
-
@archives << Archive.new(@site, { :year => year, :month => month, :day => day }, "day", posts) if enabled? "day"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# Checks if archive type is enabled in config
|
88
|
-
def enabled?(archive)
|
89
|
-
@config["enabled"] == true || @config["enabled"] == "all" || if @config["enabled"].is_a? Array
|
90
|
-
@config["enabled"].include? archive
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def tags
|
95
|
-
@site.post_attr_hash("tags")
|
96
|
-
end
|
97
|
-
|
98
|
-
def categories
|
99
|
-
@site.post_attr_hash("categories")
|
100
|
-
end
|
101
|
-
|
102
|
-
# Custom `post_attr_hash` method for years
|
103
|
-
def years
|
104
|
-
hash = Hash.new { |h, key| h[key] = [] }
|
105
|
-
|
106
|
-
# In Jekyll 3, Collection#each should be called on the #docs array directly.
|
107
|
-
if Jekyll::VERSION >= "3.0.0"
|
108
|
-
@posts.docs.each { |p| hash[p.date.strftime("%Y")] << p }
|
109
|
-
else
|
110
|
-
@posts.each { |p| hash[p.date.strftime("%Y")] << p }
|
65
|
+
posts = []
|
66
|
+
@posts.docs.each do |key, value|
|
67
|
+
posts << key
|
111
68
|
end
|
112
|
-
|
113
|
-
hash
|
114
|
-
end
|
69
|
+
@config["category"].each { |cat| @archives << Archive.new(@site, cat, "category", posts) }
|
115
70
|
|
116
|
-
def months(year_posts)
|
117
|
-
hash = Hash.new { |h, key| h[key] = [] }
|
118
|
-
year_posts.each { |p| hash[p.date.strftime("%m")] << p }
|
119
|
-
hash.each_value { |posts| posts.sort!.reverse! }
|
120
|
-
hash
|
121
71
|
end
|
122
72
|
|
123
|
-
def days(month_posts)
|
124
|
-
hash = Hash.new { |h, key| h[key] = [] }
|
125
|
-
month_posts.each { |p| hash[p.date.strftime("%d")] << p }
|
126
|
-
hash.each_value { |posts| posts.sort!.reverse! }
|
127
|
-
hash
|
128
|
-
end
|
129
73
|
end
|
130
74
|
end
|
131
75
|
end
|