feat(route): npm (#9437)
This commit is contained in:
parent
457e8f8a41
commit
bb3924cac3
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
### 更新日志
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/package/:name': ['Fatpandac'],
|
||||
};
|
||||
|
|
@ -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}`,
|
||||
},
|
||||
],
|
||||
};
|
||||
};
|
||||
|
|
@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/package/:name', require('./package'));
|
||||
};
|
||||
|
|
@ -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}}
|
||||
|
||||
Loading…
Reference in New Issue