From 75ca2df5b6ac87634753dd3038591adbe8dfed96 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Thu, 3 Dec 2020 12:37:20 +0300 Subject: [PATCH] URLized comments feed --- cmd/sgblog/http.go | 23 +++++++++++++++++++---- common.go | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/cmd/sgblog/http.go b/cmd/sgblog/http.go index 11dd515..aae2f93 100644 --- a/cmd/sgblog/http.go +++ b/cmd/sgblog/http.go @@ -635,6 +635,12 @@ func serveHTTP() { lines := strings.Split(comments[len(comments)-1], "\n") from := strings.TrimPrefix(lines[0], "From: ") date := strings.TrimPrefix(lines[1], "Date: ") + htmlized := make([]string, 0, len(lines)) + htmlized = append(htmlized, "
")
+			for _, l := range lines[2:] {
+				htmlized = append(htmlized, lineURLize(cfg.AtomBaseURL+cfg.URLPrefix, l))
+			}
+			htmlized = append(htmlized, "
") idHasher.Reset() idHasher.Write([]byte("COMMENT")) idHasher.Write(commit.Hash[:]) @@ -656,8 +662,8 @@ func serveHTTP() { Published: atom.TimeStr(date), Updated: atom.TimeStr(date), Content: &atom.Text{ - Type: "text", - Body: strings.Join(lines[2:], "\n"), + Type: "html", + Body: strings.Join(htmlized, "\n"), }, }) } @@ -733,6 +739,15 @@ func serveHTTP() { idHasher.Write([]byte("COMMENT")) idHasher.Write(commit.Hash[:]) idHasher.Write([]byte(comment.n)) + htmlized := make([]string, 0, len(comment.body)) + htmlized = append(htmlized, "
")
+				for _, l := range comment.body {
+					htmlized = append(
+						htmlized,
+						lineURLize(cfg.AtomBaseURL+cfg.URLPrefix, l),
+					)
+				}
+				htmlized = append(htmlized, "
") feed.Entry = append(feed.Entry, &atom.Entry{ Title: fmt.Sprintf("Comment %s by %s", comment.n, comment.from), Author: &atom.Person{Name: comment.from}, @@ -749,8 +764,8 @@ func serveHTTP() { Published: atom.TimeStr(comment.date), Updated: atom.TimeStr(comment.date), Content: &atom.Text{ - Type: "text", - Body: strings.Join(comment.body, "\n"), + Type: "html", + Body: strings.Join(htmlized, "\n"), }, }) } diff --git a/common.go b/common.go index 20e6a7b..108bf97 100644 --- a/common.go +++ b/common.go @@ -2,6 +2,6 @@ package sgblog const ( - Version = "0.12.0" + Version = "0.13.0" WhenFmt = "2006-01-02 15:04:05Z07:00" ) -- 2.44.0