From: Sergey Matveev <stargrave@stargrave.org>
Date: Sat, 13 Nov 2021 16:39:55 +0000 (+0300)
Subject: twtxting
X-Git-Tag: v0.25.0~1
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=f77cb43f19cc2e50548d8fd2ac1bba91dfef3161;p=sgblog.git

twtxting
---

diff --git a/README.texi b/README.texi
index 9409b09..54e0461 100644
--- a/README.texi
+++ b/README.texi
@@ -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:
 
diff --git a/cmd/sgblog/http.go b/cmd/sgblog/http.go
index 4d1e609..1bc1824 100644
--- a/cmd/sgblog/http.go
+++ b/cmd/sgblog/http.go
@@ -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 {
diff --git a/common.go b/common.go
index 59edef2..988e9ab 100644
--- 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"
 )