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
38 changes: 38 additions & 0 deletions __tests__/sitemaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,25 @@ describe('GET /sitemaps/archive-index.xml', () => {

expect(res.text).not.toContain('/sources/nonexistent-source/best-of');
});

it('should exclude squad sources from archive index', async () => {
await con.getRepository(Archive).save([
{
...archiveBase,
scopeType: ArchiveScopeType.Source,
scopeId: 'm',
periodType: ArchivePeriodType.Month,
periodStart: new Date('2025-01-01T00:00:00.000Z'),
createdAt: new Date(),
},
]);

const res = await request(app.server)
.get('/sitemaps/archive-index.xml')
.expect(200);

expect(res.text).not.toContain('/sources/moderatedSquad/best-of');
});
});

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

expect(res.text).not.toContain('/sources/nonexistent-source/best-of');
});

it('should exclude squad sources from archive pages', async () => {
await con.getRepository(Archive).save([
{
...archiveBase,
scopeType: ArchiveScopeType.Source,
scopeId: 'm',
periodType: ArchivePeriodType.Month,
periodStart: new Date('2025-01-01T00:00:00.000Z'),
createdAt: new Date(),
},
]);

const res = await request(app.server)
.get('/sitemaps/archive-pages-source-month-0.xml')
.expect(200);

expect(res.text).not.toContain('/sources/moderatedSquad/best-of');
});
});

describe('GET /sitemaps/index.xml (archive entries)', () => {
Expand Down
8 changes: 6 additions & 2 deletions src/routes/sitemaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ const buildArchiveIndexSitemapQuery = (
scopeTypes: [ArchiveScopeType.Tag, ArchiveScopeType.Source],
})
.andWhere(
`CASE WHEN a."scopeType" = '${ArchiveScopeType.Source}' THEN s.handle IS NOT NULL ELSE TRUE END`,
`CASE WHEN a."scopeType" = '${ArchiveScopeType.Source}' THEN s.handle IS NOT NULL AND s.type != '${SourceType.Squad}' ELSE TRUE END`,
)
.groupBy('a."scopeType"')
.addGroupBy(
Expand Down Expand Up @@ -498,7 +498,11 @@ const buildArchivePagesPaginatedQuery = (
.andWhere('a."periodType" = :periodType', { periodType });

if (scopeType === ArchiveScopeType.Source) {
qb.innerJoin(Source, 's', 's.id = a."scopeId"');
qb.innerJoin(
Source,
's',
`s.id = a."scopeId" AND s.type != '${SourceType.Squad}'`,
);
qb.orderBy('s.handle', 'ASC');
} else {
qb.orderBy('a."scopeId"', 'ASC');
Expand Down
Loading