From 14e2c3dbe6dadc77cb43cfb6807c04716283f6c6 Mon Sep 17 00:00:00 2001
From: prnake <52364396+prnake@users.noreply.github.com>
Date: Tue, 25 Feb 2020 00:13:25 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20url=20does=20not=20exist=20in=20?=
=?UTF-8?q?=E6=B8=85=E5=8D=8E=E5=A4=A7=E5=AD=A6=20&=20feet:=20add=20?=
=?UTF-8?q?=E6=B4=9B=E8=B0=B7=E8=BF=91=E6=9C=9F=E6=AF=94=E8=B5=9B=20&=20fi?=
=?UTF-8?q?x:=20=E6=B4=9B=E8=B0=B7=E6=97=A5=E6=8A=A5=20(#4063)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/new-media.md | 6 ----
docs/programming.md | 12 ++++++++
lib/router.js | 3 +-
lib/routes/luogu/contest.js | 41 ++++++++++++++++++++++++++++
lib/routes/luogu/daily.js | 5 ++--
lib/routes/universities/thu/index.js | 23 +++++++++++++---
6 files changed, 76 insertions(+), 14 deletions(-)
create mode 100644 lib/routes/luogu/contest.js
diff --git a/docs/new-media.md b/docs/new-media.md
index 7668bc723..c20fee4c0 100644
--- a/docs/new-media.md
+++ b/docs/new-media.md
@@ -593,12 +593,6 @@ Supported sub-sites:
-## 洛谷
-
-### 日报
-
-
-
## 镁客网 im2maker
### 镁客网频道
diff --git a/docs/programming.md b/docs/programming.md
index 3a3fb5779..a99354d09 100644
--- a/docs/programming.md
+++ b/docs/programming.md
@@ -502,6 +502,18 @@ GitHub 官方也提供了一些 RSS:
+## 洛谷
+
+### 日报
+
+
+
+
+### 近期比赛
+
+
+
+
## 码农俱乐部
### 话题
diff --git a/lib/router.js b/lib/router.js
index 5883a4d53..24f44a963 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -1262,8 +1262,9 @@ router.get('/12306/zxdt/:id?', require('./routes/12306/zxdt'));
// 北京天文馆每日一图
router.get('/bjp/apod', require('./routes/bjp/apod'));
-// 洛谷日报
+// 洛谷
router.get('/luogu/daily/:id?', require('./routes/luogu/daily'));
+router.get('/luogu/contest', require('./routes/luogu/contest'));
// 决胜网
router.get('/juesheng', require('./routes/juesheng'));
diff --git a/lib/routes/luogu/contest.js b/lib/routes/luogu/contest.js
new file mode 100644
index 000000000..024e0636d
--- /dev/null
+++ b/lib/routes/luogu/contest.js
@@ -0,0 +1,41 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const resolve_url = require('url').resolve;
+
+module.exports = async (ctx) => {
+ const link = 'https://www.luogu.com.cn/';
+ const response = await got.get(link);
+ const $ = cheerio.load(response.data);
+ const title = '洛谷近期比赛';
+
+ const out = $('.am-panel-hd ')
+ .slice(0, 10)
+ .map(function() {
+ const info = {
+ title:
+ $(this)
+ .find('a')
+ .text() || $(this).text(),
+ description:
+ $(this).html() +
+ $(this)
+ .parent()
+ .find('.am-panel-bd')
+ .html(),
+ link: resolve_url(
+ 'https://www.luogu.com.cn',
+ $(this)
+ .find('a')
+ .attr('href')
+ ),
+ };
+ return info;
+ })
+ .get();
+
+ ctx.state.data = {
+ title: title,
+ link: link,
+ item: out,
+ };
+};
diff --git a/lib/routes/luogu/daily.js b/lib/routes/luogu/daily.js
index f0d76d93b..6339b5920 100644
--- a/lib/routes/luogu/daily.js
+++ b/lib/routes/luogu/daily.js
@@ -2,12 +2,11 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
- const id = ctx.params.id || 92685;
-
+ const id = ctx.params.id || 179788;
const link = `https://www.luogu.org/discuss/show/${id}`;
const response = await got.get(link);
const $ = cheerio.load(response.data);
- const title = $('#app-body-new div h1').text();
+ const title = $('title').text();
const out = $('div.am-comment-main > div > p')
.slice(0, 10)
diff --git a/lib/routes/universities/thu/index.js b/lib/routes/universities/thu/index.js
index d2b56e360..09dce5d75 100644
--- a/lib/routes/universities/thu/index.js
+++ b/lib/routes/universities/thu/index.js
@@ -60,8 +60,8 @@ module.exports = async (ctx) => {
item: $('table>tbody>tr')
.slice(0, 10)
.map((_, elem) => ({
- link: resolve_url(base_url, $('td>a', elem).attr('href')),
- title: $('td>a', elem).text(),
+ link: get_link($('td>a', elem).attr('href'), news_url + path),
+ title: get_title($('td>a', elem).text(), $('td', elem).text()),
pubDate: new Date(
$('td>font>span', elem)
.text()
@@ -78,8 +78,8 @@ module.exports = async (ctx) => {
item: $('.cont_list>li')
.slice(0, 10)
.map((_, elem) => ({
- link: resolve_url(base_url, $('a', elem).attr('href')),
- title: $('a', elem).text(),
+ link: get_link($('a', elem).attr('href'), news_url + path),
+ title: get_title($('a', elem).text(), $.text()),
pubDate: new Date(
$('time', elem)
.text()
@@ -90,3 +90,18 @@ module.exports = async (ctx) => {
};
}
};
+
+function get_link(url, alter_url) {
+ if (url !== undefined) {
+ return resolve_url(base_url, url);
+ } else {
+ return alter_url;
+ }
+}
+
+function get_title(title, data) {
+ if (title) {
+ return title;
+ }
+ return data;
+}