feat(route): npm (#9437)

This commit is contained in:
Fatpandac 2022-04-01 18:39:08 +08:00 committed by GitHub
parent 457e8f8a41
commit bb3924cac3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 86 additions and 0 deletions

View File

@ -269,6 +269,12 @@ Refer to [#minecraft](/en/game.html#minecraft)
见 [#nintendo](/game.html#nintendo)
## NPM
### Package
<RouteEn author="Fatpandac" example="/npm/package/rsshub" path="/npm/package/:name" :paramsDesc="['Package name']"/>
## Nvidia Web Driver
### Changelog

View File

@ -318,6 +318,12 @@ pageClass: routes
见 [#nintendo](/game.html#nintendo)
## NPM
### 包
<Route author="Fatpandac" example="/npm/package/rsshub" path="/npm/package/:name" :paramsDesc="['包名']"/>
## Nvidia Web Driver
### 更新日志

3
lib/v2/npm/maintainer.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
'/package/:name': ['Fatpandac'],
};

45
lib/v2/npm/package.js Normal file
View File

@ -0,0 +1,45 @@
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const name = ctx.params.name;
const packageDownloadLastMonthAPI = `https://api.npmjs.org/downloads/point/last-month/${name}`; // 按月统计
const packageDownloadLastWeekAPI = `https://api.npmjs.org/downloads/point/last-week/${name}`; // 按周统计
const packageDownloadLastDayAPI = `https://api.npmjs.org/downloads/point/last-day/${name}`; // 按天统计
const packageVersionAPI = `https://registry.npmjs.org/${name}`; // 包基本信息
const downloadCountLastMonthRes = await got(packageDownloadLastMonthAPI).json();
const downloadCountLastWeekRes = await got(packageDownloadLastWeekAPI).json();
const downloadCountLastDayRes = await got(packageDownloadLastDayAPI).json();
const packageVersionRes = await got(packageVersionAPI).json();
const packageVersion = packageVersionRes.time;
const packageVersionList = [];
for (const key in packageVersion) {
packageVersionList.push({
version: key,
time: packageVersion[key],
});
}
packageVersionList.reverse();
ctx.state.data = {
title: `${name} - npm`,
link: `https://www.npmjs.com/package/${name}`,
description: `${name} - npm`,
item: [
{
title: `${name} - npm`,
description: art(path.join(__dirname, 'templates/package.art'), {
packageDownloadCountLastMonth: downloadCountLastMonthRes.downloads,
packageDownloadCountLastWeek: downloadCountLastWeekRes.downloads,
packageDownloadCountLastDay: downloadCountLastDayRes.downloads,
packageVersion: packageVersionList,
}),
link: `https://www.npmjs.com/package/${name}`,
guid: `https://www.npmjs.com/package/${name}${packageVersion.modified}`,
},
],
};
};

13
lib/v2/npm/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'npmjs.com': {
_name: 'npm',
'.': [
{
title: '包',
docs: 'https://docs.rsshub.app/program-update.html#npm',
source: ['/package/:name'],
target: '/npm/package/:name',
},
],
},
};

3
lib/v2/npm/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/package/:name', require('./package'));
};

View File

@ -0,0 +1,10 @@
<h3>Download</h3>
<p>Last Day: {{packageDownloadCountLastDay}}</p>
<p>Last week: {{packageDownloadCountLastWeek}}</p>
<p>Last month: {{packageDownloadCountLastMonth}}</p>
<hr/>
<h3>Version</h3>
{{ each packageVersion}}
<p>{{$value.version}}: {{$value.time}}</p>
{{/each}}