Skip to content

Commit 50fb615

Browse files
feat: add RSS feed for recent US Code updates (#132) (#134)
- /feed.xml endpoint using @astrojs/rss - Shows 50 most recently updated sections - Title format: "N U.S.C. § M — Section name" - Feed autodiscovery link in BaseLayout head - Enables RSS readers and monitoring tools to track changes Closes #132 Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c9c2511 commit 50fb615

4 files changed

Lines changed: 44 additions & 1 deletion

File tree

apps/web/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
"test": "vitest run"
1313
},
1414
"dependencies": {
15-
"@civic-source/types": "workspace:*",
15+
"@astrojs/rss": "^4.0.18",
1616
"@astrojs/svelte": "^8.0.4",
17+
"@civic-source/types": "workspace:*",
1718
"@octokit/rest": "^22.0.1",
1819
"@tailwindcss/typography": "^0.5.19",
1920
"@tailwindcss/vite": "^4.2.2",

apps/web/src/layouts/BaseLayout.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const titleEntries = Object.entries(TITLE_NAMES)
3838
<link rel="canonical" href={new URL(Astro.url.pathname, Astro.site).href} />
3939
<meta name="base-url" content={base} />
4040
<link rel="icon" type="image/svg+xml" href={`${base}favicon.svg`} />
41+
<link rel="alternate" type="application/rss+xml" title="US Code Tracker — Recent Updates" href={`${base}feed.xml`} />
4142
<!-- Open Graph -->
4243
<meta property="og:type" content="website" />
4344
<meta property="og:title" content={title === 'US Code Tracker' ? title : `${title} | US Code Tracker`} />

apps/web/src/pages/feed.xml.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import rss from '@astrojs/rss';
2+
import { getCollection } from 'astro:content';
3+
import type { APIContext } from 'astro';
4+
5+
export async function GET(context: APIContext) {
6+
const statutes = await getCollection('statutes');
7+
8+
// Sort by generated_at descending to get most recently updated sections
9+
const sorted = statutes
10+
.filter(s => s.data.generated_at)
11+
.sort((a, b) => {
12+
const aDate = a.data.generated_at ?? '';
13+
const bDate = b.data.generated_at ?? '';
14+
return bDate.localeCompare(aDate);
15+
})
16+
.slice(0, 50);
17+
18+
return rss({
19+
title: 'US Code Tracker — Recent Updates',
20+
description: 'Track amendments to the United States Code. Updated weekly from the Office of the Law Revision Counsel.',
21+
site: context.site ?? 'https://civic-source.github.io/us-code-tracker/',
22+
items: sorted.map(entry => ({
23+
title: `${entry.data.usc_title} U.S.C. § ${entry.data.usc_section}${entry.data.title.replace(/^Section \S+ - /, '')}`,
24+
pubDate: new Date(entry.data.generated_at ?? Date.now()),
25+
link: `/us-code-tracker/statute/${entry.id}/`,
26+
description: `${entry.data.classification}. Current through ${entry.data.current_through}.`,
27+
})),
28+
});
29+
}

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)