scratch/output/Scratch/fr/blog/2010-09-02-Use-git-to-calculate-trusted-mtimes/code/gitmtime.rb

16 lines
388 B
Ruby
Raw Normal View History

2011-04-20 12:29:01 +00:00
def gitmtime
filepath=@item.path.sub('/n3blog/','content/html/').sub(/\/$/,'')
ext=%{.#{@item[:extension]}}
filepath<<=ext
if not FileTest.exists?(filepath)
filepath.sub!(ext,%{/index#{ext}})
end
str=`git log -1 --format='%ci' -- #{filepath}`
if str.nil? or str.empty?
return Time.now
else
return DateTime.parse( str )
end
end