From c02d7c00fd5cb7afd11dd796b75d0349ba97c3ce Mon Sep 17 00:00:00 2001
From: Ethan Shen <42264778+nczitzk@users.noreply.github.com>
Date: Sat, 2 Jul 2022 21:41:01 +0800
Subject: [PATCH] =?UTF-8?q?fix(route):=20=E4=B8=9C=E8=8E=9E=E6=95=99?=
=?UTF-8?q?=E7=A0=94=E7=BD=91=20(#10102)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* fix(route): 东莞教研网
* fix: external links
* docs: move to study
---
docs/other.md | 12 -------
docs/study.md | 22 +++++++++++++
lib/router.js | 2 +-
lib/routes/dgjyw/index.js | 66 -------------------------------------
lib/v2/dgjyw/index.js | 67 ++++++++++++++++++++++++++++++++++++++
lib/v2/dgjyw/maintainer.js | 3 ++
lib/v2/dgjyw/radar.js | 13 ++++++++
lib/v2/dgjyw/router.js | 3 ++
8 files changed, 109 insertions(+), 79 deletions(-)
delete mode 100644 lib/routes/dgjyw/index.js
create mode 100644 lib/v2/dgjyw/index.js
create mode 100644 lib/v2/dgjyw/maintainer.js
create mode 100644 lib/v2/dgjyw/radar.js
create mode 100644 lib/v2/dgjyw/router.js
diff --git a/docs/other.md b/docs/other.md
index 84e7fcdb87..113078e99f 100644
--- a/docs/other.md
+++ b/docs/other.md
@@ -405,18 +405,6 @@ type 为 all 时,category 参数不支持 cost 和 free
-## 东莞教研网
-
-### 信息公开
-
-
-
-| 动态 | 公示 | 通知 |
-| ---- | ------------ | ------ |
-| news | announcement | notice |
-
-
-
## 福利资源 - met.red
### 福利资源 - met.red
diff --git a/docs/study.md b/docs/study.md
index 8d7ca8cc36..d2e80f4afb 100644
--- a/docs/study.md
+++ b/docs/study.md
@@ -248,6 +248,28 @@ path="/ctfhub/upcoming/:limit?"
+## 东莞教研网
+
+### 分类
+
+
+
+| 通知 | 动态 | 公示 |
+| -- | -- | -- |
+| tz | dt | gs |
+
+::: tip 提示
+
+分类字段处填写的是对应东莞教研网网址中中介于 **** 和 **.htm** 中间的一段。
+
+如 [通知](https://www.dgjyw.com/tz.htm) 的网址为 ,其中间字段为 `tz`,所以可得路由为 [`/dgjyw/tz`](https://rsshub.app/dgjyw/tz);
+
+同理,[教育科研 - 科研文件](https://www.dgjyw.com/jyky/kywj.htm) 的网址为 ,其中间字段为 `jyky/kywj`,所以可得路由为 [`/dgjyw/jyky/kywj`](https://rsshub.app/dgjyw/jyky/kywj)。
+
+:::
+
+
+
## 杭州市国家普通话测试网报信息
### 考试信息
diff --git a/lib/router.js b/lib/router.js
index 939441677d..66f035e65a 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -2863,7 +2863,7 @@ router.get('/law/jctd', lazyloadRouteHandler('./routes/law/jctd'));
router.get('/samsungmembers/latest', lazyloadRouteHandler('./routes/samsungmembers/latest'));
// 东莞教研网
-router.get('/dgjyw/:type', lazyloadRouteHandler('./routes/dgjyw/index'));
+// router.get('/dgjyw/:type', lazyloadRouteHandler('./routes/dgjyw/index'));
// 中国信息通信研究院
router.get('/gov/caict/bps', lazyloadRouteHandler('./routes/gov/caict/bps'));
diff --git a/lib/routes/dgjyw/index.js b/lib/routes/dgjyw/index.js
deleted file mode 100644
index 5de83002b7..0000000000
--- a/lib/routes/dgjyw/index.js
+++ /dev/null
@@ -1,66 +0,0 @@
-const url = require('url');
-const got = require('@/utils/got');
-const cheerio = require('cheerio');
-
-const rootUrl = 'http://zxls.dgjyw.com/';
-
-const config = {
- news: {
- link: '/node/57620',
- title: '动态',
- },
- announcement: {
- link: '/node/57725',
- title: '公示',
- },
- notice: {
- link: '/node/57621',
- title: '通知',
- },
-};
-
-module.exports = async (ctx) => {
- const cfg = config[ctx.params.type];
- if (!cfg) {
- throw Error('Bad category. See docs');
- }
-
- const currentUrl = url.resolve(rootUrl, cfg.link);
- const response = await got({
- method: 'get',
- url: currentUrl,
- });
- const $ = cheerio.load(response.data);
- const list = $('ul.list-ul')
- .eq(2)
- .find('li')
- .slice(0, 20)
- .map((_, item) => {
- item = $(item);
- const a = item.find('a[title]');
- return {
- title: a.text(),
- link: a.attr('href'),
- pubDate: new Date(new Date().getFullYear().toString().substr(0, 2) + item.find('span').text()).toUTCString(),
- };
- })
- .get();
-
- const items = await Promise.all(
- list.map((item) =>
- ctx.cache.tryGet(item.link, async () => {
- const res = await got({ method: 'get', url: item.link });
- const content = cheerio.load(res.data);
-
- item.description = content('div.text').html();
- return item;
- })
- )
- );
-
- ctx.state.data = {
- title: '东莞教研网 - ' + cfg.title,
- link: rootUrl,
- item: items,
- };
-};
diff --git a/lib/v2/dgjyw/index.js b/lib/v2/dgjyw/index.js
new file mode 100644
index 0000000000..4a2f18df27
--- /dev/null
+++ b/lib/v2/dgjyw/index.js
@@ -0,0 +1,67 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const timezone = require('@/utils/timezone');
+const { parseDate } = require('@/utils/parse-date');
+
+module.exports = async (ctx) => {
+ const params = ctx.path;
+
+ const rootUrl = 'https://www.dgjyw.com';
+ const currentUrl = `${rootUrl}${params === '/' ? '/tz' : params}.htm`;
+
+ const response = await got({
+ method: 'get',
+ url: currentUrl,
+ https: {
+ rejectUnauthorized: false,
+ },
+ });
+
+ const $ = cheerio.load(response.data);
+
+ let items = $('div.text-list ul li a')
+ .toArray()
+ .map((item) => {
+ item = $(item);
+
+ const link = item.attr('href');
+
+ return {
+ title: item.text(),
+ link: `${/^http/.test(link) ? '' : `${rootUrl}/`}${link}`,
+ pubDate: parseDate(item.next().text()),
+ };
+ });
+
+ items = await Promise.all(
+ items.map((item) =>
+ ctx.cache.tryGet(item.link, async () => {
+ if (/dgjyw\.com/.test(item.link)) {
+ const detailResponse = await got({
+ method: 'get',
+ url: item.link,
+ https: {
+ rejectUnauthorized: false,
+ },
+ });
+
+ const content = cheerio.load(detailResponse.data);
+
+ content('.cont-tit').remove();
+ content('.art-body').html(content('.v_news_content').html());
+
+ item.pubDate = timezone(parseDate(content('meta[name="PubDate"]').attr('content')), +8);
+ item.description = content('form[name="_newscontent_fromname"]').html();
+ }
+
+ return item;
+ })
+ )
+ );
+
+ ctx.state.data = {
+ title: $('title').text(),
+ link: currentUrl,
+ item: items,
+ };
+};
diff --git a/lib/v2/dgjyw/maintainer.js b/lib/v2/dgjyw/maintainer.js
new file mode 100644
index 0000000000..81eb78d732
--- /dev/null
+++ b/lib/v2/dgjyw/maintainer.js
@@ -0,0 +1,3 @@
+module.exports = {
+ '/:category?': ['nczitzk'],
+};
diff --git a/lib/v2/dgjyw/radar.js b/lib/v2/dgjyw/radar.js
new file mode 100644
index 0000000000..b9ff1b1802
--- /dev/null
+++ b/lib/v2/dgjyw/radar.js
@@ -0,0 +1,13 @@
+module.exports = {
+ 'dgjyw.com': {
+ _name: '东莞教研网',
+ '.': [
+ {
+ title: '分类',
+ docs: 'https://docs.rsshub.app/other.html#dong-guan-jia-yan-wang-fen-lei',
+ source: ['/'],
+ target: (params, url) => `/dgjyw/${new URL(url).toString().match(/dgjyw\.com\/(.*)\.htm$/)[1]}`,
+ },
+ ],
+ },
+};
diff --git a/lib/v2/dgjyw/router.js b/lib/v2/dgjyw/router.js
new file mode 100644
index 0000000000..28f05970b9
--- /dev/null
+++ b/lib/v2/dgjyw/router.js
@@ -0,0 +1,3 @@
+module.exports = function (router) {
+ router.get(/([\w\d/-]+)?/, require('./index'));
+};