#!/usr/bin/env ruby
# encoding: UTF-8
# coding: UTF-8
require 'date'
require 'fileutils'
require File.realdirpath(__FILE__).gsub(/build.*$/, '') + "template/site/main_lang.rb"
# Displays message when something goes wrong
def check condition, err_msg
if condition then puts err_msg + ' For help use -h or --help.'; abort end
end
# To the root directory
Dir.chdir(File.dirname(__FILE__) + '/../..')
# Variables
locale = ''
content = []
template_dir = 'config/template/site/'
# Displays help
if ARGV[0] =~ /-h/
puts "create-indexes-feeds generates the index and feed file for each language."
puts "\nUse:"
puts " create-indexes-feeds"
abort
end
# Formats date in RFC 2822
def format_date date
raw_date = date.gsub(/[\/:]/, ',').gsub(/\s+/, '').split(',')
par_date = DateTime.new(raw_date[0].to_i, raw_date[1].to_i, raw_date[2].to_i,
raw_date[3].to_i, raw_date[4].to_i, raw_date[5].to_i,
DateTime.now.to_s[-6..-6] + DateTime.now.to_s[-4..-4])
return par_date.rfc2822
end
# Itinerates each locale
Dir.glob('content/html/*').each do |local|
locale = local.split('/').last
content = []
rss = []
# Gets the metadata of each post
Dir.glob(local + '/*').each do |f|
if File.basename(f) =~ /^\d+/
file = f.split('/').last
title = File.read(f)
.gsub(/\n/, '')
.gsub(/^.*?
([^<]*?)<\/title>.*$/, '\1')
.strip
date = File.read(f)
.gsub(/\n/, '')
.gsub(/^.*?#{$template_lang[locale]['build']}\s+(\d+.+?)\..*$/, '\1')
.strip
if title != ''
content.push('