✨ feat: 新增 Github Trending 榜单
This commit is contained in:
parent
5df634058c
commit
b8c16ad88a
@ -38,6 +38,7 @@
|
||||
| 原神 | 最新消息 | genshin | 🟢 |
|
||||
| 微信读书 | 飙升榜 | weread | 🟢 |
|
||||
| 快手 | 热榜 | kuaishou | 🟢 |
|
||||
| Github | Trending | github | 🟢 |
|
||||
| 历史上的今天 | 指定日期 | calendar | 🟢 |
|
||||
|
||||
### 特殊接口说明
|
||||
|
@ -1,3 +1,10 @@
|
||||
/*
|
||||
* @author: x-dr
|
||||
* @date: 2023-12-25
|
||||
* @customEditors: imsyy
|
||||
* @lastEditTime: 2023-12-27
|
||||
*/
|
||||
|
||||
const Router = require("koa-router");
|
||||
const githubNewRouter = new Router();
|
||||
const axios = require("axios");
|
||||
@ -11,7 +18,6 @@ const routerInfo = {
|
||||
subtitle: "trending",
|
||||
};
|
||||
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "githubData";
|
||||
|
||||
@ -25,26 +31,33 @@ const headers = {
|
||||
"Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1",
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 数据处理
|
||||
const getData = (data) => {
|
||||
if (!data) return false;
|
||||
const dataList = [];
|
||||
const $ = cheerio.load(data);
|
||||
try {
|
||||
$(`.Box-row`).each((i,e)=>{
|
||||
$(`.Box-row`).each((i, e) => {
|
||||
// console.log(getCheerio(e).html());
|
||||
const item= cheerio.load($(e).html())
|
||||
const item = cheerio.load($(e).html());
|
||||
// console.log(item);
|
||||
const title = item("h2 a").attr('href').replace("\/","")
|
||||
const url = `https://github.com/${title}`
|
||||
const excerpt = item('p').text().replace(/(^\s*)|(\s*$)/g, "")
|
||||
const language = item('.f6 span[itemprop="programmingLanguage"]').text().replace(/(^\s*)|(\s*$)/g, "")
|
||||
const stars = item('.f6 a:first').text().replace(/(^\s*)|(\s*$)/g, "")
|
||||
const forks = item('.f6 a:eq(1)').text().replace(/(^\s*)|(\s*$)/g, "")
|
||||
const starstoday = item('.f6 span:eq(4)').text().replace(/(^\s*)|(\s*$)/g, "")
|
||||
|
||||
const title = item("h2 a").attr("href").replace("/", "");
|
||||
const url = `https://github.com/${title}`;
|
||||
const excerpt = item("p")
|
||||
.text()
|
||||
.replace(/(^\s*)|(\s*$)/g, "");
|
||||
const language = item('.f6 span[itemprop="programmingLanguage"]')
|
||||
.text()
|
||||
.replace(/(^\s*)|(\s*$)/g, "");
|
||||
const stars = item(".f6 a:first")
|
||||
.text()
|
||||
.replace(/(^\s*)|(\s*$)/g, "");
|
||||
const forks = item(".f6 a:eq(1)")
|
||||
.text()
|
||||
.replace(/(^\s*)|(\s*$)/g, "");
|
||||
const starstoday = item(".f6 span:eq(4)")
|
||||
.text()
|
||||
.replace(/(^\s*)|(\s*$)/g, "");
|
||||
|
||||
dataList.push({
|
||||
title: title,
|
||||
@ -54,7 +67,6 @@ const getData = (data) => {
|
||||
stars: stars,
|
||||
forks: forks,
|
||||
starstoday: starstoday,
|
||||
|
||||
});
|
||||
});
|
||||
return dataList;
|
||||
@ -64,8 +76,6 @@ const getData = (data) => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// trending
|
||||
githubNewRouter.get("/github", async (ctx) => {
|
||||
console.log("获取github trending");
|
||||
@ -112,10 +122,7 @@ githubNewRouter.get("/github", async (ctx) => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// 豆瓣新片榜 - 获取最新数据
|
||||
// trending - 获取最新数据
|
||||
githubNewRouter.get("/github/new", async (ctx) => {
|
||||
console.log("获取github trending - 最新数据");
|
||||
try {
|
||||
@ -161,7 +168,7 @@ githubNewRouter.get("/github/new", async (ctx) => {
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
githubNewRouter.info = routerInfo;
|
||||
module.exports = githubNewRouter;
|
||||
githubNewRouter.info = routerInfo;
|
||||
module.exports = githubNewRouter;
|
||||
|
Loading…
Reference in New Issue
Block a user