bunto-last-modified-at 1.0.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 +7 -0
- data/lib/bunto-last-modified-at/determinator.rb +100 -0
- data/lib/bunto-last-modified-at/executor.rb +31 -0
- data/lib/bunto-last-modified-at/generator.rb +15 -0
- data/lib/bunto-last-modified-at/tag.rb +21 -0
- data/lib/bunto-last-modified-at/version.rb +5 -0
- data/lib/bunto-last-modified-at.rb +14 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2659ffaedcf6acb38a3c45f8e48a17804c5a0235
|
4
|
+
data.tar.gz: 72921b6a191de8df986e3bab0e9a45e0c88f1fe7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 61a0978617f0619f9964ac392fbc41f22eff411b159403050636cc1fafe25c85dcc3659433838b1b37d5b5486bf4bbd8e239bb76b930fbacb2cc7f1139fae5b1
|
7
|
+
data.tar.gz: a5d97ed1d854d83667c814afd5c9c6d8847e6fa203609a379a97d9d934b651ff19afd42a826d4dbb8724332b1b9f35613fe66c79b482760f14c7b7e0b4adadc8
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Bunto
|
2
|
+
module LastModifiedAt
|
3
|
+
class Determinator
|
4
|
+
attr_reader :site_source, :page_path, :opts
|
5
|
+
|
6
|
+
def initialize(site_source, page_path, opts = {})
|
7
|
+
@site_source = site_source
|
8
|
+
@page_path = page_path
|
9
|
+
@opts = opts
|
10
|
+
end
|
11
|
+
|
12
|
+
def formatted_last_modified_date
|
13
|
+
return PATH_CACHE[page_path] unless PATH_CACHE[page_path].nil?
|
14
|
+
last_modified = last_modified_at_time.strftime(format)
|
15
|
+
PATH_CACHE[page_path] = last_modified
|
16
|
+
last_modified
|
17
|
+
end
|
18
|
+
|
19
|
+
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
|
23
|
+
|
24
|
+
Time.at(last_modified_at_unix.to_i)
|
25
|
+
end
|
26
|
+
|
27
|
+
def last_modified_at_unix
|
28
|
+
if is_git_repo?(site_source)
|
29
|
+
last_commit_date = Executor.sh(
|
30
|
+
'git',
|
31
|
+
'--git-dir',
|
32
|
+
top_level_git_directory,
|
33
|
+
'log',
|
34
|
+
'--format="%ct"',
|
35
|
+
'--',
|
36
|
+
relative_path_from_git_dir
|
37
|
+
)[/\d+/]
|
38
|
+
# 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
|
40
|
+
else
|
41
|
+
mtime(absolute_path_to_article)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_s
|
46
|
+
@to_s ||= formatted_last_modified_date
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_liquid
|
50
|
+
@to_liquid ||= last_modified_at_time
|
51
|
+
end
|
52
|
+
|
53
|
+
def format
|
54
|
+
opts['format'] ||= "%d-%b-%y"
|
55
|
+
end
|
56
|
+
|
57
|
+
def format=(new_format)
|
58
|
+
opts['format'] = new_format
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def absolute_path_to_article
|
64
|
+
@article_file_path ||= Bunto.sanitized_path(site_source, @page_path)
|
65
|
+
end
|
66
|
+
|
67
|
+
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
|
84
|
+
|
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
|
93
|
+
end
|
94
|
+
|
95
|
+
def mtime(file)
|
96
|
+
File.mtime(file)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'posix/spawn'
|
2
|
+
|
3
|
+
module Bunto
|
4
|
+
module LastModifiedAt
|
5
|
+
module Executor
|
6
|
+
extend POSIX::Spawn
|
7
|
+
|
8
|
+
def self.sh(*args)
|
9
|
+
r, w = IO.pipe
|
10
|
+
e, eo = IO.pipe
|
11
|
+
pid = spawn(*args, {
|
12
|
+
:out => w, r => :close,
|
13
|
+
:err => eo, e => :close
|
14
|
+
})
|
15
|
+
|
16
|
+
if pid > 0
|
17
|
+
w.close
|
18
|
+
eo.close
|
19
|
+
out = r.read
|
20
|
+
err = e.read
|
21
|
+
::Process.waitpid(pid)
|
22
|
+
if out
|
23
|
+
"#{out} #{err}".strip
|
24
|
+
end
|
25
|
+
end
|
26
|
+
ensure
|
27
|
+
[r, w, e, eo].each{ |io| io.close rescue nil }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Bunto
|
2
|
+
module LastModifiedAt
|
3
|
+
class Generator < Bunto::Generator
|
4
|
+
|
5
|
+
def generate(site)
|
6
|
+
%w(posts pages docs_to_write).each do |type|
|
7
|
+
site.send(type).each do |item|
|
8
|
+
item.data['last_modified_at'] = Determinator.new(site.source, item.path)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Bunto
|
2
|
+
module LastModifiedAt
|
3
|
+
class Tag < Liquid::Tag
|
4
|
+
def initialize(tag_name, format, tokens)
|
5
|
+
super
|
6
|
+
@format = format.empty? ? nil : format.strip
|
7
|
+
end
|
8
|
+
|
9
|
+
def render(context)
|
10
|
+
site_source = context.registers[:site].source
|
11
|
+
article_file = context.environments.first["page"]["path"]
|
12
|
+
|
13
|
+
Determinator.new(site_source, article_file, {
|
14
|
+
"format" => @format
|
15
|
+
}).formatted_last_modified_date
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Liquid::Template.register_tag('last_modified_at', Bunto::LastModifiedAt::Tag)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
module Bunto
|
3
|
+
module LastModifiedAt
|
4
|
+
autoload :VERSION, 'bunto-last-modified-at/version'
|
5
|
+
autoload :Executor, 'bunto-last-modified-at/executor'
|
6
|
+
autoload :Determinator, 'bunto-last-modified-at/determinator'
|
7
|
+
autoload :Generator, 'bunto-last-modified-at/generator'
|
8
|
+
autoload :Tag, 'bunto-last-modified-at/tag'
|
9
|
+
|
10
|
+
Generator ; Tag
|
11
|
+
|
12
|
+
PATH_CACHE = {}
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bunto-last-modified-at
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Garen J. Torikian
|
8
|
+
- Suriyaa Kudo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-03-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bunto
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: posix-spawn
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.3.9
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.3.9
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.13.0
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.13.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: spork
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description:
|
85
|
+
email:
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- lib/bunto-last-modified-at.rb
|
91
|
+
- lib/bunto-last-modified-at/determinator.rb
|
92
|
+
- lib/bunto-last-modified-at/executor.rb
|
93
|
+
- lib/bunto-last-modified-at/generator.rb
|
94
|
+
- lib/bunto-last-modified-at/tag.rb
|
95
|
+
- lib/bunto-last-modified-at/version.rb
|
96
|
+
homepage: https://github.com/gjtorikian/bunto-last-modified-at
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.2.2
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: A liquid tag for Bunto to indicate the last time a file was modified.
|
120
|
+
test_files: []
|