Files
sm-journal-plugin/routes.go
Jakub Zych 5210b64e0f feat: journal:fix-headings and the settings API
- classes.FixStoredHeadings converts stored H1 in post content (every
  locale) and category pillar text, in one transaction with a RecordSaved
  and a site cache purge per changed record
- journal:fix-headings, a dry run unless --apply, refuses with exit code 1
  while the H1 setting is off
- GET/PUT /_journal/api/v1/settings and POST /fix-headings {dry_run} for
  golem15.journal.manage_settings; 409 with the refusal while the setting
  is off
2026-11-04 10:04:27 +01:00

40 lines
1.8 KiB
Go

package journal
import (
apicontrollers "git.golem15.com/golem15/sm-journal-plugin/controllers/api"
"git.golem15.com/golem15/summercms/modules/pact"
"git.golem15.com/golem15/summercms/modules/surf"
)
// Routes mounts public GETs and backend-Bearer writes under /_journal/api/v1
// (D-14). The public group must not attach cabana middleware name "backend"
// (anonymous callers would 401 — pitfall 4). The public author routes resolve
// {author} in the handler rather than with Where, so every miss is the JSON
// 404 {"error":"Author not found"}.
func (p *Plugin) Routes(r pact.Router) error {
r.Group("/_journal/api/v1", surf.Use("throttle:journal-public-api"), func(g pact.Router) {
g.Get("/posts", apicontrollers.Index(p.app))
g.Get("/posts/{slug}", apicontrollers.Show(p.app))
g.Where("slug", `[a-z0-9][a-z0-9\-/]*`)
g.Get("/categories", apicontrollers.Categories(p.app))
g.Get("/tags", apicontrollers.Tags(p.app))
g.Get("/rss", apicontrollers.RSS(p.app))
g.Get("/authors/{author}", apicontrollers.AuthorShow(p.app))
g.Get("/authors/{author}/posts", apicontrollers.AuthorPosts(p.app))
})
r.Group("/_journal/api/v1", surf.Use("throttle:journal-api"), func(g pact.Router) {
g.Post("/media/upload", apicontrollers.UploadMedia(p.app))
g.Post("/posts", apicontrollers.Store(p.app))
g.Put("/posts/{id}", apicontrollers.Update(p.app))
g.Delete("/posts/{id}", apicontrollers.Destroy(p.app))
g.Post("/posts/{id}/featured-images", apicontrollers.UploadFeaturedImage(p.app))
g.Delete("/posts/{id}/featured-images/{fileId}", apicontrollers.DeleteFeaturedImage(p.app))
g.Where("id", `[0-9]+`)
g.Where("fileId", `[0-9]+`)
g.Get("/settings", apicontrollers.ShowSettings(p.app))
g.Put("/settings", apicontrollers.UpdateSettings(p.app))
g.Post("/fix-headings", apicontrollers.FixHeadings(p.app))
})
return nil
}