jekyll-last-modified-date 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/jekyll-last-modified-date.rb +16 -0
- data/lib/jekyll-last-modified-date/determinator.rb +84 -0
- data/lib/jekyll-last-modified-date/executor.rb +36 -0
- data/lib/jekyll-last-modified-date/git.rb +38 -0
- data/lib/jekyll-last-modified-date/hook.rb +19 -0
- data/lib/jekyll-last-modified-date/tag.rb +22 -0
- data/lib/jekyll-last-modified-date/version.rb +7 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1e17aa123ab964e982f6532ce856f7e5795ecb477a0a54c3075f0275f18e77d4
|
4
|
+
data.tar.gz: 4dff3e6ebb2155feecc3199c29057d886103cdb1d74c41712d72dd1e035b01eb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 721150c3de5fe5292ddbae1bba9c626f74c36b657bac359eb01ad7637c3230eb51b40a5777d5e84b1a8a2bc74d3edcf98bcae1144f538acfc419a851e94b7775
|
7
|
+
data.tar.gz: a92d3fa5b4ad62053dfe2c947cea0b7cb72ed18a668ff948642b5ba383eb2bb105ad6c3e626b430a83f440006ba921134e5d601487a944408b2410ebd59a3caa
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module LastModifiedDate
|
5
|
+
require 'jekyll-last-modified-date/tag'
|
6
|
+
require 'jekyll-last-modified-date/hook'
|
7
|
+
|
8
|
+
autoload :VERSION, 'jekyll-last-modified-date/version'
|
9
|
+
autoload :Executor, 'jekyll-last-modified-date/executor'
|
10
|
+
autoload :Determinator, 'jekyll-last-modified-date/determinator'
|
11
|
+
autoload :Git, 'jekyll-last-modified-date/git'
|
12
|
+
|
13
|
+
PATH_CACHE = {} # rubocop:disable Style/MutableConstant
|
14
|
+
REPO_CACHE = {} # rubocop:disable Style/MutableConstant
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module LastModifiedDate
|
5
|
+
class Determinator
|
6
|
+
attr_reader :site_source, :page_path
|
7
|
+
attr_accessor :format
|
8
|
+
|
9
|
+
def initialize(site_source, page_path, format = nil)
|
10
|
+
@site_source = site_source
|
11
|
+
@page_path = page_path
|
12
|
+
@format = format || '%d-%b-%y'
|
13
|
+
end
|
14
|
+
|
15
|
+
def git
|
16
|
+
return REPO_CACHE[site_source] unless REPO_CACHE[site_source].nil?
|
17
|
+
|
18
|
+
REPO_CACHE[site_source] = Git.new(site_source)
|
19
|
+
REPO_CACHE[site_source]
|
20
|
+
end
|
21
|
+
|
22
|
+
def formatted_last_modified_date
|
23
|
+
return PATH_CACHE[page_path] unless PATH_CACHE[page_path].nil?
|
24
|
+
|
25
|
+
last_modified = last_modified_at_time.strftime(@format)
|
26
|
+
PATH_CACHE[page_path] = last_modified
|
27
|
+
last_modified
|
28
|
+
end
|
29
|
+
|
30
|
+
def last_modified_at_time
|
31
|
+
raise Errno::ENOENT, "#{absolute_path_to_article} does not exist!" unless File.exist? absolute_path_to_article
|
32
|
+
|
33
|
+
Time.at(last_modified_at_unix.to_i)
|
34
|
+
end
|
35
|
+
|
36
|
+
def last_modified_at_unix
|
37
|
+
if git.git_repo?
|
38
|
+
last_commit_date = Executor.sh(
|
39
|
+
'git',
|
40
|
+
'--git-dir',
|
41
|
+
git.top_level_directory,
|
42
|
+
'log',
|
43
|
+
'-n',
|
44
|
+
'1',
|
45
|
+
'--format="%ct"',
|
46
|
+
'--',
|
47
|
+
relative_path_from_git_dir
|
48
|
+
)[/\d+/]
|
49
|
+
# last_commit_date can be nil iff the file was not committed.
|
50
|
+
last_commit_date.nil? || last_commit_date.empty? ? mtime(absolute_path_to_article) : last_commit_date
|
51
|
+
else
|
52
|
+
mtime(absolute_path_to_article)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_s
|
57
|
+
@to_s ||= formatted_last_modified_date
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_liquid
|
61
|
+
@to_liquid ||= last_modified_at_time
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def absolute_path_to_article
|
67
|
+
@absolute_path_to_article ||= Jekyll.sanitized_path(site_source, @page_path)
|
68
|
+
end
|
69
|
+
|
70
|
+
def relative_path_from_git_dir
|
71
|
+
return nil unless git.git_repo?
|
72
|
+
|
73
|
+
@relative_path_from_git_dir ||= Pathname.new(absolute_path_to_article)
|
74
|
+
.relative_path_from(
|
75
|
+
Pathname.new(File.dirname(git.top_level_directory))
|
76
|
+
).to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
def mtime(file)
|
80
|
+
File.mtime(file).to_i.to_s
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'posix/spawn'
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module LastModifiedDate
|
7
|
+
module Executor
|
8
|
+
extend POSIX::Spawn
|
9
|
+
|
10
|
+
def self.sh(*args)
|
11
|
+
r, w = IO.pipe
|
12
|
+
e, eo = IO.pipe
|
13
|
+
pid = spawn(*args,
|
14
|
+
:out => w, r => :close,
|
15
|
+
:err => eo, e => :close)
|
16
|
+
|
17
|
+
if pid.positive?
|
18
|
+
w.close
|
19
|
+
eo.close
|
20
|
+
out = r.read
|
21
|
+
err = e.read
|
22
|
+
::Process.waitpid(pid)
|
23
|
+
"#{out} #{err}".strip if out
|
24
|
+
end
|
25
|
+
ensure
|
26
|
+
[r, w, e, eo].each do |io|
|
27
|
+
begin
|
28
|
+
io.close
|
29
|
+
rescue StandardError
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module LastModifiedDate
|
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
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module LastModifiedDate
|
5
|
+
module Hook
|
6
|
+
def self.add_determinator_proc
|
7
|
+
proc { |item|
|
8
|
+
format = item.site.config.dig('last-modified-date', 'date-format')
|
9
|
+
item.data['last_modified_date'] = Determinator.new(item.site.source, item.path,
|
10
|
+
format)
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
Jekyll::Hooks.register :posts, :post_init, &Hook.add_determinator_proc
|
15
|
+
Jekyll::Hooks.register :pages, :post_init, &Hook.add_determinator_proc
|
16
|
+
Jekyll::Hooks.register :documents, :post_init, &Hook.add_determinator_proc
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module LastModifiedDate
|
5
|
+
class Tag < Liquid::Tag
|
6
|
+
def initialize(tag_name, format, tokens)
|
7
|
+
super
|
8
|
+
@format = format.empty? ? nil : format.strip
|
9
|
+
end
|
10
|
+
|
11
|
+
def render(context)
|
12
|
+
site = context.registers[:site]
|
13
|
+
format = @format || site.config.dig('last-modified-date', 'date-format')
|
14
|
+
article_file = context.environments.first['page']['path']
|
15
|
+
Determinator.new(site.source, article_file, format)
|
16
|
+
.formatted_last_modified_date
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Liquid::Template.register_tag('last_modified_date', Jekyll::LastModifiedDate::Tag)
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-last-modified-date
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Garen J. Torikian
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.7'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.7'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: posix-spawn
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.3.9
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
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'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.4'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.4'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rubocop
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rubocop-performance
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
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
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
description:
|
132
|
+
email:
|
133
|
+
executables: []
|
134
|
+
extensions: []
|
135
|
+
extra_rdoc_files: []
|
136
|
+
files:
|
137
|
+
- lib/jekyll-last-modified-date.rb
|
138
|
+
- lib/jekyll-last-modified-date/determinator.rb
|
139
|
+
- lib/jekyll-last-modified-date/executor.rb
|
140
|
+
- lib/jekyll-last-modified-date/git.rb
|
141
|
+
- lib/jekyll-last-modified-date/hook.rb
|
142
|
+
- lib/jekyll-last-modified-date/tag.rb
|
143
|
+
- lib/jekyll-last-modified-date/version.rb
|
144
|
+
homepage: https://github.com/Hofled/jekyll-last-modified-at
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
metadata: {}
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
requirements: []
|
163
|
+
rubygems_version: 3.1.2
|
164
|
+
signing_key:
|
165
|
+
specification_version: 4
|
166
|
+
summary: A liquid tag for Jekyll to indicate the last time a file was modified.
|
167
|
+
test_files: []
|