aboutsummaryrefslogtreecommitdiff
path: root/cmd/server/handlers.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/server/handlers.go')
-rw-r--r--cmd/server/handlers.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/cmd/server/handlers.go b/cmd/server/handlers.go
index c44c19c..d4b7140 100644
--- a/cmd/server/handlers.go
+++ b/cmd/server/handlers.go
@@ -28,9 +28,23 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
rediscache.HandleWithParams(a.redisPool, a.RedisKey,
http.HandlerFunc(a.FeedHandler)))
+ rtr.PathPrefix("/_json/").Handler(
+ rediscache.HandleWithParams(a.redisPool, a.RedisKey,
+ http.StripPrefix("/_json", http.HandlerFunc(a.PageJsonHandler))))
+
+ rtr.PathPrefix("/_md/").Handler(
+ rediscache.HandleWithParams(a.redisPool, a.RedisKey,
+ http.StripPrefix("/_md", http.HandlerFunc(a.PageMarkdownHandler))))
+
rtr.PathPrefix("/").Handler(rediscache.Handle(
a.redisPool, a.RedisKey, http.HandlerFunc(a.PageHandler)))
} else {
+ rtr.PathPrefix("/_md/").Handler(http.StripPrefix("/_md",
+ http.HandlerFunc(a.PageMarkdownHandler)))
+
+ rtr.PathPrefix("/_json/").Handler(http.StripPrefix("/_json",
+ http.HandlerFunc(a.PageJsonHandler)))
+
rtr.PathPrefix(fmt.Sprintf("/%s/{tag}", a.FeedPrefix)).HandlerFunc(
a.FeedHandler)
@@ -68,6 +82,39 @@ func (a *App) PageHandler(w http.ResponseWriter, r *http.Request) {
"LoggedIn": loggedIn,
})
}
+func (a *App) PageJsonHandler(w http.ResponseWriter, r *http.Request) {
+ u := r.URL.Path
+ if u == "/" {
+ u = "/index"
+ }
+
+ // Skip template directory
+ if strings.HasPrefix(u[1:], filepath.Clean(page.TemplateDirectory)) {
+ page.Render4xx(w, r, map[string]interface{}{}, 404)
+ return
+ }
+
+ u = filepath.Join(".", u)
+
+ page.RenderJson(w, r, u, map[string]interface{}{}, 200)
+}
+
+func (a *App) PageMarkdownHandler(w http.ResponseWriter, r *http.Request) {
+ u := r.URL.Path
+ if u == "/" {
+ u = "/index"
+ }
+
+ // Skip template directory
+ if strings.HasPrefix(u[1:], filepath.Clean(page.TemplateDirectory)) {
+ page.Render4xx(w, r, map[string]interface{}{}, 404)
+ return
+ }
+
+ u = filepath.Join(".", u)
+
+ page.RenderMarkdown(w, r, u, map[string]interface{}{}, 200)
+}
func (a *App) RebuildIndexHandler(w http.ResponseWriter, r *http.Request) {
u := r.URL.Path