aboutsummaryrefslogtreecommitdiff
path: root/cgi/user.cgi
blob: b95034e070121ff9ff5032f542214d4e487f36ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby

require 'cgi'

def link(href, text, remote = false)
  if remote
    $cgi.a(href: href, target: "_blank") { "[ #{text} ⇗ ] " }
  else
    $cgi.a(href: href) { "[ #{text} ] " }
  end
end

def toplinks
  $cgi.ul(class: "toplinks") {
    $cgi.li { link("/"                      , "Home"              ) } +
    $cgi.li { link("/bins"                  , "Bins"              ) } +
    $cgi.li { link("/shelf"                 , "Shelf"             ) } +
    $cgi.li { link("/eamit.html"            , "eamit"       , true) } +
    $cgi.li { link("https://git.4574.co.uk/", "Git"         , true) } +
    $cgi.li { link("/stuff-i-want"          , "Stuff I Want"      ) }
  }
end

def rquote
  File.readlines("../inc/quotes.txt").sample.strip
end

def page(title, jumbotitle = title)
  load "#{title.downcase.gsub(?\s, ?-)}.cgi"

  $cgi.out {
    $cgi.html(lang: "en") {
      $cgi.head {
        $cgi.title { "User_4574's Lair / #{title}" } +
        $cgi.link(rel: "stylesheet", href: "styles.css")
      } +
      $cgi.body {
        $cgi.div(class: "pagetop") {
          $cgi.h1(class: "jumbo") { jumbotitle } +
          toplinks
        } +
        $cgi.div { $page } +
        $cgi.div(id: "quote") { rquote }
      }
    }
  }
end

$cgi = CGI.new("html5")

case $cgi.path_info
when "/"
  page("Home", "User_4574's Lair")
when "/bins"
  page("Bins")
when "/shelf"
  page("Whisky Shelf")
when /^\/stuff-i-want/
  page("Stuff I Want")
when /^\/bv/
  $cgi.out("status" => "MOVED", "Location" => "https://bv.miller.cm/") {""}
end