]> Sergey Matveev's repositories - sgblog.git/blobdiff - cmd/sgblog/gopher.go
Texinfo website contents
[sgblog.git] / cmd / sgblog / gopher.go
index a4a69fd261105b44f621e9d7384f0f7c61d6dd06..1e3eb72efa432915a7e7c8fc219ed31521513ff6 100644 (file)
@@ -1,5 +1,5 @@
 /*
-SGBlog -- Git-based CGI/inetd blogging/phlogging engine
+SGBlog -- Git-backed CGI/inetd blogging/phlogging engine
 Copyright (C) 2020 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
@@ -41,6 +41,10 @@ const CRLF = "\r\n"
 
 var DashLine = strings.Repeat("-", 72)
 
+func makeI(cfg *Cfg, value string) string {
+       return strings.Join([]string{"i" + value, "err", cfg.GopherDomain, "70", CRLF}, "\t")
+}
+
 func serveGopher() {
        cfgPath := os.Args[2]
        cfgRaw, err := ioutil.ReadFile(cfgPath)
@@ -106,10 +110,9 @@ func serveGopher() {
                        }
                        yearCur, monthCur, dayCur := commit.Author.When.Date()
                        if dayCur != dayPrev || monthCur != monthPrev || yearCur != yearPrev {
-                               menu.WriteString(fmt.Sprintf(
-                                       "i%04d-%02d-%02d\t\tnull.host\t1%s",
-                                       yearCur, monthCur, dayCur, CRLF,
-                               ))
+                               menu.WriteString(makeI(cfg, fmt.Sprintf(
+                                       "%04d-%02d-%02d", yearCur, monthCur, dayCur,
+                               )))
                                yearPrev, monthPrev, dayPrev = yearCur, monthCur, dayCur
                        }
                        commitN++
@@ -130,39 +133,47 @@ func serveGopher() {
                        ))
                }
 
-               var links bytes.Buffer
+               fmt.Print(makeI(cfg, fmt.Sprintf("%s (%d-%d)", cfg.Title, offset, offset+PageEntries)))
+               if cfg.AboutURL != "" {
+                       fmt.Printf(
+                               "hAbout\tURL:%s\t%s\t%d%s",
+                               cfg.AboutURL,
+                               cfg.GopherDomain, 70, CRLF,
+                       )
+               }
                if offset > 0 {
                        offsetPrev := offset - PageEntries
                        if offsetPrev < 0 {
                                offsetPrev = 0
                        }
-                       links.WriteString(fmt.Sprintf(
+                       fmt.Printf(
                                "1Prev\toffset/%d\t%s\t%d%s",
                                offsetPrev,
                                cfg.GopherDomain, 70, CRLF,
-                       ))
+                       )
                }
                if !logEnded {
-                       links.WriteString(fmt.Sprintf(
+                       fmt.Printf(
                                "1Next\toffset/%d\t%s\t%d%s",
                                offset+PageEntries,
                                cfg.GopherDomain, 70, CRLF,
-                       ))
+                       )
                }
-
-               fmt.Printf(
-                       "i%s (%d-%d)\t\tnull.host\t1%s",
-                       cfg.Title,
-                       offset,
-                       offset+PageEntries,
-                       CRLF,
-               )
-               if cfg.AboutURL != "" {
-                       fmt.Printf("iAbout: %s\t\tnull.host\t1%s", cfg.AboutURL, CRLF)
-               }
-               fmt.Print(links.String())
                fmt.Print(menu.String())
+               fmt.Printf(makeI(cfg, "Generated by: SGBlog "+sgblog.Version))
                fmt.Print("." + CRLF)
+       } else if strings.HasPrefix(selector, "URL:") {
+               selector = selector[len("URL:"):]
+               fmt.Printf(`<html>
+<head>
+       <meta http-equiv="Refresh" content="1; url=%s" />
+       <title>Redirect to non-gopher URL</title>
+</head>
+<body>
+Redirecting to <a href="%s">%s</a>...
+</body>
+</html>
+`, selector, selector, selector)
        } else if sha1DigestRe.MatchString(selector) {
                commit, err := repo.CommitObject(plumbing.NewHash(selector[1:]))
                if err != nil {
@@ -179,9 +190,18 @@ func serveGopher() {
                if len(notesRaw) > 0 {
                        fmt.Printf("%s\nNote:\n%s\n", DashLine, string(notesRaw))
                }
+               if cfg.CommentsEmail != "" {
+                       fmt.Printf(
+                               "%s\nleave comment: mailto:%s?subject=%s\n",
+                               DashLine,
+                               cfg.CommentsEmail,
+                               commit.Hash.String(),
+                       )
+               }
                for i, comment := range parseComments(getNote(commentsTree, commit.Hash)) {
                        fmt.Printf("%s\ncomment %d:\n%s\n", DashLine, i, comment)
                }
+               fmt.Printf("%s\nGenerated by: SGBlog %s\n", DashLine, sgblog.Version)
        } else {
                log.Fatalln(errors.New("unknown selector"))
        }