Skip to content

Commit fd5d193

Browse files
News component
1 parent 6355b8c commit fd5d193

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@ function App() {
6868
)
6969
}
7070

71-
export default App
71+
export default App;
72+
export type { Blog };

src/components/News.tsx

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,48 @@
1+
import rawItemData from '../assets/items.json'
2+
import rawBlogData from '../assets/blogs.json'
3+
import type { Blog } from '../App';
4+
import { Link } from 'react-router';
5+
import avatar from '../assets/avatar.webp'
16

2-
function News(){
7+
interface Item {
8+
blog_id: string;
9+
feed: string;
10+
item_name: string;
11+
item_url: string;
12+
time: string;
13+
}
14+
15+
interface ItemData {
16+
update_time: 'string';
17+
items: Item[];
18+
}
19+
20+
const itemData: ItemData = rawItemData as ItemData;
21+
const items: Item[] = itemData.items;
22+
const blogs: Blog[] = rawBlogData as Blog[];
23+
const blogMap: Record<string, Blog> = {};
24+
25+
function News() {
26+
blogs.forEach(blog => {
27+
blogMap[blog.name] = blog;
28+
});
329
return (
4-
<div className="m-3">
5-
<h1 className="text-4xl font-bold mb-4">News Page</h1>
6-
<p className="text-lg">Welcome to the News page! Here you can find the latest updates and articles.</p>
30+
<div className='container mx-auto p-4 flex flex-col gap-4'>
31+
{items.slice(0, 20).map(item => (
32+
<div className='flex flex-row gap-2' key={item.item_url}>
33+
<div>
34+
<img src={blogMap[item.blog_id]?.avatar === 'avatar.webp' ? avatar : blogMap[item.blog_id]?.avatar} className='w-12 aspect-square overflow-hidden rounded-lg' />
35+
</div>
36+
<div className='flex flex-col gap-1'>
37+
<Link to={item.item_url}><h2 className='font-mono'>{item.item_name}</h2></Link>
38+
<div>
39+
<Link to={blogMap[item.blog_id]?.url} className='text-sm text-gray-500 font-mono'>
40+
<span className='hover:underline underline-offset-2'>{blogMap[item.blog_id]?.name}</span> <span >{new Date(item.time).toLocaleDateString()}</span>
41+
</Link>
42+
</div>
43+
</div>
44+
</div>
45+
))}
746
</div>
847
);
948
}

0 commit comments

Comments
 (0)