diff --git a/src/controllers/posts/feeds.go b/src/controllers/posts/feeds.go index 0a077b6..cef0444 100644 --- a/src/controllers/posts/feeds.go +++ b/src/controllers/posts/feeds.go @@ -70,6 +70,7 @@ func feedHandler(w http.ResponseWriter, r *http.Request) { } feed.Items = append(feed.Items, &feeds.Item{ + Id: fmt.Sprintf("%d", p.ID), Title: p.Title, Link: &feeds.Link{Href: config.Site.URL + "/" + p.Fragment}, Description: rendered, @@ -83,8 +84,12 @@ func feedHandler(w http.ResponseWriter, r *http.Request) { // What format to encode it in? if strings.Contains(r.URL.Path, ".atom") { atom, _ := feed.ToAtom() - w.Header().Set("Content-Type", "application/atom+xml") + w.Header().Set("Content-Type", "application/atom+xml; encoding=utf-8") w.Write([]byte(atom)) + } else if strings.Contains(r.URL.Path, ".json") { + jsonData, _ := feed.ToJSON() + w.Header().Set("Content-Type", "application/json; encoding=utf-8") + w.Write([]byte(jsonData)) } else { rss, _ := feed.ToRss() w.Header().Set("Content-Type", "application/rss+xml; encoding=utf-8") diff --git a/src/controllers/posts/posts.go b/src/controllers/posts/posts.go index 2d18dd8..6d8b960 100644 --- a/src/controllers/posts/posts.go +++ b/src/controllers/posts/posts.go @@ -48,6 +48,7 @@ func Register(r *mux.Router, loginError http.HandlerFunc) { r.HandleFunc("/blog", indexHandler) r.HandleFunc("/blog.rss", feedHandler) r.HandleFunc("/blog.atom", feedHandler) + r.HandleFunc("/blog.json", feedHandler) r.HandleFunc("/archive", archiveHandler) r.HandleFunc("/tagged", taggedHandler) r.HandleFunc("/tagged/{tag}", taggedHandler) diff --git a/src/middleware/age-gate.go b/src/middleware/age-gate.go index 4806e24..2e6f71a 100644 --- a/src/middleware/age-gate.go +++ b/src/middleware/age-gate.go @@ -13,6 +13,7 @@ import ( var ageGateSuffixes = []string{ "/blog.rss", // Allow public access to RSS and Atom feeds. "/blog.atom", + "/blog.json", ".js", ".css", ".txt",