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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 545441f5818c9b03538f579d7635922c4d5d7b8e589f8260be880d2edc06173f
4
- data.tar.gz: a8ef1cec4beedd36ce060af9844e93be188e17f9cd40c3b3f20c1a0b2c08aada
3
+ metadata.gz: b5e8ca51ac4e8b52849fcfcfec308024e65fcfb88535c4d95a2543aa098326c4
4
+ data.tar.gz: 64dfaa2a3f92cbcc7b183492143406619b0d3384124c83269be5b2eaa5d185d9
5
5
  SHA512:
6
- metadata.gz: 43926e5afb45d6af9d59d4b775d18bc35dd4df9c75b2a70ea5f40b839b0bf96405088767d5e6e61e90a91e8c5f41d5c7ef6be7865cfcedbdaf4153433f77c067
7
- data.tar.gz: fa3dedb65542e16d3c02b9ce1fa50ed0082fe029e89c5a649b074859f4b0f6ff42969dec6c8f218d495035acb90219405c629bea8f42ae7837c69ccdd4dd86b4
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
- repo_man = JekyllLastCommit::RepoMan.new(site.source)
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
- date_format = site.config.dig('jekyll-last-commit', 'date_format')
13
- date_format ||= '%B %d, %Y'
10
+ @repo_man = JekyllLastCommit::RepoMan.new(site.source)
11
+ @repo_man.discover_repo()
14
12
 
15
- should_fall_back_to_mtime = site.config.dig('jekyll-last-commit', 'should_fall_back_to_mtime')
16
- should_fall_back_to_mtime = should_fall_back_to_mtime.nil? ? true : should_fall_back_to_mtime
13
+ @date_format = site.config.dig('jekyll-last-commit', 'date_format')
14
+ @date_format ||= '%B %d, %Y'
17
15
 
18
- site.documents.each do |document|
19
- commit = repo_man.find_commit(document.relative_path)
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
- if commit.nil?
22
- if should_fall_back_to_mtime
23
- path_document = Jekyll.sanitized_path(site.source, document.relative_path)
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
- if File.file?(path_document)
26
- raw_time = Time.at(File.mtime(path_document).to_i)
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
- Jekyll.logger.warn "JekyllLastCommit: unable to find commit information for #{document.relative_path}. falling back to `mtime` for last_modified_at"
29
- document.data['last_modified_at'] = raw_time
30
- document.data['last_modified_at_formatted'] = raw_time.strftime(date_format)
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
- site.pages.each do |page|
43
- commit = repo_man.find_commit(page.relative_path)
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
- path_page = Jekyll.sanitized_path(site.source, page.relative_path)
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?(path_page)
50
- raw_time = Time.at(File.mtime(path_page).to_i)
51
- page.data['last_modified_at'] = raw_time
52
- page.data['last_modified_at_formatted'] = raw_time.strftime(date_format)
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
- page.data['last_commit'] = commit
60
- page.data['last_modified_at'] = raw_time
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.3
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: 2022-12-18 00:00:00.000000000 Z
11
+ date: 2024-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll