mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-04 02:58:08 +08:00
fix(route): add Open Graph image to GitHub trending (#10189)
* fix(route): add Open Graph image to GitHub trending Adds Open Graph image for each repository to the GitHub trending feed. * chore(route): address pull request feedback - Refactors page request call to make it more terse - Adds art template for trending description - Updates maintainers for '/trending/:since/:language?/:spoken_language?'
This commit is contained in:
@@ -10,6 +10,6 @@ module.exports = {
|
|||||||
'/starred_repos/:user': ['LanceZhu'],
|
'/starred_repos/:user': ['LanceZhu'],
|
||||||
'/stars/:user/:repo': ['HenryQW'],
|
'/stars/:user/:repo': ['HenryQW'],
|
||||||
'/topics/:name/:qs?': ['queensferryme'],
|
'/topics/:name/:qs?': ['queensferryme'],
|
||||||
'/trending/:since/:language?/:spoken_language?': ['DIYgod'],
|
'/trending/:since/:language?/:spoken_language?': ['DIYgod', 'jameschensmith'],
|
||||||
'/user/followers/:user': ['HenryQW'],
|
'/user/followers/:user': ['HenryQW'],
|
||||||
};
|
};
|
||||||
|
|||||||
5
lib/v2/github/templates/trending-description.art
Normal file
5
lib/v2/github/templates/trending-description.art
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<img src="{{@ cover }}">
|
||||||
|
<br>{{@ desc }}
|
||||||
|
<br><br>Language: {{@ lang }}
|
||||||
|
<br>Stars: {{@ stars }}
|
||||||
|
<br>Forks: {{@ forks }}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
const got = require('@/utils/got');
|
const got = require('@/utils/got');
|
||||||
|
const { art } = require('@/utils/render');
|
||||||
const cheerio = require('cheerio');
|
const cheerio = require('cheerio');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = async (ctx) => {
|
module.exports = async (ctx) => {
|
||||||
const since = ctx.params.since;
|
const since = ctx.params.since;
|
||||||
@@ -20,24 +22,38 @@ module.exports = async (ctx) => {
|
|||||||
const $ = cheerio.load(data);
|
const $ = cheerio.load(data);
|
||||||
const list = $('article');
|
const list = $('article');
|
||||||
|
|
||||||
|
const items = await Promise.all(
|
||||||
|
list.map((_, item) => {
|
||||||
|
item = $(item);
|
||||||
|
const endpoint = item.find('h1 a').attr('href');
|
||||||
|
const link = `https://github.com${endpoint}`;
|
||||||
|
return ctx.cache.tryGet(`github:trending:${endpoint}`, async () => {
|
||||||
|
const response = await got(link);
|
||||||
|
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
const cover = $('meta[property="og:image"]');
|
||||||
|
|
||||||
|
const single = {
|
||||||
|
title: item.find('h1').text(),
|
||||||
|
author: item.find('h1').text().split('/')[0].trim(),
|
||||||
|
description: art(path.join(__dirname, 'templates/trending-description.art'), {
|
||||||
|
cover: cover.attr('content'),
|
||||||
|
desc: item.find('p').text(),
|
||||||
|
lang: item.find('span[itemprop="programmingLanguage"]').text() || 'Unknown',
|
||||||
|
stars: item.find('.Link--muted').eq(0).text().trim(),
|
||||||
|
forks: item.find('.Link--muted').eq(1).text().trim(),
|
||||||
|
}),
|
||||||
|
link,
|
||||||
|
};
|
||||||
|
|
||||||
|
return single;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
ctx.state.data = {
|
ctx.state.data = {
|
||||||
title: $('title').text(),
|
title: $('title').text(),
|
||||||
link: url,
|
link: url,
|
||||||
item:
|
item: items,
|
||||||
list &&
|
|
||||||
list
|
|
||||||
.map((_, item) => {
|
|
||||||
item = $(item);
|
|
||||||
return {
|
|
||||||
title: item.find('h1').text(),
|
|
||||||
author: item.find('h1').text().split('/')[0].trim(),
|
|
||||||
description: `${item.find('.pr-4').text()}<br>
|
|
||||||
<br>Language: ${item.find('span[itemprop="programmingLanguage"]').text() ?? 'unknown'}
|
|
||||||
<br>Star: ${item.find('.Link--muted').eq(0).text().trim()}
|
|
||||||
<br>Fork: ${item.find('.Link--muted').eq(1).text().trim()}`,
|
|
||||||
link: `https://github.com${item.find('h1 a').attr('href')}`,
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.get(),
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user