#!/usr/bin/ruby ############# # VARIABLES # ############# TEMPLATE_DIR = "#{ENV["HOME"]}/templates/" SELF_DIR = "#{ENV["HOME"]}/b-logs/" HTML_DIR = "#{ENV["HOME"]}/public_html/" GEMINI_DIR = "#{ENV["HOME"]}/public_gemini/" dir_structure = {} ####################### # READ RELEVANT FILES # ####################### Dir.children(File.dirname(__FILE__)).each { |child| if child.match(/^b\-log/) # get relevant parts of name file_parts = child.split(".")[1..] # add to dir_structure dir = file_parts[..file_parts.length-2].join "." if dir_structure.keys.include? dir dir_structure[dir].push file_parts.last else dir_structure[dir] = [file_parts.last] end end } ##################################### # REMOVE PREVIOUSLY GENERATED FILES # ##################################### Dir.children(TEMPLATE_DIR).each{ |child| if child.match(/^b-log/) File.delete TEMPLATE_DIR + child end } ################## # GENERATE FILES # ################## dir_structure.keys.each { |key| # get all files in directory files = dir_structure[key].sort for i in 0..files.length-1 do name = key.gsub(".", "/") + "/" + files[i] path = "#{SELF_DIR}b-log.#{key}.#{files[i]}" prev_name = i == 0 ? nil : files[i-1] next_name = i == files.length-1 ? nil : files[i+1] # get file contents for both protocols # html = HTML_DIR + "b-logs/" + name + ".html\n" + \ ";;HTML_HEADER;;#{name.split(":").last};;\n" + \ "||HTML_B-LOG_HEADER||\n" + \ "