jekyll-last-modified-at 0.1.1 → 0.2.0
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-modified-at.rb +32 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e40cd5bfe078781583ad9cf56e006a4b4ee2cfc
|
4
|
+
data.tar.gz: cddd2dad3bbfac52208411af467ecccdb6272b20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4ceefbac50cf94df8bd5ff8f14ae2ab0d470f40afa39424ba5a3f015ac7782d378a675f88f12d79c4e2d3851d6b9b36da7b8249444a0e5eee28fe9049e35131
|
7
|
+
data.tar.gz: c544631a70779551de0d98577cc2633d6eeca4c42199b32c6f46bb5a7bcfc09968d939119c4e3b6ad73279f166420798665a4745e316ac19f9f488b730139210
|
@@ -6,12 +6,41 @@ module Jekyll
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def render(context)
|
9
|
+
site_source = context.registers[:site].source
|
9
10
|
article_file = context.environments.first["page"]["path"]
|
10
|
-
article_file_path = File.expand_path(article_file,
|
11
|
-
|
12
|
-
|
11
|
+
article_file_path = File.expand_path(article_file, site_source)
|
12
|
+
|
13
|
+
unless File.exists? article_file_path
|
14
|
+
raise Errno::ENOENT, "#{article_file_path} does not exist!"
|
15
|
+
end
|
16
|
+
|
17
|
+
if is_git_repo?(site_source)
|
18
|
+
top_level_git_directory = ""
|
19
|
+
Dir.chdir(site_source) do
|
20
|
+
top_level_git_directory = File.join(`git rev-parse --show-toplevel`.strip, ".git")
|
21
|
+
end
|
22
|
+
relative_file_path = File.expand_path(article_file_path, top_level_git_directory)
|
23
|
+
last_commit_date = IO.popen(['git', '--git-dir', top_level_git_directory, 'log', '--format="%ct"', '--', relative_file_path]).read[/\d+/]
|
24
|
+
# last_commit_date can be nil iff the file was not committed.
|
25
|
+
last_modified_time = (last_commit_date.nil? || last_commit_date.empty?) ? mtime(article_file_path) : last_commit_date
|
26
|
+
else
|
27
|
+
last_modified_time = mtime(article_file_path)
|
28
|
+
end
|
29
|
+
|
13
30
|
Time.at(last_modified_time.to_i).strftime(@format || "%d-%b-%y")
|
14
31
|
end
|
32
|
+
|
33
|
+
def is_git_repo?(site_source)
|
34
|
+
Dir.chdir(site_source) do
|
35
|
+
`git rev-parse --is-inside-work-tree`.strip == "true"
|
36
|
+
end
|
37
|
+
rescue
|
38
|
+
false
|
39
|
+
end
|
40
|
+
|
41
|
+
def mtime(file)
|
42
|
+
File.mtime(file)
|
43
|
+
end
|
15
44
|
end
|
16
45
|
end
|
17
46
|
|
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: 0.
|
4
|
+
version: 0.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: 2014-01-
|
11
|
+
date: 2014-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|