feat: the listing names the content types switched off

contract.ListingSettings.TypesOff lists the signpost keys of the content
types switched off in the sitemap settings, so another plugin (the SEO
tab's sitemap status) can tell an address left out with ReasonType
without reading the sitemap's tables. Additive.
This commit is contained in:
Jakub Zych
2026-11-04 13:35:17 +01:00
parent 291cf176db
commit 9e5c393709
4 changed files with 25 additions and 3 deletions

View File

@@ -200,7 +200,7 @@ The plugin publishes `classes.Listing` as `contract.Listing`:
- `Settings` answers the site address, the index address, the default locale and the groups with their listed addresses, their slug and their titles (the content type's HTML sitemap heading, else the Filter's group titles);
- `Entries` pages a group's listed addresses (`EntriesQuery{Group, Locale, After, Limit}`, 100 by default, at most 1000) with absolute URLs, titles and lastmod, `Next` and `Total`.
`Settings` also answers the HTML sitemap settings (`HTMLEnabled`, `HTMLPaths` by locale, `HTMLPageSize`) and the IndexNow key file name (`KeyFile`, `<key>.txt`, empty while IndexNow is off), so the SEO plugin and the layer read them without importing the sitemap's internals.
`Settings` also answers the HTML sitemap settings (`HTMLEnabled`, `HTMLPaths` by locale, `HTMLPageSize`) and the IndexNow key file name (`KeyFile`, `<key>.txt`, empty while IndexNow is off) and the content types switched off (`TypesOff`, whose addresses are left out with `ReasonType`), so the SEO plugin and the layer read them without importing the sitemap's internals.
### Admin

View File

@@ -8,6 +8,7 @@ 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"
)
@@ -42,7 +43,8 @@ func (l Listing) db(ctx context.Context) (*gorm.DB, error) {
// 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).
// IndexNow key file name (while IndexNow is on with a key), and the
// content types switched off.
func (l Listing) Settings(ctx context.Context) (contract.ListingSettings, error) {
var out contract.ListingSettings
db, err := l.db(ctx)
@@ -77,6 +79,18 @@ func (l Listing) Settings(ctx context.Context) (contract.ListingSettings, error)
out.HTMLPaths = settings.EffectiveHTMLPaths()
out.HTMLPageSize = settings.EffectiveHTMLPageSize()
out.KeyFile = KeyFileName(ActiveKey(settings))
out.TypesOff = []string{}
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() {
if !EffectiveType(typ, rows).Include {
out.TypesOff = append(out.TypesOff, typ.Key)
}
}
}
return out, nil
}

View File

@@ -95,7 +95,9 @@ type Listing interface {
// path) and HTMLPageSize are the HTML sitemap's settings (the sitemap
// serves its data at /_sitemap/api/v1/html); KeyFile is the IndexNow key
// file name (<key>.txt, served at /_sitemap/indexnow/<key>.txt for the
// site root), "" while IndexNow is off.
// site root), "" while IndexNow is off. TypesOff lists the content types
// (signpost keys) switched off in the sitemap settings, whose addresses
// are left out with ReasonType.
type ListingSettings struct {
SiteURL string
IndexURL string
@@ -105,6 +107,7 @@ type ListingSettings struct {
HTMLPaths map[string]string
HTMLPageSize int
KeyFile string
TypesOff []string
}
// GroupInfo is one file group: Key is the group (as Entries takes it), Slug

View File

@@ -289,6 +289,11 @@ func TestSettingsSingleton(t *testing.T) {
if reason != "type" {
t.Fatalf("the switched-off type's row has reason %q", reason)
}
if listing, ok := e.app.Lookup[contract.Listing](); !ok {
t.Fatal("no contract.Listing")
} else if ls, err := listing.Settings(t.Context()); err != nil || strings.Join(ls.TypesOff, ",") != offerType {
t.Fatalf("listing TypesOff = %v err=%v, want [%s]", ls.TypesOff, err, offerType)
}
s1 := files()
for _, want := range []string{"sitemap.xml", "sitemap-pages-1.xml", `"href":"/_sitemap/files/sitemap-pages-1.xml"`, `"href":"/sitemap.xml"`, "Left out of the sitemaps", "Content type turned off", "https://www.example.test/sitemap.xml"} {
if !strings.Contains(s1, want) {