dailyhot-api
Version:
An Api on Today's Hot list
41 lines (40 loc) • 1.3 kB
JavaScript
import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_, noCache) => {
const listData = await getList(noCache);
const routeData = {
name: "guokr",
title: "果壳",
type: "热门文章",
description: "科技有意思",
link: "https://www.guokr.com/",
total: listData.data?.length || 0,
...listData,
};
return routeData;
};
const getList = async (noCache) => {
const url = `https://www.guokr.com/beta/proxy/science_api/articles?limit=30`;
const result = await get({
url,
noCache,
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0",
},
});
const list = result.data;
return {
...result,
data: list.map((v) => ({
id: v.id,
title: v.title,
desc: v.summary,
cover: v.small_image,
author: v.author?.nickname,
hot: undefined,
timestamp: getTime(v.date_modified),
url: `https://www.guokr.com/article/${v.id}`,
mobileUrl: `https://m.guokr.com/article/${v.id}`,
})),
};
};