jekyll-last-modified-at 1.1.0 → 1.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40b5f4f5c479ae2ab0289ab0ba8f6c008971832ccba7d4a89bd28c10df21e265
4
- data.tar.gz: 4f5b2603be5d8a2654bbf24b720c8854db71ebef55fa1b102933e2af347fdba1
3
+ metadata.gz: edd7fa5df077c32a987925fd4054649bf7d5ab5f4bcbd9462ae9959f9a48ea44
4
+ data.tar.gz: 8568fc838acae9482e614e37e44d7f6969754b11e908019f08aeda1b807890a2
5
5
  SHA512:
6
- metadata.gz: 87044be27075f0318254c6d40963c50803d23e230a69a55bf15ec5564cc9e832d37fca39b080a3adb46814abca0cf476c3bd3f40e789d75061c30eb25d25c469
7
- data.tar.gz: f52773184e0315adc839525a405489f9f9e56e58b917a310231f21370df867c7706c22b7745b77c701fede01a715f6605af22a592cfff3878ab93e412ab74266
6
+ metadata.gz: 0710007c714ee79c797c5790341c08cb2e67ee9e812d2d0c6cb84c9b72273e368832fe05635d5aae26b21a279932901a84e8f357e11674d238b86ec6d749c2e3
7
+ data.tar.gz: c436b1d4d0bc674b9ac5fa6a3c1f842f02b591aa40cbc65a9fd9b44782cf20d85bd1c527b0678926c334cd6908844ee01e68d0fba3c16ebe58b55a04c99974c9
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Jekyll
3
4
  module LastModifiedAt
@@ -6,9 +7,9 @@ module Jekyll
6
7
  autoload :Determinator, 'jekyll-last-modified-at/determinator'
7
8
  autoload :Tag, 'jekyll-last-modified-at/tag'
8
9
  autoload :Hook, 'jekyll-last-modified-at/hook'
10
+ autoload :Git, 'jekyll-last-modified-at/git'
9
11
 
10
- Tag ; Hook
11
-
12
- PATH_CACHE = {}
12
+ PATH_CACHE = {} # rubocop:disable Style/MutableConstant
13
+ REPO_CACHE = {} # rubocop:disable Style/MutableConstant
13
14
  end
14
15
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module LastModifiedAt
3
5
  class Determinator
@@ -9,34 +11,42 @@ module Jekyll
9
11
  @opts = opts
10
12
  end
11
13
 
14
+ def git
15
+ return REPO_CACHE[site_source] unless REPO_CACHE[site_source].nil?
16
+
17
+ REPO_CACHE[site_source] = Git.new(site_source)
18
+ REPO_CACHE[site_source]
19
+ end
20
+
12
21
  def formatted_last_modified_date
13
22
  return PATH_CACHE[page_path] unless PATH_CACHE[page_path].nil?
23
+
14
24
  last_modified = last_modified_at_time.strftime(format)
15
25
  PATH_CACHE[page_path] = last_modified
16
26
  last_modified
17
27
  end
18
28
 
19
29
  def last_modified_at_time
20
- unless File.exists? absolute_path_to_article
21
- raise Errno::ENOENT, "#{absolute_path_to_article} does not exist!"
22
- end
30
+ raise Errno::ENOENT, "#{absolute_path_to_article} does not exist!" unless File.exist? absolute_path_to_article
23
31
 
24
32
  Time.at(last_modified_at_unix.to_i)
25
33
  end
26
34
 
27
35
  def last_modified_at_unix
28
- if is_git_repo?(site_source)
36
+ if git.git_repo?
29
37
  last_commit_date = Executor.sh(
30
38
  'git',
31
39
  '--git-dir',
32
- top_level_git_directory,
40
+ git.top_level_directory,
33
41
  'log',
42
+ '-n',
43
+ '1',
34
44
  '--format="%ct"',
35
45
  '--',
36
46
  relative_path_from_git_dir
37
47
  )[/\d+/]
38
48
  # last_commit_date can be nil iff the file was not committed.
39
- (last_commit_date.nil? || last_commit_date.empty?) ? mtime(absolute_path_to_article) : last_commit_date
49
+ last_commit_date.nil? || last_commit_date.empty? ? mtime(absolute_path_to_article) : last_commit_date
40
50
  else
41
51
  mtime(absolute_path_to_article)
42
52
  end
@@ -51,7 +61,7 @@ module Jekyll
51
61
  end
52
62
 
53
63
  def format
54
- opts['format'] ||= "%d-%b-%y"
64
+ opts['format'] ||= '%d-%b-%y'
55
65
  end
56
66
 
57
67
  def format=(new_format)
@@ -61,39 +71,20 @@ module Jekyll
61
71
  private
62
72
 
63
73
  def absolute_path_to_article
64
- @article_file_path ||= Jekyll.sanitized_path(site_source, @page_path)
74
+ @absolute_path_to_article ||= Jekyll.sanitized_path(site_source, @page_path)
65
75
  end
66
76
 
67
77
  def relative_path_from_git_dir
68
- return nil unless is_git_repo?(site_source)
69
- @relative_path_from_git_dir ||= Pathname.new(absolute_path_to_article)
70
- .relative_path_from(
71
- Pathname.new(File.dirname(top_level_git_directory))
72
- ).to_s
73
- end
74
-
75
- def top_level_git_directory
76
- @top_level_git_directory ||= begin
77
- Dir.chdir(site_source) do
78
- top_level_git_directory = File.join(Executor.sh("git", "rev-parse", "--show-toplevel"), ".git")
79
- end
80
- rescue
81
- ""
82
- end
83
- end
78
+ return nil unless git.git_repo?
84
79
 
85
- def is_git_repo?(site_source)
86
- @is_git_repo ||= begin
87
- Dir.chdir(site_source) do
88
- Executor.sh("git", "rev-parse", "--is-inside-work-tree").eql? "true"
89
- end
90
- rescue
91
- false
92
- end
80
+ @relative_path_from_git_dir ||= Pathname.new(absolute_path_to_article)
81
+ .relative_path_from(
82
+ Pathname.new(File.dirname(git.top_level_directory))
83
+ ).to_s
93
84
  end
94
85
 
95
86
  def mtime(file)
96
- File.mtime(file)
87
+ File.mtime(file).to_i.to_s
97
88
  end
98
89
  end
99
90
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'posix/spawn'
2
4
 
3
5
  module Jekyll
@@ -8,23 +10,26 @@ module Jekyll
8
10
  def self.sh(*args)
9
11
  r, w = IO.pipe
10
12
  e, eo = IO.pipe
11
- pid = spawn(*args, {
12
- :out => w, r => :close,
13
- :err => eo, e => :close
14
- })
13
+ pid = spawn(*args,
14
+ :out => w, r => :close,
15
+ :err => eo, e => :close)
15
16
 
16
- if pid > 0
17
+ if pid.positive?
17
18
  w.close
18
19
  eo.close
19
20
  out = r.read
20
21
  err = e.read
21
22
  ::Process.waitpid(pid)
22
- if out
23
- "#{out} #{err}".strip
24
- end
23
+ "#{out} #{err}".strip if out
25
24
  end
26
25
  ensure
27
- [r, w, e, eo].each{ |io| io.close rescue nil }
26
+ [r, w, e, eo].each do |io|
27
+ begin
28
+ io.close
29
+ rescue StandardError
30
+ nil
31
+ end
32
+ end
28
33
  end
29
34
  end
30
35
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module LastModifiedAt
5
+ class Git
6
+ attr_reader :site_source
7
+
8
+ def initialize(site_source)
9
+ @site_source = site_source
10
+ @is_git_repo = nil
11
+ end
12
+
13
+ def top_level_directory
14
+ return nil unless git_repo?
15
+
16
+ @top_level_directory ||= begin
17
+ Dir.chdir(@site_source) do
18
+ @top_level_directory = File.join(Executor.sh('git', 'rev-parse', '--show-toplevel'), '.git')
19
+ end
20
+ rescue StandardError
21
+ ''
22
+ end
23
+ end
24
+
25
+ def git_repo?
26
+ return @is_git_repo unless @is_git_repo.nil?
27
+
28
+ @is_git_repo = begin
29
+ Dir.chdir(@site_source) do
30
+ Executor.sh('git', 'rev-parse', '--is-inside-work-tree').eql? 'true'
31
+ end
32
+ rescue StandardError
33
+ false
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module LastModifiedAt
3
5
  module Hook
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module LastModifiedAt
3
5
  class Tag < Liquid::Tag
@@ -8,11 +10,10 @@ module Jekyll
8
10
 
9
11
  def render(context)
10
12
  site_source = context.registers[:site].source
11
- article_file = context.environments.first["page"]["path"]
13
+ article_file = context.environments.first['page']['path']
12
14
 
13
- Determinator.new(site_source, article_file, {
14
- "format" => @format
15
- }).formatted_last_modified_date
15
+ Determinator.new(site_source, article_file,
16
+ 'format' => @format).formatted_last_modified_date
16
17
  end
17
18
  end
18
19
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module LastModifiedAt
3
- VERSION = "1.1.0"
5
+ VERSION = '1.2.0'
4
6
  end
5
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-last-modified-at
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen J. Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-24 00:00:00.000000000 Z
11
+ date: 2019-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: 0.3.9
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: rspec
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -59,7 +73,7 @@ dependencies:
59
73
  - !ruby/object:Gem::Version
60
74
  version: '3.4'
61
75
  - !ruby/object:Gem::Dependency
62
- name: rake
76
+ name: rubocop
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
79
  - - ">="
@@ -73,7 +87,7 @@ dependencies:
73
87
  - !ruby/object:Gem::Version
74
88
  version: '0'
75
89
  - !ruby/object:Gem::Dependency
76
- name: spork
90
+ name: rubocop-performance
77
91
  requirement: !ruby/object:Gem::Requirement
78
92
  requirements:
79
93
  - - ">="
@@ -87,7 +101,21 @@ dependencies:
87
101
  - !ruby/object:Gem::Version
88
102
  version: '0'
89
103
  - !ruby/object:Gem::Dependency
90
- name: redcarpet
104
+ name: rubocop-standard
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: spork
91
119
  requirement: !ruby/object:Gem::Requirement
92
120
  requirements:
93
121
  - - ">="
@@ -109,6 +137,7 @@ files:
109
137
  - lib/jekyll-last-modified-at.rb
110
138
  - lib/jekyll-last-modified-at/determinator.rb
111
139
  - lib/jekyll-last-modified-at/executor.rb
140
+ - lib/jekyll-last-modified-at/git.rb
112
141
  - lib/jekyll-last-modified-at/hook.rb
113
142
  - lib/jekyll-last-modified-at/tag.rb
114
143
  - lib/jekyll-last-modified-at/version.rb
@@ -131,8 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
160
  - !ruby/object:Gem::Version
132
161
  version: '0'
133
162
  requirements: []
134
- rubyforge_project:
135
- rubygems_version: 2.7.6
163
+ rubygems_version: 3.0.6
136
164
  signing_key:
137
165
  specification_version: 4
138
166
  summary: A liquid tag for Jekyll to indicate the last time a file was modified.