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
|
||||
switch query := r.URL.Query(); query.Get("q") {
|
||||
case "config":
|
||||
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),
|
||||
})
|
||||
}
|
||||
}
|
||||
channels := a.getMicropubChannelsMap()
|
||||
result = map[string]any{
|
||||
"channels": channels,
|
||||
"media-endpoint": a.getFullAddress(micropubPath + micropubMediaSubPath),
|
||||
|
@ -81,6 +69,9 @@ func (a *goBlog) serveMicropubQuery(w http.ResponseWriter, r *http.Request) {
|
|||
allCategories = append(allCategories, values...)
|
||||
}
|
||||
result = map[string]any{"categories": allCategories}
|
||||
case "channel":
|
||||
channels := a.getMicropubChannelsMap()
|
||||
result = map[string]any{"channels": channels}
|
||||
default:
|
||||
a.serve404(w, r)
|
||||
return
|
||||
|
@ -95,6 +86,23 @@ func (a *goBlog) serveMicropubQuery(w http.ResponseWriter, r *http.Request) {
|
|||
_ = 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) {
|
||||
defer r.Body.Close()
|
||||
switch mt, _, _ := mime.ParseMediaType(r.Header.Get(contentType)); mt {
|
||||
|
|
|
@ -57,6 +57,11 @@ func Test_micropubQuery(t *testing.T) {
|
|||
want: "{\"categories\":[\"test\",\"test2\"]}",
|
||||
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",
|
||||
wantStatus: http.StatusNotFound,
|
||||
|
|
Loading…
Reference in New Issue