-
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): 中国海洋大学信息科学与工程学部团学工作 (#13699)
* feat(route): 中国海洋大学信息科学与工程学部团学工作 * Update lib/v2/ouc/it-tx.js * Update lib/v2/ouc/it-tx.js ---------
- Loading branch information
1 parent
cbf693e
commit 68e33dc
Showing
5 changed files
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
module.exports = async (ctx) => { | ||
const host = 'https://it.ouc.edu.cn'; | ||
const id = ctx.params.id || 'xwdt'; | ||
const link = `${host}/tx/${id}/list.htm`; | ||
const response = await got(link); | ||
const $ = cheerio.load(response.data); | ||
const typeTitle = $("span.Column_Anchor").text(); | ||
const title = $("li.col_title h2").text(); | ||
|
||
const list = $('ul.wp_article_list li') | ||
.toArray() | ||
.map((e) => { | ||
e = $(e); | ||
const a = e.find('a'); | ||
return { | ||
title: a.attr('title'), | ||
link: new URL(a.attr('href'), host).href, | ||
pubDate: parseDate(e.find('span.Article_PublishDate').text(), 'YYYY-MM-DD'), | ||
}; | ||
}); | ||
|
||
const out = await Promise.all( | ||
list.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const response = await got(item.link); | ||
const $ = cheerio.load(response.data); | ||
item.author = '中国海洋大学信息科学与工程学院'; | ||
item.description = $('.wp_articlecontent').html(); | ||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: `信息科学与工程学院团学工作 - ${typeTitle}${title === typeTitle ? "" : title}`, | ||
description: '中国海洋大学信息科学与工程学院团学工作', | ||
link, | ||
item: out, | ||
}; | ||
}; |
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