class Jekyll::LastModifiedDate::Determinator
Attributes
format[RW]
page_path[R]
site_source[R]
Public Class Methods
new(site_source, page_path, format = nil)
click to toggle source
# File lib/jekyll-last-modified-date/determinator.rb, line 9 def initialize(site_source, page_path, format = nil) @site_source = site_source @page_path = page_path @format = format || '%d-%b-%y' end
Public Instance Methods
formatted_last_modified_date()
click to toggle source
# File lib/jekyll-last-modified-date/determinator.rb, line 22 def formatted_last_modified_date return PATH_CACHE[page_path] unless PATH_CACHE[page_path].nil? last_modified = last_modified_at_time.strftime(@format) PATH_CACHE[page_path] = last_modified last_modified end
git()
click to toggle source
# File lib/jekyll-last-modified-date/determinator.rb, line 15 def git return REPO_CACHE[site_source] unless REPO_CACHE[site_source].nil? REPO_CACHE[site_source] = Git.new(site_source) REPO_CACHE[site_source] end
last_modified_at_time()
click to toggle source
# File lib/jekyll-last-modified-date/determinator.rb, line 30 def last_modified_at_time raise Errno::ENOENT, "#{absolute_path_to_article} does not exist!" unless File.exist? absolute_path_to_article Time.at(last_modified_at_unix.to_i) end
last_modified_at_unix()
click to toggle source
# File lib/jekyll-last-modified-date/determinator.rb, line 36 def last_modified_at_unix if git.git_repo? last_commit_date = Executor.sh( 'git', '--git-dir', git.top_level_directory, 'log', '-n', '1', '--format="%ct"', '--', relative_path_from_git_dir )[/\d+/] # last_commit_date can be nil iff the file was not committed. last_commit_date.nil? || last_commit_date.empty? ? mtime(absolute_path_to_article) : last_commit_date else mtime(absolute_path_to_article) end end
to_liquid()
click to toggle source
# File lib/jekyll-last-modified-date/determinator.rb, line 60 def to_liquid @to_liquid ||= last_modified_at_time end
to_s()
click to toggle source
# File lib/jekyll-last-modified-date/determinator.rb, line 56 def to_s @to_s ||= formatted_last_modified_date end
Private Instance Methods
absolute_path_to_article()
click to toggle source
# File lib/jekyll-last-modified-date/determinator.rb, line 66 def absolute_path_to_article @absolute_path_to_article ||= Jekyll.sanitized_path(site_source, @page_path) end
mtime(file)
click to toggle source
# File lib/jekyll-last-modified-date/determinator.rb, line 79 def mtime(file) File.mtime(file).to_i.to_s end
relative_path_from_git_dir()
click to toggle source
# File lib/jekyll-last-modified-date/determinator.rb, line 70 def relative_path_from_git_dir return nil unless git.git_repo? @relative_path_from_git_dir ||= Pathname.new(absolute_path_to_article) .relative_path_from( Pathname.new(File.dirname(git.top_level_directory)) ).to_s end