]> Sergey Matveev's repositories - sgblog.git/blobdiff - cmd/sgblog/http.go
ISO compatible, Atom-required, dates in comments feed
[sgblog.git] / cmd / sgblog / http.go
index d039ed38ec6b27b2964cc8811ac7904a6fce895f..02237353366459d2fc20550fa27c22721c54814b 100644 (file)
@@ -401,9 +401,9 @@ func serveHTTP() {
                                break
                        }
                        etagHash.Write(commit.Hash[:])
-                       commentsRaw := getNote(commentsTree, commit.Hash)
+                       commentsRaw := sgblog.GetNote(repo, commentsTree, commit.Hash)
                        etagHash.Write(commentsRaw)
-                       topicsRaw := getNote(topicsTree, commit.Hash)
+                       topicsRaw := sgblog.GetNote(repo, topicsTree, commit.Hash)
                        etagHash.Write(topicsRaw)
                        entries = append(entries, TableEntry{
                                Commit:      commit,
@@ -426,8 +426,8 @@ func serveHTTP() {
                                }
                                entry.DomainURLs = append(entry.DomainURLs, makeA(line, u.Host))
                        }
-                       entry.CommentsNum = len(parseComments(entry.CommentsRaw))
-                       entry.Topics = parseTopics(entry.TopicsRaw)
+                       entry.CommentsNum = len(sgblog.ParseComments(entry.CommentsRaw))
+                       entry.Topics = sgblog.ParseTopics(entry.TopicsRaw)
                        entries[i] = entry
                }
                offsetPrev := offset - PageEntries
@@ -533,7 +533,7 @@ func serveHTTP() {
                        }
                        lines := msgSplit(commit.Message)
                        var categories []atom.Category
-                       for _, topic := range parseTopics(getNote(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))
@@ -613,7 +613,7 @@ func serveHTTP() {
                        if err != nil {
                                continue
                        }
-                       comments := parseComments(getNote(t, commentedHash))
+                       comments := sgblog.ParseComments(sgblog.GetNote(repo, t, commentedHash))
                        if len(comments) == 0 {
                                continue
                        }
@@ -645,8 +645,8 @@ func serveHTTP() {
                                                commit.Hash.String(), "#comment", commentN,
                                        }, ""),
                                }},
-                               Published: atom.TimeStr(date),
-                               Updated:   atom.TimeStr(date),
+                               Published: atom.TimeStr(strings.Replace(date, " ", "T", -1)),
+                               Updated:   atom.TimeStr(strings.Replace(date, " ", "T", -1)),
                                Content: &atom.Text{
                                        Type: "html",
                                        Body: strings.Join(htmlized, "\n"),
@@ -673,9 +673,9 @@ func serveHTTP() {
                        cfg.AtomBaseURL, cfg.URLPrefix, "/",
                        commit.Hash.String(), "/", AtomCommentsFeed,
                }, "")
-               commentsRaw := getNote(commentsTree, commit.Hash)
+               commentsRaw := sgblog.GetNote(repo, commentsTree, commit.Hash)
                etagHash.Write(commentsRaw)
-               topicsRaw := getNote(topicsTree, commit.Hash)
+               topicsRaw := sgblog.GetNote(repo, topicsTree, commit.Hash)
                etagHash.Write(topicsRaw)
                if strings.HasSuffix(pathInfo, AtomCommentsFeed) {
                        etagHash.Write([]byte("ATOM COMMENTS"))
@@ -686,7 +686,7 @@ func serveHTTP() {
                                date string
                                body []string
                        }
-                       commentsRaw := parseComments(commentsRaw)
+                       commentsRaw := sgblog.ParseComments(commentsRaw)
                        var toSkip int
                        if len(commentsRaw) > PageEntries {
                                toSkip = len(commentsRaw) - PageEntries
@@ -747,8 +747,12 @@ func serveHTTP() {
                                                        "#comment", comment.n,
                                                }, ""),
                                        }},
-                                       Published: atom.TimeStr(comment.date),
-                                       Updated:   atom.TimeStr(comment.date),
+                                       Published: atom.TimeStr(
+                                               strings.Replace(comment.date, " ", "T", -1),
+                                       ),
+                                       Updated: atom.TimeStr(
+                                               strings.Replace(comment.date, " ", "T", -1),
+                                       ),
                                        Content: &atom.Text{
                                                Type: "html",
                                                Body: strings.Join(htmlized, "\n"),
@@ -762,7 +766,7 @@ func serveHTTP() {
                        out.Write(data)
                        goto AtomFinish
                }
-               notesRaw := getNote(notesTree, commit.Hash)
+               notesRaw := sgblog.GetNote(repo, notesTree, commit.Hash)
                etagHash.Write(notesRaw)
                checkETag(etagHash)
 
@@ -773,7 +777,7 @@ func serveHTTP() {
                if len(commit.ParentHashes) > 0 {
                        parent = commit.ParentHashes[0].String()
                }
-               commentsParsed := parseComments(commentsRaw)
+               commentsParsed := sgblog.ParseComments(commentsRaw)
                comments := make([]CommentEntry, 0, len(commentsParsed))
                for _, comment := range commentsParsed {
                        lines := strings.Split(comment, "\n")
@@ -813,7 +817,7 @@ func serveHTTP() {
                        Lines:           lines[2:],
                        NoteLines:       notesLines,
                        Comments:        comments,
-                       Topics:          parseTopics(topicsRaw),
+                       Topics:          sgblog.ParseTopics(topicsRaw),
                })
                if err != nil {
                        makeErr(err)