]> Sergey Matveev's repositories - sgblog.git/blobdiff - cmd/sgblog/http.go
URLized comments feed
[sgblog.git] / cmd / sgblog / http.go
index 808c3d99fd687b8c025114ea6ecb80c030bd2fc4..aae2f93ac30196668ef9405df236ac796492cf2d 100644 (file)
@@ -550,6 +550,12 @@ func serveHTTP() {
                        for _, topic := range parseTopics(getNote(topicsTree, commit.Hash)) {
                                categories = append(categories, atom.Category{Term: topic})
                        }
+                       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>")
                        feed.Entry = append(feed.Entry, &atom.Entry{
                                Title: lines[0],
                                ID:    "urn:uuid:" + bytes2uuid(commit.Hash[:]),
@@ -561,8 +567,8 @@ func serveHTTP() {
                                Updated:   atom.Time(commit.Author.When),
                                Summary:   &atom.Text{Type: "text", Body: lines[0]},
                                Content: &atom.Text{
-                                       Type: "text",
-                                       Body: strings.Join(lines[2:], "\n"),
+                                       Type: "html",
+                                       Body: strings.Join(htmlized, "\n"),
                                },
                                Category: categories,
                        })
@@ -629,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[:])
@@ -650,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"),
                                },
                        })
                }
@@ -727,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},
@@ -743,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"),
                                        },
                                })
                        }