mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: show top 5 trending plugins in new tab in Extend > Plugins
This commit is contained in:
@@ -8,15 +8,25 @@ const meta = require('../../meta');
|
||||
const pluginsController = module.exports;
|
||||
|
||||
pluginsController.get = async function (req, res) {
|
||||
const [compatible, all] = await Promise.all([
|
||||
const [compatible, all, trending] = await Promise.all([
|
||||
getCompatiblePlugins(),
|
||||
getAllPlugins(),
|
||||
plugins.listTrending(),
|
||||
]);
|
||||
|
||||
const compatiblePkgNames = compatible.map(pkgData => pkgData.name);
|
||||
const installedPlugins = compatible.filter(plugin => plugin && plugin.installed);
|
||||
const activePlugins = all.filter(plugin => plugin && plugin.installed && plugin.active);
|
||||
|
||||
const trendingScores = trending.reduce((memo, cur) => {
|
||||
memo[cur.label] = cur.value;
|
||||
return memo;
|
||||
}, {});
|
||||
const trendingPlugins = all.filter(plugin => plugin && Object.keys(trendingScores).includes(plugin.id)).sort((a, b) => trendingScores[b.id] - trendingScores[a.id]).map((plugin) => {
|
||||
plugin.downloads = trendingScores[plugin.id];
|
||||
return plugin;
|
||||
});
|
||||
|
||||
res.render('admin/extend/plugins', {
|
||||
installed: installedPlugins,
|
||||
installedCount: installedPlugins.length,
|
||||
@@ -34,6 +44,7 @@ pluginsController.get = async function (req, res) {
|
||||
incompatible: all.filter(function (plugin) {
|
||||
return !compatiblePkgNames.includes(plugin.name);
|
||||
}),
|
||||
trending: trendingPlugins,
|
||||
submitPluginUsage: meta.config.submitPluginUsage,
|
||||
version: nconf.get('version'),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user