/*
SGBlog -- Git-backed CGI/UCSPI blogging/phlogging/gemlogging engine
-Copyright (C) 2020-2021 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2020-2022 Sergey Matveev <stargrave@stargrave.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
"strconv"
"strings"
"text/template"
+ "time"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"gopher": {},
"http": {},
"https": {},
+ "irc": {},
+ "ircs": {},
+ "news": {},
"telnet": {},
}
func startHeader(etag hash.Hash, gziped bool) string {
lines := []string{
- "Content-Type: text/html; charset=UTF-8",
+ "Content-Type: text/html; charset=utf-8",
"ETag: " + etagString(etag),
}
if gziped {
func makeErr(err error, status int) {
fmt.Println("Status:", status)
- fmt.Print("Content-Type: text/plain; charset=UTF-8\n\n")
+ fmt.Print("Content-Type: text/plain; charset=utf-8\n\n")
fmt.Println(err)
log.Fatalln(err)
}
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 {
}
lines := msgSplit(commit.Message)
var categories []atom.Category
- for _, topic := range sgblog.ParseTopics(sgblog.GetNote(repo, topicsTree, commit.Hash)) {
+ for _, topic := range sgblog.ParseTopics(sgblog.GetNote(
+ repo, topicsTree, commit.Hash,
+ )) {
categories = append(categories, atom.Category{Term: topic})
}
htmlized := make([]string, 0, len(lines))
return
AtomFinish:
- os.Stdout.WriteString("Content-Type: application/atom+xml; charset=UTF-8\n")
+ os.Stdout.WriteString("Content-Type: application/atom+xml; charset=utf-8\n")
os.Stdout.WriteString("ETag: " + etagString(etagHash) + "\n")
if gzipWriter != nil {
os.Stdout.WriteString("Content-Encoding: gzip\n")