forked from chengxuanying/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.
Co-authored-by: NeverBehave <[email protected]>
- Loading branch information
1 parent
472b293
commit 9e5baaa
Showing
3 changed files
with
54 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,45 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
module.exports = async (ctx) => { | ||
const { type } = ctx.params; | ||
const baseURL = 'https://www.tongli.com.tw/'; | ||
const link = `${baseURL}TNews_List.aspx?Type=${type}&Page=1`; | ||
const res = await got.get(link); | ||
const $ = cheerio.load(res.data); | ||
const title = $('entry_title .n1').text(); | ||
const _list = $('.news_list ul li') | ||
.map(function () { | ||
let link = $(this).find('.title a').attr('href'); | ||
/^https?:\/\//.test(link) || (link = baseURL + link); | ||
return { | ||
title: $(this).find('.title a').text(), | ||
link, | ||
pubDate: new Date($(this).find('.date').text()), | ||
}; | ||
}) | ||
.get(); | ||
const list = await Promise.all( | ||
_list.map(async (item) => { | ||
const { title, link, pubDate } = item; | ||
const description = await ctx.cache.tryGet(link, async () => { | ||
const res = await got.get(link); | ||
const $ = cheerio.load(res.data); | ||
if (/^https:\/\/tonglinv\.pixnet\.net/.test(link)) { | ||
return $('.article-content-inner').html(); | ||
} else if (/^https?:\/\/blog\.xuite\.net\//.test(link)) { | ||
return $('#content_all').html(); | ||
} else if (/TNews_View\.aspx/.test(link)) { | ||
return $('#ContentPlaceHolder1_TNewsContent').html(); | ||
} else { | ||
return ''; | ||
} | ||
}); | ||
return Promise.resolve({ title, link, description, pubDate }); | ||
}) | ||
); | ||
ctx.state.data = { | ||
title, | ||
link, | ||
item: list, | ||
}; | ||
}; |