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:
Jakub Zych
2026-11-04 12:32:47 +01:00
parent e02d0b173f
commit 8f4ff2a97d
12 changed files with 981 additions and 67 deletions

View File

@@ -1,6 +1,7 @@
package classes
import (
"encoding/json"
"strings"
"git.golem15.com/golem15/sm-sitemap-plugin/models"
@@ -59,3 +60,39 @@ func Absolute(site, u string) string {
}
return ""
}
// MergeHTMLPaths merges submitted HTML sitemap addresses (locale to path)
// into the stored ones: a sent locale replaces its address, a blank one
// removes it, the others keep theirs. problem is true when a sent address
// is not a models.ValidHTMLPath; nothing is merged then.
func MergeHTMLPaths(db *gorm.DB, sent map[string]string) (map[string]string, bool) {
settings, err := LoadSettings(db)
if err != nil {
return nil, true
}
merged := settings.EffectiveHTMLPaths()
for locale, path := range sent {
locale, path = strings.TrimSpace(locale), strings.TrimSpace(path)
if locale == "" {
continue
}
if path == "" {
delete(merged, locale)
continue
}
if !models.ValidHTMLPath(path) {
return nil, true
}
merged[locale] = path
}
return merged, false
}
// StoreHTMLPaths writes the HTML sitemap addresses to settings row 1.
func StoreHTMLPaths(db *gorm.DB, paths map[string]string) error {
raw, err := json.Marshal(paths)
if err != nil {
return err
}
return db.Exec(`UPDATE golem15_sitemap_settings SET html_paths = ?::jsonb WHERE id = 1`, string(raw)).Error
}