jekyll-last-commit 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-last-commit/generator.rb +78 -37
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5e8ca51ac4e8b52849fcfcfec308024e65fcfb88535c4d95a2543aa098326c4
|
4
|
+
data.tar.gz: 64dfaa2a3f92cbcc7b183492143406619b0d3384124c83269be5b2eaa5d185d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b21f0e0acb5a08c19fce6f53b8ab3fd4112839cea6edf668409f92cba53d267cf07137ae39c5e87bd5adfe1178e52eed59312596f0ef480d14a657da9f5a0760
|
7
|
+
data.tar.gz: 1c5a7f7d3195e2bd98cb55874a7279a02d78e0adfb8a8985d09ee7a1b3b34e749294098d6635a088100f1db8d62c967323bba2cc7cedab36e42034664929e06d
|
@@ -2,66 +2,107 @@ require 'jekyll'
|
|
2
2
|
|
3
3
|
module JekyllLastCommit
|
4
4
|
class Generator < Jekyll::Generator
|
5
|
+
priority :highest
|
5
6
|
|
6
7
|
def generate(site)
|
7
|
-
|
8
|
-
repo_man.discover_repo()
|
9
|
-
repo_man.discover_commits(site.documents.map {|d| d.relative_path })
|
10
|
-
repo_man.discover_commits(site.pages.map {|p| p.relative_path })
|
8
|
+
@site = site
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
@repo_man = JekyllLastCommit::RepoMan.new(site.source)
|
11
|
+
@repo_man.discover_repo()
|
14
12
|
|
15
|
-
|
16
|
-
|
13
|
+
@date_format = site.config.dig('jekyll-last-commit', 'date_format')
|
14
|
+
@date_format ||= '%B %d, %Y'
|
17
15
|
|
18
|
-
site.
|
19
|
-
|
16
|
+
@should_fall_back_to_mtime = site.config.dig('jekyll-last-commit', 'should_fall_back_to_mtime')
|
17
|
+
@should_fall_back_to_mtime ||= true
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
@repo_man.discover_commits(site.documents.map {|d| d.relative_path })
|
20
|
+
populate_jekyll(site.documents)
|
21
|
+
|
22
|
+
@repo_man.discover_commits(site.pages.map {|p| p.relative_path })
|
23
|
+
populate_jekyll(site.pages)
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
index_static_files = site.config.dig('jekyll-last-commit', 'index_static_files')
|
26
|
+
index_static_files ||= false
|
27
|
+
if index_static_files
|
28
|
+
@repo_man.discover_commits(site.static_files.map {|sf| '.' + sf.relative_path })
|
29
|
+
populate_jekyll(site.static_files, '.')
|
30
|
+
end
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
|
32
|
+
index_data_files = site.config.dig('jekyll-last-commit', 'index_data_files')
|
33
|
+
index_data_files ||= false
|
34
|
+
if index_data_files
|
35
|
+
data_file_extensions = ['.yml', '.yaml', '.json', '.tsv', '.csv']
|
36
|
+
data_files = []
|
37
|
+
site.data.keys.each do |data_file|
|
38
|
+
data_file_extensions.each do |data_file_extension|
|
39
|
+
data_file_name = data_file + data_file_extension
|
40
|
+
if File.file?('./_data/' + data_file_name)
|
41
|
+
data_files.append(data_file_name)
|
42
|
+
break
|
31
43
|
end
|
32
44
|
end
|
33
|
-
else
|
34
|
-
raw_time = Time.at(commit["time"].to_i)
|
35
|
-
|
36
|
-
document.data['last_commit'] = commit
|
37
|
-
document.data['last_modified_at'] = raw_time
|
38
|
-
document.data['last_modified_at_formatted'] = raw_time.strftime(date_format)
|
39
45
|
end
|
46
|
+
|
47
|
+
data_files_key = site.config.dig('jekyll-last-commit', 'data_files_key')
|
48
|
+
data_files_key ||= 'meta'
|
49
|
+
|
50
|
+
@repo_man.discover_commits(data_files.map {|df| './_data/' + df })
|
51
|
+
|
52
|
+
site.data[data_files_key] = {}
|
53
|
+
populate_data(data_files, site.data[data_files_key], './_data/')
|
40
54
|
end
|
55
|
+
end
|
41
56
|
|
42
|
-
|
43
|
-
|
57
|
+
def populate_jekyll(files, prepend_path = '')
|
58
|
+
files.each do |file|
|
59
|
+
commit = @repo_man.find_commit(prepend_path + file.relative_path)
|
44
60
|
|
45
61
|
if commit.nil?
|
46
|
-
if should_fall_back_to_mtime
|
47
|
-
|
62
|
+
if @should_fall_back_to_mtime
|
63
|
+
path_file = Jekyll.sanitized_path(@site.source, prepend_path + file.relative_path)
|
48
64
|
|
49
|
-
if File.file?(
|
50
|
-
raw_time = Time.at(File.mtime(
|
51
|
-
|
52
|
-
|
65
|
+
if File.file?(path_file)
|
66
|
+
raw_time = Time.at(File.mtime(path_file).to_i)
|
67
|
+
file.data['commit'] = prepend_path + file.relative_path
|
68
|
+
file.data['last_modified_at'] = raw_time
|
69
|
+
file.data['last_modified_at_formatted'] = raw_time.strftime(@date_format)
|
53
70
|
end
|
54
71
|
end
|
55
72
|
|
56
73
|
else
|
57
74
|
raw_time = Time.at(commit["time"].to_i)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
page.data['last_modified_at_formatted'] = raw_time.strftime(date_format)
|
75
|
+
file.data['last_commit'] = commit
|
76
|
+
file.data['last_modified_at'] = raw_time
|
77
|
+
file.data['last_modified_at_formatted'] = raw_time.strftime(@date_format)
|
62
78
|
end
|
63
79
|
end
|
64
80
|
end
|
65
81
|
|
82
|
+
def populate_data(source, output = {}, prepend_path = '')
|
83
|
+
source.each do |file|
|
84
|
+
output[file] ||= {}
|
85
|
+
|
86
|
+
relative_path = prepend_path + file
|
87
|
+
commit = @repo_man.find_commit(relative_path)
|
88
|
+
|
89
|
+
if commit.nil?
|
90
|
+
if @should_fall_back_to_mtime
|
91
|
+
path_file = Jekyll.sanitized_path(@site.source, relative_path)
|
92
|
+
|
93
|
+
if File.file?(file)
|
94
|
+
raw_time = Time.at(File.mtime(path_file).to_i)
|
95
|
+
output[file]['last_modified_at'] = raw_time
|
96
|
+
output[file]['last_modified_at_formatted'] = raw_time.strftime(@date_format)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
else
|
100
|
+
raw_time = Time.at(commit['time'].to_i)
|
101
|
+
output[file]['last_commit'] = commit
|
102
|
+
output[file]['last_modified_at'] = raw_time
|
103
|
+
output[file]['last_modified_at_formatted'] = raw_time.strftime(@date_format)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
66
107
|
end
|
67
|
-
end
|
108
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-last-commit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kip Landergren
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|