From 9e5c393709bf76c574b59586d39b8ede65331ab3 Mon Sep 17 00:00:00 2001 From: Jakub Zych Date: Wed, 4 Nov 2026 13:35:17 +0100 Subject: [PATCH] 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. --- README.md | 2 +- classes/listing.go | 16 +++++++++++++++- contract/contract.go | 5 ++++- sitemap_index_test.go | 5 +++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7cf2e61..7cccad6 100644 --- a/README.md +++ b/README.md @@ -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`, `.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`, `.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 diff --git a/classes/listing.go b/classes/listing.go index 2493792..d80ffb9 100644 --- a/classes/listing.go +++ b/classes/listing.go @@ -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 } diff --git a/contract/contract.go b/contract/contract.go index fe7b398..8826157 100644 --- a/contract/contract.go +++ b/contract/contract.go @@ -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 (.txt, served at /_sitemap/indexnow/.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 diff --git a/sitemap_index_test.go b/sitemap_index_test.go index abf54d8..65ad754 100644 --- a/sitemap_index_test.go +++ b/sitemap_index_test.go @@ -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) {