/*
-SGBlog -- Git-based CGI blogging engine
+SGBlog -- Git-based 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
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-// Git-based CGI blogging engine
package main
import (
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)
}
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++
))
}
- 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 {
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"))
}