From c612f10b2caf7c71cf56d8c44762e432e804fae7 Mon Sep 17 00:00:00 2001 From: Connor van Spronssen Date: Thu, 26 Dec 2024 15:44:59 +0100 Subject: [PATCH] feat: Change the GetSitemapData function to exclude any entries that should be excluded from the sitemap --- cmd/api/utils/get-alt-locales.go | 42 ++++++++++++++--------- cmd/cs_sdk/api/get-entry-with-metadata.go | 2 +- cmd/server/routes/v1/get-sitemap-data.go | 7 +++- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/cmd/api/utils/get-alt-locales.go b/cmd/api/utils/get-alt-locales.go index 46d8009..41aaffd 100644 --- a/cmd/api/utils/get-alt-locales.go +++ b/cmd/api/utils/get-alt-locales.go @@ -8,25 +8,35 @@ import ( "github.com/Dobefu/csb/cmd/logger" ) -func GetAltLocales(entry structs.Route) ([]api_structs.AltLocale, error) { +func GetAltLocales(entry structs.Route, includeSitemapExcluded bool) ([]api_structs.AltLocale, error) { + where := []db_structs.QueryWhere{ + { + Name: "uid", + Value: entry.Uid, + }, + { + Name: "published", + Value: true, + }, + { + Name: "locale", + Value: entry.Locale, + Operator: db_structs.NOT_EQUALS, + }, + } + + if !includeSitemapExcluded { + where = append(where, db_structs.QueryWhere{ + Name: "exclude_sitemap", + Value: true, + Operator: db_structs.NOT_EQUALS, + }) + } + rows, err := query.QueryRows( "routes", []string{"uid", "content_type", "locale", "slug", "url"}, - []db_structs.QueryWhere{ - { - Name: "uid", - Value: entry.Uid, - }, - { - Name: "published", - Value: true, - }, - { - Name: "locale", - Value: entry.Locale, - Operator: db_structs.NOT_EQUALS, - }, - }, + where, ) if err != nil { diff --git a/cmd/cs_sdk/api/get-entry-with-metadata.go b/cmd/cs_sdk/api/get-entry-with-metadata.go index a815540..3d2691c 100644 --- a/cmd/cs_sdk/api/get-entry-with-metadata.go +++ b/cmd/cs_sdk/api/get-entry-with-metadata.go @@ -13,7 +13,7 @@ func GetEntryWithMetadata(route structs.Route) (interface{}, []api_structs.AltLo return nil, nil, nil, err } - altLocales, err := utils.GetAltLocales(route) + altLocales, err := utils.GetAltLocales(route, true) if err != nil { return nil, nil, nil, err diff --git a/cmd/server/routes/v1/get-sitemap-data.go b/cmd/server/routes/v1/get-sitemap-data.go index 014cf98..df079dc 100644 --- a/cmd/server/routes/v1/get-sitemap-data.go +++ b/cmd/server/routes/v1/get-sitemap-data.go @@ -42,6 +42,11 @@ func getEntries() (map[string]interface{}, error) { Name: "locale", Value: "en", }, + { + Name: "exclude_sitemap", + Value: true, + Operator: db_structs.NOT_EQUALS, + }, }, ) @@ -64,7 +69,7 @@ func getEntries() (map[string]interface{}, error) { return entries, err } - altLocales, err := api_utils.GetAltLocales(result) + altLocales, err := api_utils.GetAltLocales(result, false) if err != nil { return entries, err