]> Sergey Matveev's repositories - sgblog.git/blobdiff - cmd/sgblog/http.go
Images support
[sgblog.git] / cmd / sgblog / http.go
index fd5f7b448ec88bcdb7dc8a15d5b51e01a5575b5a..50bb1a882f841715f2d0dee1be079243ef67e858 100644 (file)
@@ -484,13 +484,22 @@ func serveHTTP() {
                                htmlized = append(htmlized, lineURLize(cfg.AtomBaseURL+cfg.URLPrefix, l))
                        }
                        htmlized = append(htmlized, "</pre>")
+                       links := []atom.Link{{
+                               Rel:  "alternate",
+                               Href: cfg.AtomBaseURL + cfg.URLPrefix + "/" + commit.Hash.String(),
+                       }}
+                       for _, img := range listImgs(cfg, commit.Hash) {
+                               links = append(links, atom.Link{
+                                       Rel:    "enclosure",
+                                       Href:   "http://" + cfg.ImgDomain + "/" + img.Path,
+                                       Type:   img.Typ,
+                                       Length: uint(img.Size),
+                               })
+                       }
                        feed.Entry = append(feed.Entry, &atom.Entry{
-                               Title: lines[0],
-                               ID:    "urn:uuid:" + bytes2uuid(commit.Hash[:]),
-                               Link: []atom.Link{{
-                                       Rel:  "alternate",
-                                       Href: cfg.AtomBaseURL + cfg.URLPrefix + "/" + commit.Hash.String(),
-                               }},
+                               Title:     lines[0],
+                               ID:        "urn:uuid:" + bytes2uuid(commit.Hash[:]),
+                               Link:      links,
                                Published: atom.Time(commit.Author.When),
                                Updated:   atom.Time(commit.Author.When),
                                Summary:   &atom.Text{Type: "text", Body: lines[0]},
@@ -742,6 +751,7 @@ func serveHTTP() {
                        NoteLines       []string
                        Comments        []CommentEntry
                        Topics          []string
+                       Imgs            []Img
                }{
                        T:               localizer,
                        Version:         sgblog.Version,
@@ -756,6 +766,7 @@ func serveHTTP() {
                        NoteLines:       notesLines,
                        Comments:        comments,
                        Topics:          sgblog.ParseTopics(topicsRaw),
+                       Imgs:            listImgs(cfg, commit.Hash),
                })
                if err != nil {
                        makeErr(err, http.StatusInternalServerError)