]> Sergey Matveev's repositories - sgblog.git/commitdiff
URL support in Gopher
authorSergey Matveev <stargrave@stargrave.org>
Sun, 15 Mar 2020 11:32:48 +0000 (14:32 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 15 Mar 2020 11:32:48 +0000 (14:32 +0300)
cmd/sgblog/gopher.go
common.go

index 41dc9d16089c15737d8f18bc76d4ce81271d8c6b..2fbbeda1479b110463b9cdac4d4b954eb95ccc85 100644 (file)
@@ -107,8 +107,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,
+                                       "i%04d-%02d-%02d\tnil\t%s\t%d%s",
+                                       yearCur, monthCur, dayCur,
+                                       cfg.GopherDomain, 70, CRLF,
                                ))
                                yearPrev, monthPrev, dayPrev = yearCur, monthCur, dayCur
                        }
@@ -131,14 +132,18 @@ func serveGopher() {
                }
 
                fmt.Printf(
-                       "i%s (%d-%d)\t\tnull.host\t1%s",
+                       "i%s (%d-%d)\tnil\t%s\t%d%s",
                        cfg.Title,
                        offset,
                        offset+PageEntries,
-                       CRLF,
+                       cfg.GopherDomain, 70, CRLF,
                )
                if cfg.AboutURL != "" {
-                       fmt.Printf("iAbout: %s\t\tnull.host\t1%s", cfg.AboutURL, CRLF)
+                       fmt.Printf(
+                               "hAbout\tURL:%s\t%s\t%d%s",
+                               cfg.AboutURL,
+                               cfg.GopherDomain, 70, CRLF,
+                       )
                }
                if offset > 0 {
                        offsetPrev := offset - PageEntries
@@ -159,8 +164,24 @@ func serveGopher() {
                        )
                }
                fmt.Print(menu.String())
-               fmt.Printf("iGenerated by: SGBlog %s\t\tnull.host\t1%s", sgblog.Version, CRLF)
+               fmt.Printf(
+                       "iGenerated by: SGBlog %s\terr\t%s\t%d%s",
+                       sgblog.Version,
+                       cfg.GopherDomain, 70, CRLF,
+               )
                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 {
index 86d1e8317876bf0524b1c14d8807c09615537de4..bcc0d9c511dc96b5a8fd7abdb0b497a56c678be5 100644 (file)
--- a/common.go
+++ b/common.go
@@ -2,6 +2,6 @@
 package sgblog
 
 const (
-       Version = "0.4.0"
+       Version = "0.5.0"
        WhenFmt = "2006-01-02 15:04:05Z07:00"
 )