-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): 增加大数据专家委员会和中国人工智能学会新闻 (#11510)
* 增加大数据专家委员会和中国人工智能学会新闻 * 修复问题 * fix: add docs for `caai` fix: maintainer does not with match with router * fix: add docs for `ccf/tfbd` fix: use raw output for `art-template` fix: standardise use of `got` not using `got()` in one place and `got.get()` in another place * refactor: migrate to v2 ---------
- Loading branch information
Showing
21 changed files
with
252 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const utils = require('./utils'); | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
|
||
module.exports = async (ctx) => { | ||
const base = utils.urlBase(ctx.params.caty); | ||
const res = await got(base); | ||
const info = utils.fetchAllArticles(res.data); | ||
const $ = cheerio.load(res.data); | ||
|
||
const details = await Promise.all(info.map((e) => utils.detailPage(e, ctx.cache))); | ||
|
||
ctx.state.json = { | ||
info, | ||
}; | ||
|
||
ctx.state.data = { | ||
title: '中国人工智能学会 - ' + $('.article-list h1').text(), | ||
link: base, | ||
item: details, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/:caty': ['tudou027'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
'caai.cn': { | ||
_name: '中国人工智能学会', | ||
'.': [ | ||
{ | ||
title: '学会动态', | ||
docs: 'https://docs.rsshub.app/study.html#zhong-guo-ren-gong-zhi-neng-xue-hui', | ||
source: ['/index.php'], | ||
target: (_, url) => `/caai/${url.match(/\/(\d+)\.html/)[1]}`, | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function (router) { | ||
router.get('/:caty', require('./index')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{@ desc }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const cheerio = require('cheerio'); | ||
const got = require('@/utils/got'); | ||
const { art } = require('@/utils/render'); | ||
const path = require('path'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const timezone = require('@/utils/timezone'); | ||
|
||
const base = 'http://www.caai.cn'; | ||
|
||
const urlBase = (caty) => base + `/index.php?s=/home/article/index/id/${caty}.html`; | ||
|
||
const renderDesc = (desc) => | ||
art(path.join(__dirname, 'templates/description.art'), { | ||
desc, | ||
}); | ||
|
||
const detailPage = (e, cache) => | ||
cache.tryGet(e.link, async () => { | ||
const result = await got(e.link); | ||
const $ = cheerio.load(result.data); | ||
e.description = $('div.article').html(); | ||
return e; | ||
}); | ||
|
||
const fetchAllArticles = (data) => { | ||
const $ = cheerio.load(data); | ||
const articles = $('div.article-list > ul > li'); | ||
const info = articles.toArray().map((e) => { | ||
const c = $(e); | ||
const r = { | ||
title: c.find('h3 a[href]').text().trim(), | ||
link: base + c.find('h3 a[href]').attr('href'), | ||
pubDate: timezone(parseDate(c.find('h4').text().trim(), 'YYYY-MM-DD'), +8), | ||
}; | ||
return r; | ||
}); | ||
return info; | ||
}; | ||
|
||
module.exports = { | ||
BASE: base, | ||
urlBase, | ||
fetchAllArticles, | ||
detailPage, | ||
renderDesc, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
'/ccfcv/:channel/:category': ['elxy'], | ||
'/news/:category?': ['nczitzk'], | ||
'/tfbd/:caty/:id': ['tudou027'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module.exports = { | ||
'ccf.org.cn': { | ||
_name: '中国计算机学会', | ||
'.': [ | ||
{ | ||
title: '新闻', | ||
docs: 'https://docs.rsshub.app/study.html#zhong-guo-ji-suan-ji-xue-hui', | ||
source: ['/:category', '/'], | ||
target: '/ccf/news/:category', | ||
}, | ||
], | ||
ccfcv: [ | ||
{ | ||
title: '计算机视觉专委会 - 学术动态 - 学术前沿', | ||
docs: 'https://docs.rsshub.app/study.html#zhong-guo-ji-suan-ji-xue-hui', | ||
source: ['/ccfcv/xsdt/xsqy/'], | ||
target: '/ccf/ccfcv/xsdt/xsqy', | ||
}, | ||
{ | ||
title: '计算机视觉专委会 - 学术动态 - 热点征文', | ||
docs: 'https://docs.rsshub.app/study.html#zhong-guo-ji-suan-ji-xue-hui', | ||
source: ['/ccfcv/xsdt/rdzw/'], | ||
target: '/ccf/ccfcv/xsdt/rdzw', | ||
}, | ||
{ | ||
title: '计算机视觉专委会 - 学术动态 - 学术会议', | ||
docs: 'https://docs.rsshub.app/study.html#zhong-guo-ji-suan-ji-xue-hui', | ||
source: ['/ccfcv/xsdt/xshy/'], | ||
target: '/ccf/ccfcv/xsdt/xshy', | ||
}, | ||
], | ||
tfbd: [ | ||
{ | ||
title: '大数据专家委员会', | ||
docs: 'https://docs.rsshub.app/study.html#zhong-guo-ji-suan-ji-xue-hui', | ||
source: ['/tfbd/:caty/:id', '/'], | ||
target: '/ccf/tfbd/:caty/:id', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = function (router) { | ||
router.get('/ccfcv/:channel/:category', require('./ccfcv/index')); | ||
router.get('/news/:category?', require('./news')); | ||
router.get('/tfbd/:caty/:id', require('./tfbd/index')); | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{@ desc }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const utils = require('./utils'); | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
|
||
module.exports = async (ctx) => { | ||
const base = utils.urlBase(ctx.params.caty, ctx.params.id); | ||
const res = await got(base); | ||
const info = utils.fetchAllArticles(res.data); | ||
const $ = cheerio.load(res.data); | ||
|
||
const details = await Promise.all(info.map((e) => utils.detailPage(e, ctx.cache))); | ||
|
||
ctx.state.json = { | ||
info, | ||
}; | ||
|
||
ctx.state.data = { | ||
title: '大数据专家委员会 - ' + $('.position a:last-child').text(), | ||
link: base, | ||
item: details, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const cheerio = require('cheerio'); | ||
const got = require('@/utils/got'); | ||
const { art } = require('@/utils/render'); | ||
const path = require('path'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const timezone = require('@/utils/timezone'); | ||
|
||
const base = 'http://tfbd.ccf.org.cn'; | ||
|
||
const urlBase = (caty, id) => base + `/tfbd/${caty}/${id}/`; | ||
|
||
const renderDesc = (desc) => | ||
art(path.join(__dirname, '../templates/tfbd/description.art'), { | ||
desc, | ||
}); | ||
|
||
const detailPage = (e, cache) => | ||
cache.tryGet(e.link, async () => { | ||
const result = await got(e.link); | ||
const $ = cheerio.load(result.data); | ||
e.description = $('div.articleCon').html(); | ||
|
||
return e; | ||
}); | ||
|
||
const fetchAllArticles = (data) => { | ||
const $ = cheerio.load(data); | ||
const articles = $('div.file-list div.article-item'); | ||
const info = articles.toArray().map((e) => { | ||
const c = $(e); | ||
const r = { | ||
title: c.find('h3 a[href]').text().trim(), | ||
link: base + c.find('h3 a[href]').attr('href'), | ||
pubDate: timezone(parseDate(c.find('p').text().trim(), 'YYYY-MM-DD'), +8), | ||
}; | ||
return r; | ||
}); | ||
return info; | ||
}; | ||
|
||
module.exports = { | ||
BASE: base, | ||
urlBase, | ||
fetchAllArticles, | ||
detailPage, | ||
renderDesc, | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.