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| 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 end