]> Sergey Matveev's repositories - sgblog.git/commitdiff
twtxting
authorSergey Matveev <stargrave@stargrave.org>
Sat, 13 Nov 2021 16:39:55 +0000 (19:39 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 13 Nov 2021 16:39:55 +0000 (19:39 +0300)
README.texi
cmd/sgblog/http.go
common.go

index 9409b09a938bbb3096e13d7946b15110a10f4741..54e0461a0c5934c78a6d9e61d6a4c3721d130908 100644 (file)
@@ -11,9 +11,11 @@ Copyright @copyright{} 2020 @email{stargrave@@stargrave.org, Sergey Matveev}
 
 SGBlog is minimalistic and simple Git-backed CGI/UCSPI
 @url{https://en.wikipedia.org/wiki/Blog, blogging} (@code{http://}/@code{https://}),
-@url{https://en.wikipedia.org/wiki/Phlog, phlogging} (@code{gopher://}) and
-gemlogging (@code{gemini://}) engine
-with email-backed comments support, written on @url{https://golang.org/, Go}.
+@url{https://en.wikipedia.org/wiki/Phlog, phlogging} (@code{gopher://}),
+@url{https://twtxt.readthedocs.io/en/latest/index.html, twtxting}, and
+@url{https://en.wikipedia.org/wiki/Gemini_(protocol), gemlogging} (@code{gemini://})
+engine with email-backed comments support,
+written on @url{https://golang.org/, Go}.
 
 Its main competitive features:
 
index 4d1e609fa3d49a5faf5e5b39621bb787a924a963..1bc1824aa9c9fac134d4cd1517b7bea4241223b9 100644 (file)
@@ -36,6 +36,7 @@ import (
        "strconv"
        "strings"
        "text/template"
+       "time"
 
        "github.com/go-git/go-git/v5"
        "github.com/go-git/go-git/v5/plumbing"
@@ -379,6 +380,38 @@ func serveHTTP() {
                if err != nil {
                        makeErr(err, http.StatusInternalServerError)
                }
+       } else if pathInfo == "/twtxt.txt" {
+               commit, err := repo.CommitObject(*headHash)
+               if err != nil {
+                       makeErr(err, http.StatusInternalServerError)
+               }
+               etagHash.Write([]byte("TWTXT POSTS"))
+               etagHash.Write(commit.Hash[:])
+               checkETag(etagHash)
+               repoLog, err := repo.Log(&git.LogOptions{From: *headHash})
+               if err != nil {
+                       makeErr(err, http.StatusInternalServerError)
+               }
+               for i := 0; i < PageEntries; i++ {
+                       commit, err = repoLog.Next()
+                       if err != nil {
+                               break
+                       }
+                       fmt.Fprintf(
+                               out, "%s\t%s\n",
+                               commit.Author.When.Format(time.RFC3339),
+                               msgSplit(commit.Message)[0],
+                       )
+               }
+               os.Stdout.WriteString("Content-Type: text/plain; charset=utf-8\n")
+               os.Stdout.WriteString("ETag: " + etagString(etagHash) + "\n")
+               if gzipWriter != nil {
+                       os.Stdout.WriteString("Content-Encoding: gzip\n")
+                       gzipWriter.Close()
+               }
+               os.Stdout.WriteString("\n")
+               os.Stdout.Write(outBuf.Bytes())
+               return
        } else if pathInfo == "/"+AtomPostsFeed {
                commit, err := repo.CommitObject(*headHash)
                if err != nil {
index 59edef22ef69ee4143409d0de3fa3c5a2f52ec06..988e9abaf56ab65c53a7628a14e83930735c3cf4 100644 (file)
--- a/common.go
+++ b/common.go
@@ -15,7 +15,7 @@ import (
 )
 
 const (
-       Version = "0.24.0"
+       Version = "0.25.0"
        WhenFmt = "2006-01-02 15:04:05Z07:00"
 )