#!/usr/bin/ruby ############# # VARIABLES # ############# GEMINI_DIR = "/home/de_alchmst/public_gemini/" HTML_DIR = "/home/de_alchmst/public_html/" TO_MANAGE = ["b-logs", "data"] SELF_DIR = File.dirname __FILE__ ######################### # DELETE OLD CROSSROADS # ######################### Dir.children(SELF_DIR).each { |child| if child.match /^crossroad/ File.delete SELF_DIR + "/" + child end } ################ # EXTRACT DATA # ################ def extract(path) outcome = { :all => [], :dirs => [] } # get children and sort dirs Dir.children(path).each { |child_end| if child_end == "index.html" or child_end == "index.gmi" next end child = path + "/" + child_end # don't add links, they are already covered if File.directory?(child) && !File.symlink?(child) outcome[:dirs].push child end outcome[:all].push child } outcome end ################# # CONVERT PATHS # ################# def path_convert(path) path.sub /^\/home\/de_alchmst\/public_.+?\//, "~de_alchmst/" end ################## # GENERATE FILES # ################## def gen(path, format) outcome = "" # get data data = extract(path) # generate contents # if format == :gemtext path_to_show = path.partition("gemini/")[2] outcome = path + "/index.gmi\n" outcome += ";;GEMTEXT_CROSSROAD_HEADER;;#{path_to_show};;\n" data[:all].sort.each { |dat| unless File.symlink? dat outcome += "=> /#{path_convert dat} #{dat.split(/[\/:]/).last}\n" else outcome += "=> /#{path_convert dat} ~> #{dat.split(/[\/:]/).last}\n" end } outcome += "\n||GEMTEXT_CROSSROAD_FOOTER||" else path_to_show = path.partition("html/")[2] outcome = path + "/index.html\n" outcome += ";;HTML_HEADER;;#{path_to_show};;\n" outcome += ";;HTML_CROSSROAD_HEADER;;#{path_to_show};;\n" data[:all].sort.each { |dat| unless File.symlink? dat outcome += "