💾 Archived View for flume.space › genfeed.rb captured on 2021-12-04 at 18:04:22.

View Raw

More Information

⬅️ Previous capture (2021-11-30)

➡️ Next capture (2022-04-28)

-=-=-=-=-=-=-

require 'date'

def entry(line)
  valid = (/=>.* (?<date>\d\d\d\d-\d\d-\d\d) (?<title>.*)/ =~ line)
  return date, title if valid
end

def genAtomEntry(line)
  (date, title) = entry line
  unless date.nil? or title.nil?
    '<entry>'\
      '<updated>' + date + 'T12:00:00Z</updated>'\
      '<title>' + title + '</title>'\
      '<id>gemini://flume.space/gemlog/' + date + '.gmi</id>'\
      '<link href="gemini://flume.space/gemlog/' + date + '.gmi" rel="alternate" />'\
    '</entry>'
  end
end

def genAtomFeed(lines)
  '<?xml version="1.0" encoding="utf-8"?>'\
  '<feed xmlns="http://www.w3.org/2005/Atom">'\
    '<title>mpm\'s gemlog</title>'\
    '<link rel="alternate" type="text/gemini" href="gemini://flume.space/" />'\
    '<link rel="self" type="application/atom+xml" href="gemini://flume.space/atom.xml" />'\
    '<generator uri="gemini://flume.space/genfeed.rb" version="1.0.0">genfeed.rb</generator>'\
    '<id>gemini://flume.space/</id>'\
    '<author><name>mpm</name></author>'\
    '<updated>' + DateTime.now.to_s + '</updated>'\
    + lines.map {|x| genAtomEntry x}.join("") +
  '</feed>'
end

File.open('atom.xml', 'w') do |f|
  f.write genAtomFeed(File.open('index.gmi', 'r').readlines)
end