#! /usr/bin/ruby ################# # LINE STARTS: # h - title # l - link # de - description # dt - date # # SUBSTITIONS: # [HOME] - homepage address # [PROT] - protocol part of URL # [PROT+GMI] - adds 'gemini.' to the gemini path # [EXT] - adds file extension for given protocol # [DOC-NAME] - 'webpage' or 'capsule' # [SELF] - link to the generated file ##################### ############# # VARIABLES # ############# SOURCE = "/home/de_alchmst/rss" WEB_PATH = "/home/de_alchmst/public_html/web-rss.xml" GEMINI_PATH = "/home/de_alchmst/public_html/gemini-rss.xml" TODAY = `date "+%a, %d %b %Y %X %Z"`.strip ########## # HEADER # ########## header = %{ Ðe-Alchmst's [DOC-NAME] [HOME]/ My personal [DOC-NAME], hosted on the ctrl-c.club tilde server. en-us #{TODAY} } footer = %{ } ################## # PARSE THE FILE # ################## File.open(SOURCE) { |file| file.readlines.each { |line| header += "\n " line = line.strip if line.empty? header += "\n " elsif line.start_with? "h " header += " #{line[2..]}" elsif line.start_with? "l " header += " #{line[2..]}\n #{line[2..]}" elsif line.start_with? "de " header += " #{line[3..]}" elsif line.start_with? "dt " header += " #{line[3..]}" else abort "\x1b[31minvalid line: #{line}\x1b[0m" end } } header += footer ###################################### # CONVERT FOR BOTH VERSIONS AND SAVE # ###################################### # web # wb = header.gsub("[HOME]", "https://ctrl-c.club/~de_alchmst") \ .gsub("[PROT]", "https://") \ .gsub("[PROT+GMI]", "https://") \ .gsub("[EXT]", ".html") \ .gsub("[DOC-NAME]", "webpage") \ .gsub("[SELF]", "https://ctrl-c.club/~de_alchmst/web-rss.xml") File.open(WEB_PATH, "w") { |file| file.print wb } # gemini # gm = header.gsub("[HOME]", "gemini://gemini.ctrl-c.club/~de_alchmst") \ .gsub("[PROT]", "gemini://") \ .gsub("[PROT+GMI]", "gemini://gemini.") \ .gsub("[EXT]", ".gmi") \ .gsub("[DOC-NAME]", "capsule") \ .gsub("[SELF]", "https://ctrl-c.club/~de_alchmst/gemini-rss.xml") File.open(GEMINI_PATH, "w") { |file| file.print gm }