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.
Merge pull request #97 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
49 changed files
with
806 additions
and
106 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module.exports = { | ||
'/topic/:topic': ['TonyRL'], | ||
'/topic_list': ['TonyRL'], | ||
'/:category?': ['TonyRL'], | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module.exports = function (router) { | ||
module.exports = (router) => { | ||
router.get('/topic/:topic', require('./topic')); | ||
router.get('/topic_list', require('./topic_list')); | ||
router.get('/:category?', 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,31 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { baseUrl, parseArticle } = require('./utils'); | ||
|
||
module.exports = async (ctx) => { | ||
const { topic } = ctx.params; | ||
const link = `${baseUrl}/topic/${topic}`; | ||
const response = await got(link); | ||
|
||
const $ = cheerio.load(response.data); | ||
const ldJson = JSON.parse($('script[type="application/ld+json"]').text()); | ||
const list = $('.ag-post-item__link') | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
return { | ||
title: item.text().trim(), | ||
link: `${baseUrl}${item.attr('href')}`, | ||
}; | ||
}); | ||
|
||
const items = await Promise.all(list.map((item) => ctx.cache.tryGet(item.link, () => parseArticle(item)))); | ||
|
||
ctx.state.data = { | ||
title: $('head title').text().trim(), | ||
link, | ||
description: ldJson['@graph'][0].description, | ||
item: items, | ||
language: $('html').attr('lang'), | ||
}; | ||
}; |
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,139 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const timezone = require('@/utils/timezone'); | ||
const path = require('path'); | ||
const { art } = require('@/utils/render'); | ||
|
||
const urlMap = { | ||
srac: { | ||
baseUrl: 'https://china.hket.com', | ||
}, | ||
sran: { | ||
baseUrl: 'https://inews.hket.com', | ||
}, | ||
srat: { | ||
baseUrl: 'https://topick.hket.com', | ||
}, | ||
sraw: { | ||
baseUrl: 'https://wealth.hket.com', | ||
}, | ||
}; | ||
|
||
module.exports = async (ctx) => { | ||
const { category = 'sran001' } = ctx.params; | ||
const baseUrl = urlMap[category.substring(0, 4)].baseUrl; | ||
|
||
const { data: response } = await got(`${baseUrl}/${category}`); | ||
|
||
const $ = cheerio.load(response); | ||
|
||
const list = $('div.listing-title > a') | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
return { | ||
title: item.text().trim(), | ||
link: item.attr('href').startsWith('/') | ||
? // remove tracking parameters | ||
baseUrl + item.attr('href').split('?')[0].substring(0, item.attr('href').lastIndexOf('/')) | ||
: item.attr('href').split('?')[0].substring(0, item.attr('href').lastIndexOf('/')), | ||
}; | ||
}); | ||
|
||
const items = await Promise.all( | ||
list.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
if (item.link.startsWith('https://invest.hket.com/') || item.link.startsWith('https://ps.hket.com/')) { | ||
let data; | ||
|
||
if (item.link.startsWith('https://invest.hket.com/')) { | ||
data = await got.post('https://invest.hket.com/content-api-middleware/content', { | ||
headers: { | ||
referer: item.link, | ||
}, | ||
json: { | ||
id: item.link.split('/').pop(), | ||
channel: 'invest', | ||
}, | ||
}); | ||
} else { | ||
data = await got('https://data02.hket.com/content', { | ||
headers: { | ||
referer: item.link, | ||
}, | ||
searchParams: { | ||
id: item.link.split('/').pop(), | ||
channel: 'epc', | ||
}, | ||
}); | ||
} | ||
data = data.data; | ||
|
||
item.pubDate = timezone(parseDate(data.displayDate), +8); | ||
item.updated = timezone(parseDate(data.lastModifiedDate), +8); | ||
item.author = data.authors?.map((e) => e.name).join(', '); | ||
item.description = data.content.full || data.content.partial; | ||
item.category = data.contentTags?.map((e) => e.name); | ||
|
||
return item; | ||
} | ||
|
||
const { data: response } = await got(item.link); | ||
const $ = cheerio.load(response); | ||
|
||
item.category = $('.contentTags-container > .hotkey-container-wrapper > .hotkey-container > a') | ||
.toArray() | ||
.map((e) => $(e).text().trim()); | ||
|
||
// remove unwanted elements | ||
$('source').remove(); | ||
$('p.article-detail_caption, .article-extend-button, span.click-to-enlarge').remove(); | ||
$('.loyalty-promotion-container, .relatedContents-container, .article-details-center-sharing-btn, .article-detail_login').remove(); | ||
$('.gallery-related-container, .contentTags-container').remove(); | ||
$('.listing-widget-126, div.template-default.hket-row.no-padding.detail-widget').remove(); | ||
|
||
// remove ads | ||
$('.ad_MobileMain, .adunit, .native-ad').remove(); | ||
|
||
$('span').each((_, e) => { | ||
if ($(e).text().startsWith('+')) { | ||
$(e).remove(); | ||
} | ||
}); | ||
|
||
// fix lazyload image and caption | ||
$('img').each((_, e) => { | ||
e = $(e); | ||
e.replaceWith( | ||
art(path.join(__dirname, 'templates/image.art'), { | ||
alt: e.attr('data-alt'), | ||
src: e.attr('data-src') ?? e.attr('src'), | ||
}) | ||
); | ||
}); | ||
|
||
item.description = $('div.article-detail-body-container').html(); | ||
item.pubDate = timezone(parseDate($('.article-details-info-container_date, .publish-date-time').text().trim()), +8); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: $('head meta[name=title]').attr('content').trim(), | ||
link: baseUrl + '/' + category, | ||
description: $('head meta[name=description]').attr('content').trim(), | ||
item: items, | ||
language: 'zh-hk', | ||
}; | ||
|
||
ctx.state.json = { | ||
title: $('head meta[name=title]').attr('content').trim(), | ||
link: baseUrl + '/' + category, | ||
description: $('head meta[name=description]').attr('content').trim(), | ||
item: items, | ||
language: 'zh-hk', | ||
}; | ||
}; |
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 = { | ||
'/:category?': ['TonyRL'], | ||
}; |
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 @@ | ||
module.exports = { | ||
'hket.com': { | ||
_name: '香港经济日报', | ||
china: [ | ||
{ | ||
title: '新闻', | ||
docs: 'https://docs.rsshub.app/routes/traditional-media#xiang-gang-jing-ji-ri-bao', | ||
source: ['/:category/*'], | ||
target: '/hket/:category', | ||
}, | ||
], | ||
inews: [ | ||
{ | ||
title: '新闻', | ||
docs: 'https://docs.rsshub.app/routes/traditional-media#xiang-gang-jing-ji-ri-bao', | ||
source: ['/:category/*'], | ||
target: '/hket/:category', | ||
}, | ||
], | ||
topick: [ | ||
{ | ||
title: '新闻', | ||
docs: 'https://docs.rsshub.app/routes/traditional-media#xiang-gang-jing-ji-ri-bao', | ||
source: ['/:category/*'], | ||
target: '/hket/:category', | ||
}, | ||
], | ||
wealth: [ | ||
{ | ||
title: '新闻', | ||
docs: 'https://docs.rsshub.app/routes/traditional-media#xiang-gang-jing-ji-ri-bao', | ||
source: ['/:category/*'], | ||
target: '/hket/:category', | ||
}, | ||
], | ||
www: [ | ||
{ | ||
title: '新闻', | ||
docs: 'https://docs.rsshub.app/routes/traditional-media#xiang-gang-jing-ji-ri-bao', | ||
source: ['/'], | ||
target: '/hket', | ||
}, | ||
], | ||
}, | ||
}; |
Oops, something went wrong.