mirror of https://github.com/jlelse/GoBlog
Add support for seperate micropub channel request
This commit is contained in:
parent
7dbaf9fadb
commit
bb8bcdb6e2
34
micropub.go
34
micropub.go
|
@ -24,19 +24,7 @@ func (a *goBlog) serveMicropubQuery(w http.ResponseWriter, r *http.Request) {
|
||||||
var result any
|
var result any
|
||||||
switch query := r.URL.Query(); query.Get("q") {
|
switch query := r.URL.Query(); query.Get("q") {
|
||||||
case "config":
|
case "config":
|
||||||
channels := []map[string]any{}
|
channels := a.getMicropubChannelsMap()
|
||||||
for b, bc := range a.cfg.Blogs {
|
|
||||||
channels = append(channels, map[string]any{
|
|
||||||
"name": fmt.Sprintf("%s: %s", b, bc.Title),
|
|
||||||
"uid": b,
|
|
||||||
})
|
|
||||||
for s, sc := range bc.Sections {
|
|
||||||
channels = append(channels, map[string]any{
|
|
||||||
"name": fmt.Sprintf("%s/%s: %s", b, s, sc.Name),
|
|
||||||
"uid": fmt.Sprintf("%s/%s", b, s),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result = map[string]any{
|
result = map[string]any{
|
||||||
"channels": channels,
|
"channels": channels,
|
||||||
"media-endpoint": a.getFullAddress(micropubPath + micropubMediaSubPath),
|
"media-endpoint": a.getFullAddress(micropubPath + micropubMediaSubPath),
|
||||||
|
@ -81,6 +69,9 @@ func (a *goBlog) serveMicropubQuery(w http.ResponseWriter, r *http.Request) {
|
||||||
allCategories = append(allCategories, values...)
|
allCategories = append(allCategories, values...)
|
||||||
}
|
}
|
||||||
result = map[string]any{"categories": allCategories}
|
result = map[string]any{"categories": allCategories}
|
||||||
|
case "channel":
|
||||||
|
channels := a.getMicropubChannelsMap()
|
||||||
|
result = map[string]any{"channels": channels}
|
||||||
default:
|
default:
|
||||||
a.serve404(w, r)
|
a.serve404(w, r)
|
||||||
return
|
return
|
||||||
|
@ -95,6 +86,23 @@ func (a *goBlog) serveMicropubQuery(w http.ResponseWriter, r *http.Request) {
|
||||||
_ = a.min.Get().Minify(contenttype.JSON, w, buf)
|
_ = a.min.Get().Minify(contenttype.JSON, w, buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *goBlog) getMicropubChannelsMap() []map[string]any {
|
||||||
|
channels := []map[string]any{}
|
||||||
|
for b, bc := range a.cfg.Blogs {
|
||||||
|
channels = append(channels, map[string]any{
|
||||||
|
"name": fmt.Sprintf("%s: %s", b, bc.Title),
|
||||||
|
"uid": b,
|
||||||
|
})
|
||||||
|
for s, sc := range bc.Sections {
|
||||||
|
channels = append(channels, map[string]any{
|
||||||
|
"name": fmt.Sprintf("%s/%s: %s", b, s, sc.Name),
|
||||||
|
"uid": fmt.Sprintf("%s/%s", b, s),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return channels
|
||||||
|
}
|
||||||
|
|
||||||
func (a *goBlog) serveMicropubPost(w http.ResponseWriter, r *http.Request) {
|
func (a *goBlog) serveMicropubPost(w http.ResponseWriter, r *http.Request) {
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
switch mt, _, _ := mime.ParseMediaType(r.Header.Get(contentType)); mt {
|
switch mt, _, _ := mime.ParseMediaType(r.Header.Get(contentType)); mt {
|
||||||
|
|
|
@ -57,6 +57,11 @@ func Test_micropubQuery(t *testing.T) {
|
||||||
want: "{\"categories\":[\"test\",\"test2\"]}",
|
want: "{\"categories\":[\"test\",\"test2\"]}",
|
||||||
wantStatus: http.StatusOK,
|
wantStatus: http.StatusOK,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
query: "channel",
|
||||||
|
want: "{\"channels\":[{\"name\":\"default: My Blog\",\"uid\":\"default\"},{\"name\":\"default/posts: posts\",\"uid\":\"default/posts\"}]}",
|
||||||
|
wantStatus: http.StatusOK,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
query: "somethingelse",
|
query: "somethingelse",
|
||||||
wantStatus: http.StatusNotFound,
|
wantStatus: http.StatusNotFound,
|
||||||
|
|
Loading…
Reference in New Issue