diff options
Diffstat (limited to '_plugins/devaway.rb')
-rw-r--r-- | _plugins/devaway.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/_plugins/devaway.rb b/_plugins/devaway.rb index 9ba5018..b7ebec7 100644 --- a/_plugins/devaway.rb +++ b/_plugins/devaway.rb @@ -1,14 +1,27 @@ +require 'date' + module Gentoo class DevawayGenerator < Jekyll::Generator DEVAWAY_XML = '_data/devaway.xml' + # ... @ yyyy/mm/dd HH:MMZ + DATE_REGEXP = /@ (\d+)\/(\d+)\/(\d+) (\d+):(\d)+Z$/ def generate(site) data = Nokogiri::XML(File.open(DEVAWAY_XML)) site.data['devaway'] ||= {} + now = Time.now data.xpath('/devaway/dev').each do |dev| - site.data['devaway'][dev['nick']] = dev.xpath('./reason/text()').first.content + reason = dev.xpath('./reason/text()').first.content + date = Time.utc(*(DATE_REGEXP.match(reason).captures.map(&:to_i))) + away_sec = now - date + + site.data['devaway'][dev['nick']] = { + 'reason' => dev.xpath('./reason/text()').first.content, + 'date' => date, + 'away_days' => away_sec / 24 / 3600, + } end end end |