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

16 lines
389 B
Ruby
Raw Normal View History

2010-09-02 14:42:39 +00:00
def gitmtime
filepath=@item.path.sub('/Scratch/','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}`
2010-09-02 14:51:37 +00:00
if str.nil? or str.empty?
return Time.now
2010-09-02 14:42:39 +00:00
else
return DateTime.parse( str )
end
end