jekyll-categorize-pages 0.1.4 → 0.1.5
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.
- checksums.yaml +4 -4
- metadata +2 -3
- data/lib/generator.rb +0 -94
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76b0b989a699dd749dab1f178b2798adb6a84bb6
|
4
|
+
data.tar.gz: adf810741c1a6326e89d53a26716ab4ca5b0b301
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1d7afd376a5d85452be160217e2b86724ef7bc889d0b086acb35a8febf5e029d10966dbfcc124aa37cc214cf13ee1b9de42bdbb0521aca416d74758ac49afaf
|
7
|
+
data.tar.gz: a6c45a9d44257c913ba1794c4a1ab1963acb95f98994b30976cc035658c62dc79cf0f535d9d3acd82cb7a1ea4a70d6b912dfc550e47c7078659ec2885aa8d5a6
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-categorize-pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
@@ -30,8 +30,7 @@ email:
|
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
|
-
files:
|
34
|
-
- lib/generator.rb
|
33
|
+
files: []
|
35
34
|
homepage: ''
|
36
35
|
licenses:
|
37
36
|
- MIT
|
data/lib/generator.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "jekyll"
|
3
|
-
|
4
|
-
module Jekyll
|
5
|
-
|
6
|
-
# Injects front matter defaults to set default category/sub-category values
|
7
|
-
class CategorizePageGenerator < Jekyll::Generator
|
8
|
-
# priority :high
|
9
|
-
safe true
|
10
|
-
|
11
|
-
def get_collection(name)
|
12
|
-
@site.collections[name] ? @site.collections[name].docs : []
|
13
|
-
end
|
14
|
-
|
15
|
-
def add_category_and_sub_category(item, values)
|
16
|
-
# puts "adding: #{item.relative_path}"
|
17
|
-
# puts "values: #{values}"
|
18
|
-
|
19
|
-
item.data["category"] = values[:category] # i.data is the front matter header
|
20
|
-
item.data["sub_category"] = values[:sub_category]
|
21
|
-
end
|
22
|
-
|
23
|
-
def add_category_only(item, values)
|
24
|
-
# puts "adding: #{item.relative_path}"
|
25
|
-
# puts "values: #{values}"
|
26
|
-
item.data["category"] = values[:category]
|
27
|
-
# item.data["sub_category"] = values[:sub_category].slice(0, values[:sub_category].length - 3)
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
def isValid?(item)
|
32
|
-
all_categories = @site.data["all_categories"] || [] # sub folders inside collection
|
33
|
-
path = item.relative_path.split('/')
|
34
|
-
|
35
|
-
category = path[1] if path[1] != "index.md"
|
36
|
-
|
37
|
-
# ignore index.md pages
|
38
|
-
if path.include?("index.md")
|
39
|
-
return false
|
40
|
-
end
|
41
|
-
|
42
|
-
# if category folder has no sub categories
|
43
|
-
if path.length == 3
|
44
|
-
# puts "path: #{path}"
|
45
|
-
# puts "length: #{path.length}"
|
46
|
-
header_values = get_header_values_to_add(item)
|
47
|
-
add_category_only(item, header_values)
|
48
|
-
return false
|
49
|
-
end
|
50
|
-
|
51
|
-
return all_categories.include?(category)
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
def get_header_values_to_add(item)
|
56
|
-
all_categories = @site.data["all_categories"] || [] # sub folders inside collection
|
57
|
-
# puts "-----------------------"
|
58
|
-
# puts "all_categories: #{all_categories}"
|
59
|
-
# puts "item.relative_path: #{item.relative_path}"
|
60
|
-
|
61
|
-
path = item.relative_path.split('/')
|
62
|
-
category = path[1] if path[1] != "index.md"
|
63
|
-
# puts "@category: #{@category}"
|
64
|
-
sub_category = path[2] if path[2] != "index.md"
|
65
|
-
# puts "@sub_category: #{@sub_category}"
|
66
|
-
file = path[3] if path[3] != "index.md"
|
67
|
-
# puts "file: #{file}"
|
68
|
-
|
69
|
-
return {
|
70
|
-
:category => category,
|
71
|
-
:sub_category => sub_category,
|
72
|
-
:file => file
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
|
-
def generate(site)
|
77
|
-
@site = site
|
78
|
-
# The collections to add category/sub category front matter values
|
79
|
-
collections = ["pages"] # TODO: Move this variable to _config/_data
|
80
|
-
|
81
|
-
for c in collections
|
82
|
-
for item in get_collection(c)
|
83
|
-
valid_category = isValid?(item)
|
84
|
-
if valid_category
|
85
|
-
header_values = get_header_values_to_add(item)
|
86
|
-
# puts "header_values: #{header_values}"
|
87
|
-
add_category_and_sub_category(item, header_values)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
end
|