mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-24 05:24:23 +00:00
Refactor API endpoints to use cached data and update Code of Conduct to Contributor Covenant
This commit is contained in:
parent
878ac4f1a6
commit
96b297f617
17 changed files with 207 additions and 31 deletions
30
server/api/cached/rss/google.ts
Normal file
30
server/api/cached/rss/google.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import Parser from "rss-parser";
|
||||
import { HTMLToJSON } from "html-to-json-parser";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
let array = [];
|
||||
const parser = new Parser();
|
||||
try {
|
||||
const feed = await parser.parseURL(
|
||||
"https://news.google.com/rss?&hl=zh-TW&gl=TW&ceid=TW:zh-Hant",
|
||||
);
|
||||
feed.items.forEach(async (item) => {
|
||||
const rawRelatedNews = await HTMLToJSON(item.content, true);
|
||||
const relatedNews = JSON.parse(rawRelatedNews.replace("ol", ""));
|
||||
array.push({
|
||||
title: item.title,
|
||||
link: item.link,
|
||||
date: item.pubDate,
|
||||
content: relatedNews,
|
||||
});
|
||||
console.log(item.title);
|
||||
});
|
||||
return array;
|
||||
} catch (error) {
|
||||
console.error("Error fetching RSS:", error);
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: "Failed to fetch RSS feed",
|
||||
});
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue