/*
-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 (
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,
+ "i%04d-%02d-%02d\tnil\t%s\t%d%s",
+ yearCur, monthCur, dayCur,
+ cfg.GopherDomain, 70, CRLF,
))
yearPrev, monthPrev, dayPrev = yearCur, monthCur, dayCur
}
))
}
- var links bytes.Buffer
+ fmt.Printf(
+ "i%s (%d-%d)\tnil\t%s\t%d%s",
+ cfg.Title,
+ offset,
+ offset+PageEntries,
+ cfg.GopherDomain, 70, CRLF,
+ )
+ 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.Print(menu.String())
fmt.Printf(
- "i%s (%d-%d)\t\tnull.host\t1%s",
- cfg.Title,
- offset,
- offset+PageEntries,
- CRLF,
+ "iGenerated by: SGBlog %s\terr\t%s\t%d%s",
+ sgblog.Version,
+ cfg.GopherDomain, 70, 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.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 {
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"))
}