|
1 |
| -import parse from "rss-to-json"; |
| 1 | +import Parser from "rss-parser"; |
2 | 2 |
|
3 | 3 | import type { Item } from "./_components/dashboard-item";
|
4 | 4 |
|
@@ -78,52 +78,47 @@ export const exampleData: Item[] = [
|
78 | 78 | },
|
79 | 79 | ];
|
80 | 80 |
|
81 |
| -export async function getRssData(): Promise<Item[]> { |
82 |
| - const rssData = (await parse( |
| 81 | +export async function getRssData(): Promise<NewsFeed> { |
| 82 | + const parser = new Parser(); |
| 83 | + |
| 84 | + const rssData = await parser.parseURL( |
83 | 85 | "https://www.economist.com/business/rss.xml",
|
84 |
| - )) as RssData; |
85 |
| - return rssData.items.map((item) => ({ |
86 |
| - description: item.description, |
87 |
| - id: encodeURIComponent(item.link), |
88 |
| - title: item.title, |
89 |
| - type: "news", |
90 |
| - url: item.link, |
91 |
| - })); |
| 86 | + ); |
| 87 | + |
| 88 | + return { |
| 89 | + ...rssData, |
| 90 | + id: encodeURIComponent(rssData.feedUrl ?? ""), |
| 91 | + type: "newsFeed", |
| 92 | + items: rssData.items.map((item) => ({ |
| 93 | + ...item, |
| 94 | + id: encodeURIComponent(item.link ?? ""), |
| 95 | + url: item.link, |
| 96 | + type: "newsItem", |
| 97 | + })), |
| 98 | + }; |
| 99 | + |
| 100 | + // return rssData.items.map((item) => ({ |
| 101 | + // ...item, |
| 102 | + // id: encodeURIComponent(item.link ?? ""), |
| 103 | + // url: item.link, |
| 104 | + // type: "news", |
| 105 | + // description: item.contentSnippet ?? "", |
| 106 | + // })); |
92 | 107 | }
|
93 | 108 |
|
94 |
| -export interface RssData { |
| 109 | +export type NewsItem = Parser.Item & { |
| 110 | + id: string; |
| 111 | + type: "newsItem"; |
| 112 | +}; |
| 113 | + |
| 114 | +export type NewsFeed = Omit<Parser.Output<undefined>, "items"> & { |
| 115 | + id: string; |
| 116 | + type: "newsFeed"; |
| 117 | + items: NewsItem[]; |
| 118 | +}; |
| 119 | + |
| 120 | +export type NewsSource = { |
95 | 121 | title: string;
|
96 |
| - description: string; |
97 |
| - link: string; |
98 |
| - image: string; |
99 |
| - category: []; |
100 |
| - items: { |
101 |
| - id: string; |
102 |
| - title: string; |
103 |
| - description: string; |
104 |
| - link: string; |
105 |
| - author: string; |
106 |
| - published: number | Date; |
107 |
| - created: number | Date; |
108 |
| - category: { |
109 |
| - $text: string; |
110 |
| - domain: string; |
111 |
| - }[]; |
112 |
| - enclosures: { |
113 |
| - height: string; |
114 |
| - medium: string; |
115 |
| - url: string; |
116 |
| - width: string; |
117 |
| - }[]; |
118 |
| - media: { |
119 |
| - thumbnail: |
120 |
| - | { |
121 |
| - height: string; |
122 |
| - medium: string; |
123 |
| - url: string; |
124 |
| - width: string; |
125 |
| - } |
126 |
| - | undefined; |
127 |
| - }; |
128 |
| - }[]; |
129 |
| -} |
| 122 | + url: string; |
| 123 | + feeds: NewsFeed[]; |
| 124 | +}; |
0 commit comments