diff options
Diffstat (limited to 'sunday.rb')
-rwxr-xr-x | sunday.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/sunday.rb b/sunday.rb new file mode 100755 index 0000000..43cf824 --- /dev/null +++ b/sunday.rb @@ -0,0 +1,40 @@ +#!/bin/env ruby + +require "cgi" +require "date" + +THOUGHTS_DIR = "/srv/thoughts" + +heading = <<~END +================================================================================ +Welcome to Martin's Sunday Corner! Here you will find some of my random thoughts + from throughout the past week. Available only on Sundays. + + You can host your own Sunday Corner by copying my code from + >>> git.m-chrzan.xyz/sunday <<< +================================================================================ +END +no_thoughts = <<~END + No thoughts to share this week. Check back next Sunday! +END +not_sunday = <<~END + It's not Sunday today, the corner is closed. Check back on Sunday! +END + +cgi = CGI.new +today = Date::today +thoughts_file = "#{THOUGHTS_DIR}/#{today}" + +if Date::today.sunday? + if File.exist? thoughts_file + contents = File.read thoughts_file + else + contents = no_thoughts + end +else + contents = not_sunday +end + +cgi.out "type" => "text/plain", "charset" => "utf-8" do + heading + "\n" + contents +end |