pax_global_header 0000666 0000000 0000000 00000000064 13652535003 0014514 g ustar 00root root 0000000 0000000 52 comment=173bcfda0375fab2f49ea9f5dfaa36d8aa957056 jekyll-last-modified-at-1.3.0/ 0000775 0000000 0000000 00000000000 13652535003 0016130 5 ustar 00root root 0000000 0000000 jekyll-last-modified-at-1.3.0/.github/ 0000775 0000000 0000000 00000000000 13652535003 0017470 5 ustar 00root root 0000000 0000000 jekyll-last-modified-at-1.3.0/.github/FUNDING.yml 0000664 0000000 0000000 00000001052 13652535003 0021303 0 ustar 00root root 0000000 0000000 # These are supported funding model platforms github: gjtorikian patreon: gjtorikian open_collective: garen-torikian #ko_fi: # Replace with a single Ko-fi username #tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel #community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry #liberapay: # Replace with a single Liberapay username issuehunt: gjtorikian #otechie: # Replace with a single Otechie username #custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] jekyll-last-modified-at-1.3.0/.gitignore 0000664 0000000 0000000 00000000253 13652535003 0020120 0 ustar 00root root 0000000 0000000 *.gem _site/ Gemfile.lock spec/fixtures/_posts/1992-09-11-last-modified-at.md spec/fixtures/.jekyll-metadata spec/fixtures/.jekyll-cache spec/dev/out.txt spec/dev/err.txt jekyll-last-modified-at-1.3.0/.rubocop.yml 0000664 0000000 0000000 00000000312 13652535003 0020376 0 ustar 00root root 0000000 0000000 inherit_gem: rubocop-standard: - config/default.yml Style/StringLiterals: Enabled: true EnforcedStyle: single_quotes Naming/FileName: Enabled: false Style/Documentation: Enabled: false jekyll-last-modified-at-1.3.0/.travis.yml 0000664 0000000 0000000 00000000234 13652535003 0020240 0 ustar 00root root 0000000 0000000 language: ruby rvm: - 2.3 - 2.4 - 2.5 - 2.6 sudo: false cache: bundler matrix: include: - script: bundle exec rake rubocop rvm: 2.6.0 jekyll-last-modified-at-1.3.0/Gemfile 0000664 0000000 0000000 00000000204 13652535003 0017417 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true source 'https://rubygems.org' gemspec gem 'jekyll', ENV['JEKYLL_VERSION'] if ENV['JEKYLL_VERSION'] jekyll-last-modified-at-1.3.0/LICENSE 0000664 0000000 0000000 00000002074 13652535003 0017140 0 ustar 00root root 0000000 0000000 The MIT License (MIT) Copyright (c) 2014 Garen J. Torikian Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. jekyll-last-modified-at-1.3.0/README.md 0000664 0000000 0000000 00000002722 13652535003 0017412 0 ustar 00root root 0000000 0000000 # Last Modified At Plugin A liquid tag for Jekyll to indicate the last time a file was modified. This plugin determines a page's last modified date by checking the last Git commit date of source files. In the event Git is not available, the file's `mtime` is used. ## Setting up Open your Gemfile in your Jekyll root folder and add the following: ``` ruby group :jekyll_plugins do gem "jekyll-last-modified-at" end ``` Add the following to your site's `_config.yml` file ```yml plugins: - jekyll-last-modified-at # Optional. The default date format, used if none is specified in the tag. last-modified-at: date-format: '%d-%b-%y' ``` ## Usage There are a few ways to use this gem. You can place the following tag somewhere within your layout: ``` liquid {% last_modified_at %} ``` By default, this creates a time format matching `"%d-%b-%y"` (like "04-Jan-14"). You can also choose to pass along your own time format. For example: ```liquid {% last_modified_at %Y:%B:%A:%d:%S:%R %} ``` That produces "2014:January:Saturday:04." You can also call the method directly on a Jekyll "object," like so: ``` liquid {{ page.last_modified_at }} ``` To format such a time, you'll need to rely on Liquid's `date` filter: ``` liquid {{ page.last_modified_at | date: '%Y:%B:%A:%d:%S:%R' }} ``` (It's generally [more performant to use the `page.last_modified_at` version](https://github.com/gjtorikian/jekyll-last-modified-at/issues/24#issuecomment-55431108) of this plugin.) jekyll-last-modified-at-1.3.0/Rakefile 0000775 0000000 0000000 00000000347 13652535003 0017604 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true require 'bundler' Bundler::GemHelper.install_tasks require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) task default: :spec require 'rubocop/rake_task' RuboCop::RakeTask.new(:rubocop) jekyll-last-modified-at-1.3.0/jekyll-last-modified-at.gemspec 0000664 0000000 0000000 00000001646 13652535003 0024117 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true require File.expand_path('lib/jekyll-last-modified-at/version.rb', __dir__) Gem::Specification.new do |s| s.name = 'jekyll-last-modified-at' s.version = Jekyll::LastModifiedAt::VERSION s.summary = 'A liquid tag for Jekyll to indicate the last time a file was modified.' s.authors = 'Garen J. Torikian' s.homepage = 'https://github.com/gjtorikian/jekyll-last-modified-at' s.license = 'MIT' s.files = Dir['lib/**/*.rb'] s.add_dependency 'jekyll', '>= 3.7', ' < 5.0' s.add_dependency 'posix-spawn', '~> 0.3.9' s.add_development_dependency 'rake' s.add_development_dependency 'rspec', '~> 3.4' s.add_development_dependency 'rubocop' s.add_development_dependency 'rubocop-performance' s.add_development_dependency 'rubocop-standard' s.add_development_dependency 'spork' end jekyll-last-modified-at-1.3.0/lib/ 0000775 0000000 0000000 00000000000 13652535003 0016676 5 ustar 00root root 0000000 0000000 jekyll-last-modified-at-1.3.0/lib/jekyll-last-modified-at.rb 0000664 0000000 0000000 00000001006 13652535003 0023633 0 ustar 00root root 0000000 0000000 # 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 jekyll-last-modified-at-1.3.0/lib/jekyll-last-modified-at/ 0000775 0000000 0000000 00000000000 13652535003 0023311 5 ustar 00root root 0000000 0000000 jekyll-last-modified-at-1.3.0/lib/jekyll-last-modified-at/determinator.rb 0000664 0000000 0000000 00000004503 13652535003 0026335 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true module Jekyll module LastModifiedAt class Determinator attr_reader :site_source, :page_path attr_accessor :format def initialize(site_source, page_path, format = nil) @site_source = site_source @page_path = page_path @format = format || '%d-%b-%y' 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 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.3.0/lib/jekyll-last-modified-at/executor.rb 0000664 0000000 0000000 00000001360 13652535003 0025474 0 ustar 00root root 0000000 0000000 # 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.3.0/lib/jekyll-last-modified-at/git.rb 0000664 0000000 0000000 00000001665 13652535003 0024431 0 ustar 00root root 0000000 0000000 # 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.3.0/lib/jekyll-last-modified-at/hook.rb 0000664 0000000 0000000 00000001210 13652535003 0024570 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true module Jekyll module LastModifiedAt module Hook def self.add_determinator_proc proc { |item| format = item.site.config.dig('last-modified-at', 'date-format') item.data['last_modified_at'] = Determinator.new(item.site.source, item.path, format) } 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.3.0/lib/jekyll-last-modified-at/tag.rb 0000664 0000000 0000000 00000001213 13652535003 0024406 0 ustar 00root root 0000000 0000000 # 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 = context.registers[:site] format = @format || site.config.dig('last-modified-at', 'date-format') article_file = context.environments.first['page']['path'] Determinator.new(site.source, article_file, format) .formatted_last_modified_date end end end end Liquid::Template.register_tag('last_modified_at', Jekyll::LastModifiedAt::Tag) jekyll-last-modified-at-1.3.0/lib/jekyll-last-modified-at/version.rb 0000664 0000000 0000000 00000000145 13652535003 0025323 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true module Jekyll module LastModifiedAt VERSION = '1.3.0' end end jekyll-last-modified-at-1.3.0/script/ 0000775 0000000 0000000 00000000000 13652535003 0017434 5 ustar 00root root 0000000 0000000 jekyll-last-modified-at-1.3.0/script/bootstrap 0000775 0000000 0000000 00000000035 13652535003 0021375 0 ustar 00root root 0000000 0000000 #! /bin/bash bundle install jekyll-last-modified-at-1.3.0/script/cibuild 0000775 0000000 0000000 00000000106 13652535003 0020772 0 ustar 00root root 0000000 0000000 #! /bin/bash script/bootstrap > /dev/null 2>&1 bundle exec rake spec jekyll-last-modified-at-1.3.0/spec/ 0000775 0000000 0000000 00000000000 13652535003 0017062 5 ustar 00root root 0000000 0000000 jekyll-last-modified-at-1.3.0/spec/dev/ 0000775 0000000 0000000 00000000000 13652535003 0017640 5 ustar 00root root 0000000 0000000 jekyll-last-modified-at-1.3.0/spec/dev/.gitkeep 0000664 0000000 0000000 00000000000 13652535003 0021257 0 ustar 00root root 0000000 0000000 jekyll-last-modified-at-1.3.0/spec/fixtures/ 0000775 0000000 0000000 00000000000 13652535003 0020733 5 ustar 00root root 0000000 0000000 jekyll-last-modified-at-1.3.0/spec/fixtures/_config.yml 0000664 0000000 0000000 00000000051 13652535003 0023056 0 ustar 00root root 0000000 0000000 name: Your New Jekyll Site timezone: UTC jekyll-last-modified-at-1.3.0/spec/fixtures/_layouts/ 0000775 0000000 0000000 00000000000 13652535003 0022572 5 ustar 00root root 0000000 0000000 jekyll-last-modified-at-1.3.0/spec/fixtures/_layouts/last_modified_at.html 0000664 0000000 0000000 00000000305 13652535003 0026745 0 ustar 00root root 0000000 0000000