feat: HTML sitemap groups API
- GET /_sitemap/api/v1/html?locale= answers the overview: the listed
addresses of the XML sitemaps by group, in the order pages, offers,
services, categories (as a tree), posts (newest first), tags, authors,
other content types, each with its title in the locale, total, the
first html_page_size links and more
- GET /_sitemap/api/v1/html/{group}?locale=&page= answers one page of a
group; past the last page, an unknown group or the HTML sitemap off
answer 404; every answer is noindex; per-IP bucket sitemap-html
- the HTML sitemap tab: html_enabled, the address per locale (html_paths)
and html_page_size 50 to 500, with errors.html_path and errors.page_size
- contract.Listing.Settings answers HTMLEnabled, HTMLPaths, HTMLPageSize
and KeyFile
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"git.golem15.com/golem15/sm-sitemap-plugin/contract"
|
||||
"git.golem15.com/golem15/sm-sitemap-plugin/models"
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/signpost"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -40,9 +39,10 @@ func (l Listing) db(ctx context.Context) (*gorm.DB, error) {
|
||||
}
|
||||
|
||||
// Settings answers the site address, the index address, the default
|
||||
// locale and the groups with listed addresses (by key), with their titles:
|
||||
// a content type's saved HTML sitemap headings, else the titles of the
|
||||
// published Filter's group of that key.
|
||||
// locale and the groups with listed addresses (by key), with their titles
|
||||
// (a content type's saved HTML sitemap headings, else the titles of the
|
||||
// published Filter's group of that key), the HTML sitemap settings and the
|
||||
// IndexNow key file name (while IndexNow is on with a key).
|
||||
func (l Listing) Settings(ctx context.Context) (contract.ListingSettings, error) {
|
||||
var out contract.ListingSettings
|
||||
db, err := l.db(ctx)
|
||||
@@ -65,34 +65,18 @@ func (l Listing) Settings(ctx context.Context) (contract.ListingSettings, error)
|
||||
if err := db.Raw(`SELECT grp, COUNT(*) AS n FROM golem15_sitemap_urls WHERE excluded_reason = '' GROUP BY grp ORDER BY grp`).Scan(&counts).Error; err != nil {
|
||||
return out, err
|
||||
}
|
||||
titles := map[string]map[string]string{}
|
||||
if filter, ok := l.App.Lookup[contract.Filter](); ok && filter != nil {
|
||||
groups, err := filter.Groups(ctx)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
for _, g := range groups {
|
||||
if len(g.Titles) > 0 {
|
||||
titles[g.Key] = g.Titles
|
||||
}
|
||||
}
|
||||
}
|
||||
if reg, ok := l.App.Lookup[*signpost.Registry](); ok && reg != nil {
|
||||
rows, err := LoadTypeSettings(db)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
for _, typ := range reg.ContentTypes() {
|
||||
cfg := EffectiveType(typ, rows)
|
||||
if len(cfg.Titles) > 0 {
|
||||
titles[cfg.Slug] = cfg.Titles
|
||||
}
|
||||
}
|
||||
titles, _, _, err := groupTitles(ctx, l.App, db)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
out.Groups = make([]contract.GroupInfo, 0, len(counts))
|
||||
for _, c := range counts {
|
||||
out.Groups = append(out.Groups, contract.GroupInfo{Key: c.Grp, Slug: c.Grp, Titles: titles[c.Grp], Count: c.N})
|
||||
}
|
||||
out.HTMLEnabled = settings.HTMLEnabled
|
||||
out.HTMLPaths = settings.EffectiveHTMLPaths()
|
||||
out.HTMLPageSize = settings.EffectiveHTMLPageSize()
|
||||
out.KeyFile = KeyFileName(ActiveKey(settings))
|
||||
return out, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user