commit b355ae564a399a98efb5a17b0981065ddb754ebb
parent 646c4deee31cca209aab78bbc51c3d9211a6c26a
Author: Henry Unite <unitehenry@gmail.com>
Date: Sun, 10 May 2026 23:42:42 +0000
feat: load feeds
Diffstat:
4 files changed, 358 insertions(+), 10 deletions(-)
diff --git a/app/src/App.tsx b/app/src/App.tsx
@@ -1,17 +1,194 @@
-import { Button } from "@/components/ui/button"
+import { useEffect, useState, useMemo } from "react"
+import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
+import { Badge } from "@/components/ui/badge"
+import { Input } from "@/components/ui/input"
+
+interface FeedItem {
+ title: string
+ description: string
+ link: string
+ pubDate: string
+ encoded?: string
+}
+
+interface RawFeedItemRSS {
+ title: string
+ description: string
+ link: string
+ pubDate: string
+ encoded?: string
+}
+
+interface RawFeedItemJsonFeed {
+ title: string
+ content_html?: string
+ content_text?: string
+ date_published: string
+ url: string
+}
+
+interface Feed {
+ name: string
+ title: string
+ description: string
+ items: FeedItem[]
+}
export function App() {
+ const [feeds, setFeeds] = useState<Feed[]>([])
+ const [loading, setLoading] = useState(true)
+ const [searchQuery, setSearchQuery] = useState("")
+
+ const filteredFeeds = useMemo(() => {
+ if (!searchQuery) {
+ return feeds.map(feed => ({
+ ...feed,
+ items: feed.items.sort((a, b) => new Date(b.pubDate).getTime() - new Date(a.pubDate).getTime())
+ }))
+ }
+ return feeds.map(feed => ({
+ ...feed,
+ items: feed.items
+ .filter(item =>
+ item.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
+ item.description.toLowerCase().includes(searchQuery.toLowerCase())
+ )
+ .sort((a, b) => new Date(b.pubDate).getTime() - new Date(a.pubDate).getTime())
+ })).filter(feed => feed.items.length > 0)
+ }, [feeds, searchQuery])
+
+
+
+ useEffect(() => {
+ async function loadFeeds() {
+ try {
+ const csvResponse = await fetch('/feeds/feeds.csv')
+ const csvText = await csvResponse.text()
+ const lines = csvText.trim().split('\n')
+ const feedPromises = lines.map(async line => {
+ try {
+ const [, , file] = line.split(',')
+ const jsonResponse = await fetch(`/feeds/${file}.json`)
+ if (!jsonResponse.ok) throw new Error(`Fetch failed: ${jsonResponse.status}`)
+ const data = await jsonResponse.json()
+
+ let title: string, description: string, rawItems: any[]
+
+ if (data.rss?.channel) {
+ // RSS format
+ const channel = data.rss.channel
+ title = channel.title
+ description = channel.description || ''
+ rawItems = Array.isArray(channel.item) ? channel.item : []
+ } else if (data.version && Array.isArray(data.items)) {
+ // JSON Feed format
+ title = data.title || file
+ description = data.description || ''
+ rawItems = data.items
+ } else if (data.feed?.entry) {
+ // Atom format
+ const feed = data.feed
+ title = feed.title?.["#text"] || feed.title || file
+ description = feed.subtitle?.["#text"] || feed.subtitle || ''
+ rawItems = Array.isArray(feed.entry) ? feed.entry : [feed.entry]
+ } else {
+ // Unknown format, skip
+ return null
+ }
+
+ const items: FeedItem[] = rawItems.map(item => {
+ if (item.title && item.description && item.link && item.pubDate) {
+ // RSS item
+ return {
+ title: item.title,
+ description: item.description,
+ link: item.link,
+ pubDate: item.pubDate,
+ encoded: item.encoded
+ } as FeedItem
+ } else if (item.title && (item.content_html || item.content_text) && item.url && item.date_published) {
+ // JsonFeed item
+ return {
+ title: item.title,
+ description: item.content_text || item.content_html || '',
+ link: item.url,
+ pubDate: item.date_published
+ } as FeedItem
+ } else if (item.published || item.updated) {
+ // Atom entry
+ return {
+ title: item.title?.["#text"] || item.title,
+ description: item.summary?.["#text"] || item.content?.["#text"] || '',
+ link: item.link?.["@href"] || item.link,
+ pubDate: item.published || item.updated
+ } as FeedItem
+ } else {
+ // Unknown item format, skip
+ return null
+ }
+ }).filter(Boolean) as FeedItem[]
+
+ const feed: Feed = {
+ name: file,
+ title,
+ description,
+ items
+ }
+ return feed
+ } catch (error) {
+ console.error(`Error processing feed ${line}:`, error)
+ return null
+ }
+ })
+ const loadedFeeds = (await Promise.all(feedPromises)).filter(Boolean) as Feed[]
+ setFeeds(loadedFeeds)
+ } catch (error) {
+ console.error('Error loading feeds:', error)
+ } finally {
+ setLoading(false)
+ }
+ }
+ loadFeeds()
+ }, [])
+
+ if (loading) {
+ return <div className="flex min-h-svh p-6">Loading RSS feeds...</div>
+ }
+
return (
<div className="flex min-h-svh p-6">
- <div className="flex max-w-md min-w-0 flex-col gap-4 text-sm leading-loose">
- <div>
- <h1 className="font-medium">Project ready!</h1>
- <p>You may now add components and start building.</p>
- <p>We've already added the button component for you.</p>
- <Button className="mt-2">Button</Button>
- </div>
- <div className="font-mono text-xs text-muted-foreground">
- (Press <kbd>d</kbd> to toggle dark mode)
+ <div className="max-w-4xl w-full mx-auto gap-4">
+ <h1 className="text-2xl font-bold mb-6">RSS Reader</h1>
+ <Input
+ placeholder="Search RSS items..."
+ value={searchQuery}
+ onChange={(e) => setSearchQuery(e.target.value)}
+ className="mb-6"
+ />
+ <div className="grid gap-6">
+ {filteredFeeds.map(feed => (
+ <Card key={feed.name}>
+ <CardHeader>
+ <CardTitle>{feed.title}</CardTitle>
+ <CardDescription>{feed.description}</CardDescription>
+ </CardHeader>
+ <CardContent>
+ <div className="space-y-4">
+ {feed.items.map((item, index) => (
+ <div key={index} className="border rounded-lg p-4">
+ <h3 className="font-semibold mb-1">
+ <a href={item.link} target="_blank" rel="noopener noreferrer" className="hover:underline">
+ {item.title}
+ </a>
+ </h3>
+ <p className="text-sm text-muted-foreground mb-2 line-clamp-3">{item.description}</p>
+ <Badge variant="secondary">{new Date(item.pubDate).toLocaleDateString()}</Badge>
+ </div>
+ ))}
+ </div>
+ </CardContent>
+ </Card>
+ ))}
</div>
</div>
</div>
diff --git a/app/src/components/ui/badge.tsx b/app/src/components/ui/badge.tsx
@@ -0,0 +1,49 @@
+import * as React from "react"
+import { cva, type VariantProps } from "class-variance-authority"
+import { Slot } from "radix-ui"
+
+import { cn } from "@/lib/utils"
+
+const badgeVariants = cva(
+ "group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-all focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!",
+ {
+ variants: {
+ variant: {
+ default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
+ secondary:
+ "bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
+ destructive:
+ "bg-destructive/10 text-destructive focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:focus-visible:ring-destructive/40 [a]:hover:bg-destructive/20",
+ outline:
+ "border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
+ ghost:
+ "hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
+ link: "text-primary underline-offset-4 hover:underline",
+ },
+ },
+ defaultVariants: {
+ variant: "default",
+ },
+ }
+)
+
+function Badge({
+ className,
+ variant = "default",
+ asChild = false,
+ ...props
+}: React.ComponentProps<"span"> &
+ VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
+ const Comp = asChild ? Slot.Root : "span"
+
+ return (
+ <Comp
+ data-slot="badge"
+ data-variant={variant}
+ className={cn(badgeVariants({ variant }), className)}
+ {...props}
+ />
+ )
+}
+
+export { Badge, badgeVariants }
diff --git a/app/src/components/ui/card.tsx b/app/src/components/ui/card.tsx
@@ -0,0 +1,103 @@
+import * as React from "react"
+
+import { cn } from "@/lib/utils"
+
+function Card({
+ className,
+ size = "default",
+ ...props
+}: React.ComponentProps<"div"> & { size?: "default" | "sm" }) {
+ return (
+ <div
+ data-slot="card"
+ data-size={size}
+ className={cn(
+ "group/card flex flex-col gap-4 overflow-hidden rounded-xl bg-card py-4 text-sm text-card-foreground ring-1 ring-foreground/10 has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:gap-3 data-[size=sm]:py-3 data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="card-header"
+ className={cn(
+ "group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-4 group-data-[size=sm]/card:px-3 has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-4 group-data-[size=sm]/card:[.border-b]:pb-3",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="card-title"
+ className={cn(
+ "font-heading text-base leading-snug font-medium group-data-[size=sm]/card:text-sm",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="card-description"
+ className={cn("text-sm text-muted-foreground", className)}
+ {...props}
+ />
+ )
+}
+
+function CardAction({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="card-action"
+ className={cn(
+ "col-start-2 row-span-2 row-start-1 self-start justify-self-end",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function CardContent({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="card-content"
+ className={cn("px-4 group-data-[size=sm]/card:px-3", className)}
+ {...props}
+ />
+ )
+}
+
+function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="card-footer"
+ className={cn(
+ "flex items-center rounded-b-xl border-t bg-muted/50 p-4 group-data-[size=sm]/card:p-3",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+export {
+ Card,
+ CardHeader,
+ CardFooter,
+ CardTitle,
+ CardAction,
+ CardDescription,
+ CardContent,
+}
diff --git a/app/src/components/ui/input.tsx b/app/src/components/ui/input.tsx
@@ -0,0 +1,19 @@
+import * as React from "react"
+
+import { cn } from "@/lib/utils"
+
+function Input({ className, type, ...props }: React.ComponentProps<"input">) {
+ return (
+ <input
+ type={type}
+ data-slot="input"
+ className={cn(
+ "h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+export { Input }