mirror of https://github.com/jlelse/GoBlog
Fix post list query
This commit is contained in:
parent
2d940f37a5
commit
1e9f97cb2f
30
micropub.go
30
micropub.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ type micropubConfig struct {
|
||||||
func serveMicropubQuery(w http.ResponseWriter, r *http.Request) {
|
func serveMicropubQuery(w http.ResponseWriter, r *http.Request) {
|
||||||
switch r.URL.Query().Get("q") {
|
switch r.URL.Query().Get("q") {
|
||||||
case "config":
|
case "config":
|
||||||
w.Header().Add(contentType, contentTypeJSON)
|
w.Header().Add(contentType, contentTypeJSONUTF8)
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
mc := µpubConfig{}
|
mc := µpubConfig{}
|
||||||
if appConfig.Micropub.MediaStorage != nil {
|
if appConfig.Micropub.MediaStorage != nil {
|
||||||
|
@ -45,7 +46,12 @@ func serveMicropubQuery(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
mf = p.toMfItem()
|
mf = p.toMfItem()
|
||||||
} else {
|
} else {
|
||||||
posts, err := getPosts(&postsRequestConfig{})
|
limit, _ := strconv.Atoi(r.URL.Query().Get("limit"))
|
||||||
|
offset, _ := strconv.Atoi(r.URL.Query().Get("offset"))
|
||||||
|
posts, err := getPosts(&postsRequestConfig{
|
||||||
|
limit: limit,
|
||||||
|
offset: offset,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
@ -56,7 +62,7 @@ func serveMicropubQuery(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
mf = list
|
mf = list
|
||||||
}
|
}
|
||||||
w.Header().Add(contentType, contentTypeJSON)
|
w.Header().Add(contentType, contentTypeJSONUTF8)
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_ = json.NewEncoder(w).Encode(mf)
|
_ = json.NewEncoder(w).Encode(mf)
|
||||||
default:
|
default:
|
||||||
|
@ -74,12 +80,18 @@ func (p *post) toMfItem() *microformatItem {
|
||||||
return µformatItem{
|
return µformatItem{
|
||||||
Type: []string{"h-entry"},
|
Type: []string{"h-entry"},
|
||||||
Properties: µformatProperties{
|
Properties: µformatProperties{
|
||||||
Name: p.Parameters["title"],
|
Name: p.Parameters["title"],
|
||||||
Published: []string{p.Published},
|
Published: []string{p.Published},
|
||||||
Updated: []string{p.Updated},
|
Updated: []string{p.Updated},
|
||||||
Content: []string{content},
|
Category: p.Parameters[appConfig.Micropub.CategoryParam],
|
||||||
MpSlug: []string{p.Slug},
|
Content: []string{content},
|
||||||
Category: p.Parameters[appConfig.Micropub.CategoryParam],
|
URL: []string{appConfig.Server.PublicAddress + p.Path},
|
||||||
|
InReplyTo: p.Parameters[appConfig.Micropub.ReplyParam],
|
||||||
|
LikeOf: p.Parameters[appConfig.Micropub.LikeParam],
|
||||||
|
BookmarkOf: p.Parameters[appConfig.Micropub.BookmarkParam],
|
||||||
|
MpSlug: []string{p.Slug},
|
||||||
|
Audio: p.Parameters[appConfig.Micropub.AudioParam],
|
||||||
|
// TODO: Photos
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue