Skip to content

Commit 7a9a21d

Browse files
authored
fix: exclude squads from sources best-of sitemap (#3786)
1 parent 025d221 commit 7a9a21d

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

__tests__/sitemaps.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,25 @@ describe('GET /sitemaps/archive-index.xml', () => {
11501150

11511151
expect(res.text).not.toContain('/sources/nonexistent-source/best-of');
11521152
});
1153+
1154+
it('should exclude squad sources from archive index', async () => {
1155+
await con.getRepository(Archive).save([
1156+
{
1157+
...archiveBase,
1158+
scopeType: ArchiveScopeType.Source,
1159+
scopeId: 'm',
1160+
periodType: ArchivePeriodType.Month,
1161+
periodStart: new Date('2025-01-01T00:00:00.000Z'),
1162+
createdAt: new Date(),
1163+
},
1164+
]);
1165+
1166+
const res = await request(app.server)
1167+
.get('/sitemaps/archive-index.xml')
1168+
.expect(200);
1169+
1170+
expect(res.text).not.toContain('/sources/moderatedSquad/best-of');
1171+
});
11531172
});
11541173

11551174
describe('GET /sitemaps/archive-pages-:scopeType-:periodType-:page.xml', () => {
@@ -1303,6 +1322,25 @@ describe('GET /sitemaps/archive-pages-:scopeType-:periodType-:page.xml', () => {
13031322

13041323
expect(res.text).not.toContain('/sources/nonexistent-source/best-of');
13051324
});
1325+
1326+
it('should exclude squad sources from archive pages', async () => {
1327+
await con.getRepository(Archive).save([
1328+
{
1329+
...archiveBase,
1330+
scopeType: ArchiveScopeType.Source,
1331+
scopeId: 'm',
1332+
periodType: ArchivePeriodType.Month,
1333+
periodStart: new Date('2025-01-01T00:00:00.000Z'),
1334+
createdAt: new Date(),
1335+
},
1336+
]);
1337+
1338+
const res = await request(app.server)
1339+
.get('/sitemaps/archive-pages-source-month-0.xml')
1340+
.expect(200);
1341+
1342+
expect(res.text).not.toContain('/sources/moderatedSquad/best-of');
1343+
});
13061344
});
13071345

13081346
describe('GET /sitemaps/index.xml (archive entries)', () => {

src/routes/sitemaps.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ const buildArchiveIndexSitemapQuery = (
455455
scopeTypes: [ArchiveScopeType.Tag, ArchiveScopeType.Source],
456456
})
457457
.andWhere(
458-
`CASE WHEN a."scopeType" = '${ArchiveScopeType.Source}' THEN s.handle IS NOT NULL ELSE TRUE END`,
458+
`CASE WHEN a."scopeType" = '${ArchiveScopeType.Source}' THEN s.handle IS NOT NULL AND s.type != '${SourceType.Squad}' ELSE TRUE END`,
459459
)
460460
.groupBy('a."scopeType"')
461461
.addGroupBy(
@@ -498,7 +498,11 @@ const buildArchivePagesPaginatedQuery = (
498498
.andWhere('a."periodType" = :periodType', { periodType });
499499

500500
if (scopeType === ArchiveScopeType.Source) {
501-
qb.innerJoin(Source, 's', 's.id = a."scopeId"');
501+
qb.innerJoin(
502+
Source,
503+
's',
504+
`s.id = a."scopeId" AND s.type != '${SourceType.Squad}'`,
505+
);
502506
qb.orderBy('s.handle', 'ASC');
503507
} else {
504508
qb.orderBy('a."scopeId"', 'ASC');

0 commit comments

Comments
 (0)