jekyll-last-modified-at-1.2.1/0000755000004100000410000000000013571311137016160 5ustar www-datawww-datajekyll-last-modified-at-1.2.1/jekyll-last-modified-at.gemspec0000644000004100000410000000533213571311137024143 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: jekyll-last-modified-at 1.2.1 ruby lib Gem::Specification.new do |s| s.name = "jekyll-last-modified-at".freeze s.version = "1.2.1" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["Garen J. Torikian".freeze] s.date = "2019-12-02" s.files = ["lib/jekyll-last-modified-at.rb".freeze, "lib/jekyll-last-modified-at/determinator.rb".freeze, "lib/jekyll-last-modified-at/executor.rb".freeze, "lib/jekyll-last-modified-at/git.rb".freeze, "lib/jekyll-last-modified-at/hook.rb".freeze, "lib/jekyll-last-modified-at/tag.rb".freeze, "lib/jekyll-last-modified-at/version.rb".freeze] s.homepage = "https://github.com/gjtorikian/jekyll-last-modified-at".freeze s.licenses = ["MIT".freeze] s.rubygems_version = "2.5.2.1".freeze s.summary = "A liquid tag for Jekyll to indicate the last time a file was modified.".freeze if s.respond_to? :specification_version then s.specification_version = 4 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q.freeze, ["< 5.0", ">= 3.7"]) s.add_runtime_dependency(%q.freeze, ["~> 0.3.9"]) s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, ["~> 3.4"]) s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, [">= 0"]) else s.add_dependency(%q.freeze, ["< 5.0", ">= 3.7"]) s.add_dependency(%q.freeze, ["~> 0.3.9"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, ["~> 3.4"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) end else s.add_dependency(%q.freeze, ["< 5.0", ">= 3.7"]) s.add_dependency(%q.freeze, ["~> 0.3.9"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, ["~> 3.4"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) end end jekyll-last-modified-at-1.2.1/lib/0000755000004100000410000000000013571311137016726 5ustar www-datawww-datajekyll-last-modified-at-1.2.1/lib/jekyll-last-modified-at/0000755000004100000410000000000013571311137023341 5ustar www-datawww-datajekyll-last-modified-at-1.2.1/lib/jekyll-last-modified-at/version.rb0000644000004100000410000000014513571311137025353 0ustar www-datawww-data# frozen_string_literal: true module Jekyll module LastModifiedAt VERSION = '1.2.1' end end jekyll-last-modified-at-1.2.1/lib/jekyll-last-modified-at/tag.rb0000644000004100000410000000113413571311137024440 0ustar www-datawww-data# frozen_string_literal: true module Jekyll module LastModifiedAt class Tag < Liquid::Tag def initialize(tag_name, format, tokens) super @format = format.empty? ? nil : format.strip end def render(context) site_source = context.registers[:site].source article_file = context.environments.first['page']['path'] Determinator.new(site_source, article_file, 'format' => @format).formatted_last_modified_date end end end end Liquid::Template.register_tag('last_modified_at', Jekyll::LastModifiedAt::Tag) jekyll-last-modified-at-1.2.1/lib/jekyll-last-modified-at/determinator.rb0000644000004100000410000000465113571311137026371 0ustar www-datawww-data# frozen_string_literal: true module Jekyll module LastModifiedAt class Determinator attr_reader :site_source, :page_path, :opts def initialize(site_source, page_path, opts = {}) @site_source = site_source @page_path = page_path @opts = opts end 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 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 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 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 def to_s @to_s ||= formatted_last_modified_date end def to_liquid @to_liquid ||= last_modified_at_time end def format opts['format'] ||= '%d-%b-%y' end def format=(new_format) opts['format'] = new_format end private def absolute_path_to_article @absolute_path_to_article ||= Jekyll.sanitized_path(site_source, @page_path) end 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 def mtime(file) File.mtime(file).to_i.to_s end end end end jekyll-last-modified-at-1.2.1/lib/jekyll-last-modified-at/hook.rb0000644000004100000410000000077213571311137024634 0ustar www-datawww-data# frozen_string_literal: true module Jekyll module LastModifiedAt module Hook def self.add_determinator_proc proc { |item| item.data['last_modified_at'] = Determinator.new(item.site.source, item.path) } end Jekyll::Hooks.register :posts, :post_init, &Hook.add_determinator_proc Jekyll::Hooks.register :pages, :post_init, &Hook.add_determinator_proc Jekyll::Hooks.register :documents, :post_init, &Hook.add_determinator_proc end end end jekyll-last-modified-at-1.2.1/lib/jekyll-last-modified-at/executor.rb0000644000004100000410000000136013571311137025524 0ustar www-datawww-data# frozen_string_literal: true require 'posix/spawn' module Jekyll module LastModifiedAt module Executor extend POSIX::Spawn def self.sh(*args) r, w = IO.pipe e, eo = IO.pipe pid = spawn(*args, :out => w, r => :close, :err => eo, e => :close) if pid.positive? w.close eo.close out = r.read err = e.read ::Process.waitpid(pid) "#{out} #{err}".strip if out end ensure [r, w, e, eo].each do |io| begin io.close rescue StandardError nil end end end end end end jekyll-last-modified-at-1.2.1/lib/jekyll-last-modified-at/git.rb0000644000004100000410000000166513571311137024461 0ustar www-datawww-data# frozen_string_literal: true module Jekyll module LastModifiedAt class Git attr_reader :site_source def initialize(site_source) @site_source = site_source @is_git_repo = nil end def top_level_directory return nil unless git_repo? @top_level_directory ||= begin Dir.chdir(@site_source) do @top_level_directory = File.join(Executor.sh('git', 'rev-parse', '--show-toplevel'), '.git') end rescue StandardError '' end end def git_repo? return @is_git_repo unless @is_git_repo.nil? @is_git_repo = begin Dir.chdir(@site_source) do Executor.sh('git', 'rev-parse', '--is-inside-work-tree').eql? 'true' end rescue StandardError false end end end end end jekyll-last-modified-at-1.2.1/lib/jekyll-last-modified-at.rb0000644000004100000410000000100613571311137023663 0ustar www-datawww-data# frozen_string_literal: true module Jekyll module LastModifiedAt require 'jekyll-last-modified-at/tag' require 'jekyll-last-modified-at/hook' autoload :VERSION, 'jekyll-last-modified-at/version' autoload :Executor, 'jekyll-last-modified-at/executor' autoload :Determinator, 'jekyll-last-modified-at/determinator' autoload :Git, 'jekyll-last-modified-at/git' PATH_CACHE = {} # rubocop:disable Style/MutableConstant REPO_CACHE = {} # rubocop:disable Style/MutableConstant end end