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
35 changes: 32 additions & 3 deletions apps/web/src/pages/browse/[title].astro
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ export async function getStaticPaths() {
const { titleNum, entries } = Astro.props;
const titleName = TITLE_NAMES[titleNum] ?? `Title ${titleNum}`;

// Load per-section change index (generated by generate-diffs.ts)
let changedSections: Record<string, string[]> = {};
try {
const { readFile } = await import('node:fs/promises');
const { join } = await import('node:path');
const diffsDir = new URL('../../../public/diffs/', import.meta.url).pathname;
const raw = await readFile(join(diffsDir, 'changed-sections.json'), 'utf8');
changedSections = JSON.parse(raw) as Record<string, string[]>;
} catch {
// No change data available yet
}

/** Check if a section was changed in any release point */
function sectionChangedIn(section: string): string[] {
const key = `title-${titleNum}/${section}`;
return changedSections[key] ?? [];
}

// Group entries by chapter, sort sections within each chapter
const byChapter = new Map<number, typeof entries>();
for (const entry of entries) {
Expand Down Expand Up @@ -145,16 +163,23 @@ const autoExpand = sortedChapters.length <= 10;
sTitle.includes('Renumbered') ? 'Renumbered' :
sTitle.includes('Transferred') ? 'Transferred' : null
);
const changes = sectionChangedIn(`section-${entry.data.usc_section}`);
const lastChange = changes.length > 0 ? changes[changes.length - 1] : null;

return (
<li>
<a
href={`${base}statute/${entry.id}/`}
class:list={[
'flex items-baseline gap-3 px-4 py-1.5 pl-12 text-xs transition-colors hover:bg-gray-50 dark:hover:bg-gray-900',
'flex items-center gap-3 px-4 py-1.5 pl-12 text-xs transition-colors hover:bg-gray-50 dark:hover:bg-gray-900',
isInactive && 'opacity-50',
]}
>
{lastChange ? (
<span class="h-1.5 w-1.5 shrink-0 rounded-full bg-teal" title={`Changed in ${lastChange.replace('pl-', 'PL ').replace('-', '-')}`} aria-label="Recently changed"></span>
) : (
<span class="h-1.5 w-1.5 shrink-0"></span>
)}
<span class="w-14 shrink-0 text-right font-mono text-[11px] text-slate dark:text-gray-500">
&sect; {entry.data.usc_section}
</span>
Expand All @@ -164,11 +189,15 @@ const autoExpand = sortedChapters.length <= 10;
]}>
{sTitle.replace(/^Section \S+ - /, '')}
</span>
{statusLabel && (
{statusLabel ? (
<span class="ml-auto shrink-0 rounded bg-gray-100 px-1 py-0.5 text-[9px] font-medium text-gray-500 dark:bg-gray-800 dark:text-gray-500">
{statusLabel}
</span>
)}
) : lastChange ? (
<span class="ml-auto shrink-0 text-[9px] text-teal dark:text-teal-bright">
{lastChange.replace('pl-', 'PL ').replace('-', '-')}
</span>
) : null}
</a>
</li>
);
Expand Down
24 changes: 22 additions & 2 deletions scripts/generate-diffs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

import { execSync } from 'node:child_process';
import { readFile, writeFile, mkdir } from 'node:fs/promises';
import { readFile, readdir, writeFile, mkdir } from 'node:fs/promises';
import { join } from 'node:path';
import { parseArgs } from 'node:util';

Expand Down Expand Up @@ -198,6 +198,26 @@ manifest.pairs.sort((a, b) => {
return ac !== bc ? ac - bc : al - bl;
});

// Build per-section change index: { "title-18/section-111": ["pl-117-159", ...] }
const sectionChanges: Record<string, string[]> = {};
for (const pair of manifest.pairs) {
const pairDir = join(output, `${pair.from}_${pair.to}`);
try {
const titles = await readdir(pairDir).catch(() => [] as string[]);
for (const titleDir of titles) {
const sections = await readdir(join(pairDir, titleDir)).catch(() => [] as string[]);
for (const sectionFile of sections) {
const key = `${titleDir}/${sectionFile.replace('.json', '')}`;
if (!sectionChanges[key]) sectionChanges[key] = [];
sectionChanges[key].push(pair.to);
}
}
} catch {
// Pair dir may not exist for cached entries from previous runs
}
}

await mkdir(output, { recursive: true });
await writeFile(join(output, 'manifest.json'), JSON.stringify(manifest, null, 2));
console.log(`Done. ${computed} new pairs computed, ${skipped} skipped (already cached). Manifest: ${output}/manifest.json`);
await writeFile(join(output, 'changed-sections.json'), JSON.stringify(sectionChanges));
console.log(`Done. ${computed} new pairs computed, ${skipped} skipped (already cached). ${Object.keys(sectionChanges).length} sections with changes tracked. Manifest: ${output}/manifest.json`);
Loading