Skip to content

Commit

Permalink
feat: Change the GetSitemapData function to exclude any entries that …
Browse files Browse the repository at this point in the history
…should be excluded from the sitemap
  • Loading branch information
Dobefu committed Dec 26, 2024
1 parent e41421c commit c612f10
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
42 changes: 26 additions & 16 deletions cmd/api/utils/get-alt-locales.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cs_sdk/api/get-entry-with-metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion cmd/server/routes/v1/get-sitemap-data.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func getEntries() (map[string]interface{}, error) {
Name: "locale",
Value: "en",
},
{
Name: "exclude_sitemap",
Value: true,
Operator: db_structs.NOT_EQUALS,
},
},
)

Expand All @@ -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
Expand Down

0 comments on commit c612f10

Please sign in to comment.