Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions go/cmd/generatesitemap/generatesitemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ func generateSitemaps(ctx context.Context, client clients.CloudStorage, outputDi

for _, eco := range ecosystems {
vulns := entries[eco]
// Sort by LastModified descending
// Sort by LastModified ascending (oldest first)
sort.Slice(vulns, func(i, j int) bool {
return vulns[i].LastModified.After(vulns[j].LastModified)
return vulns[i].LastModified.Before(vulns[j].LastModified)
})

// Split into chunks
Expand All @@ -258,7 +258,8 @@ func generateSitemaps(ctx context.Context, client clients.CloudStorage, outputDi
// Add to index
chunkLastMod := time.Unix(0, 0).UTC()
if len(chunk) > 0 {
chunkLastMod = chunk[0].LastModified
// Since we sort by oldest first, the last item is the newest
chunkLastMod = chunk[len(chunk)-1].LastModified
}

sitemapIndexEntries = append(sitemapIndexEntries, SitemapIndexEntry{
Expand Down
6 changes: 3 additions & 3 deletions go/cmd/generatesitemap/generatesitemap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ func TestGenerateSitemaps(t *testing.T) {
if len(urlSet.URLs) != 2 {
t.Errorf("expected 2 URLs in sitemap_Go.xml, got %d", len(urlSet.URLs))
}
// Verify sorting (descending)
if urlSet.URLs[0].Loc != "https://example.com/vulnerability/GO-2" {
t.Errorf("expected GO-2 first (newer), got %s", urlSet.URLs[0].Loc)
// Verify sorting (ascending)
if urlSet.URLs[0].Loc != "https://example.com/vulnerability/GO-1" {
t.Errorf("expected GO-1 first (older), got %s", urlSet.URLs[0].Loc)
}

// Verify content of sitemap_index.xml
Expand Down
Loading