diff options
Diffstat (limited to 'system/api/handlers.go')
-rw-r--r-- | system/api/handlers.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/system/api/handlers.go b/system/api/handlers.go index c238ca9..7a2073d 100644 --- a/system/api/handlers.go +++ b/system/api/handlers.go @@ -91,6 +91,12 @@ func contentHandler(res http.ResponseWriter, req *http.Request) { q := req.URL.Query() id := q.Get("id") t := q.Get("type") + slug := q.Get("slug") + + if slug != "" { + contentHandlerBySlug(res, req) + return + } if _, ok := content.Types[t]; !ok { res.WriteHeader(http.StatusNotFound) @@ -117,6 +123,26 @@ func contentHandler(res http.ResponseWriter, req *http.Request) { sendData(res, j, http.StatusOK) } +func contentHandlerBySlug(res http.ResponseWriter, req *http.Request) { + slug := req.URL.Query().Get("slug") + + // lookup type:id by slug key in __contentIndex + post, err := db.ContentBySlug(slug) + if err != nil { + log.Println("Error finding content by slug:", slug, err) + res.WriteHeader(http.StatusInternalServerError) + return + } + + j, err := fmtJSON(json.RawMessage(post)) + if err != nil { + res.WriteHeader(http.StatusInternalServerError) + return + } + + sendData(res, j, http.StatusOK) +} + func fmtJSON(data ...json.RawMessage) ([]byte, error) { var msg = []json.RawMessage{} for _, d := range data { |