forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add 遠見 gvm.com.tw (DIYgod#6282)
- Loading branch information
Showing
3 changed files
with
107 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
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,95 @@ | ||
const got = require('got'); | ||
const cheerio = require('cheerio'); | ||
|
||
module.exports = async (ctx) => { | ||
const category = ctx.params.category || 'newest'; | ||
let suffix = '/newest'; | ||
|
||
const options = { | ||
newest: '最新文章', | ||
recommend: '你可能會喜歡', | ||
opinion: '名家專欄', | ||
topic: '專題', | ||
news: '時事熱點', | ||
politics: '政治', | ||
society: '社會', | ||
figure: '人物報導', | ||
world: '國際', | ||
world_focus: '全球焦點', | ||
cross_strait_politics: '兩岸', | ||
money: '金融理財', | ||
investment: '投資理財', | ||
insurance: '保險規劃', | ||
retire: '退休理財', | ||
fintech: '金融Fintech', | ||
real_estate: '房地產', | ||
economy: '總體經濟', | ||
tech: '科技', | ||
tech_trend: '科技趨勢', | ||
energy: '能源', | ||
business: '產經', | ||
industry: '傳產', | ||
service: '消費服務', | ||
medical: '生技醫藥', | ||
family_business_succession: '傳承轉型', | ||
startup: '創業新創', | ||
management: '管理', | ||
agriculture: '農業', | ||
education: '教育', | ||
higher_education: '高教', | ||
technological: '技職', | ||
parent: '親子教育', | ||
world_education: '國際文教', | ||
sports: '體育', | ||
life: '好享生活', | ||
art: '時尚設計', | ||
self_growth: '心靈成長', | ||
film: '藝文影視', | ||
travel: '旅遊', | ||
environment: '環境生態', | ||
health: '健康', | ||
food: '美食', | ||
career: '職場生涯', | ||
survey: '調查', | ||
county: '縣市', | ||
csr: 'CSR', | ||
}; | ||
|
||
if (category !== 'newest' && category !== 'recommend') { | ||
suffix = `/category/${category}`; | ||
} | ||
|
||
const response = await got({ | ||
method: 'get', | ||
url: 'https://www.gvm.com.tw' + suffix, | ||
}); | ||
|
||
const $ = cheerio.load(response.body); | ||
|
||
const articles = $('#article_list .article-list-item .article-list-item__intro') | ||
.map((index, ele) => ({ | ||
title: $('a', ele).text(), | ||
link: $('a', ele).attr('href'), | ||
pubDate: new Date($('.time', ele).text()), | ||
author: $('.author', ele).text(), | ||
})) | ||
.get(); | ||
|
||
const item = await Promise.all( | ||
articles.map( | ||
async (item) => | ||
await ctx.cache.tryGet(item.link, async () => { | ||
const res = await got.get(item.link); | ||
const content = cheerio.load(res.body); | ||
item.description = content('.article-content').html(); | ||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: `遠見 - ${options[category]}`, | ||
link: 'https://www.gvm.com.tw' + suffix, | ||
item, | ||
}; | ||
}; |