···1414export async function getDocumentsByTag(
1515 tag: string,
1616): Promise<{ posts: Post[] }> {
1717- // Query documents that have this tag
1717+ // Normalize tag to lowercase for case-insensitive matching
1818+ const normalizedTag = tag.toLowerCase();
1919+2020+ // Query documents that have this tag (case-insensitive)
2121+ // Use ilike on the JSONB text cast to match regardless of stored case
1822 const { data: rawDocuments, error } = await supabaseServerClient
1923 .from("documents")
2024 .select(
···2327 document_mentions_in_bsky(count),
2428 documents_in_publications(publications(*))`,
2529 )
2626- .contains("data->tags", `["${tag}"]`)
3030+ .filter("data->>tags", "ilike", `%"${normalizedTag}"%`)
2731 .order("sort_date", { ascending: false })
2832 .limit(50);
2933