]> Sergey Matveev's repositories - sgblog.git/commitdiff
URLized comments feed v0.13.0
authorSergey Matveev <stargrave@stargrave.org>
Thu, 3 Dec 2020 09:37:20 +0000 (12:37 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 3 Dec 2020 09:37:36 +0000 (12:37 +0300)
cmd/sgblog/http.go
common.go

index 11dd51566c18b3b81480b8bf8b760ad9e8325d0a..aae2f93ac30196668ef9405df236ac796492cf2d 100644 (file)
@@ -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, "<pre>")
+                       for _, l := range lines[2:] {
+                               htmlized = append(htmlized, lineURLize(cfg.AtomBaseURL+cfg.URLPrefix, l))
+                       }
+                       htmlized = append(htmlized, "</pre>")
                        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, "<pre>")
+                               for _, l := range comment.body {
+                                       htmlized = append(
+                                               htmlized,
+                                               lineURLize(cfg.AtomBaseURL+cfg.URLPrefix, l),
+                                       )
+                               }
+                               htmlized = append(htmlized, "</pre>")
                                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"),
                                        },
                                })
                        }
index 20e6a7bde31a5291a92758e4b1dfcd3afd54d1e5..108bf97585afd3c37132d18d375b25052935c42f 100644 (file)
--- 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"
 )