66const fs = require ( 'fs' ) . promises ;
77const path = require ( 'path' ) ;
88
9- // fetch 请求改接口: https://oss.x-lab.info/open_leaderboard/activity/company /chinese/20247 .json
9+ // fetch 请求接口: https://oss.x-lab.info/open_leaderboard/open_rank/actor /chinese/2024 .json
1010// 然后将数据写入到 source/_data/rankingList.json 中
1111async function fetchXlab ( year ) {
1212 const response = await fetch ( `https://oss.x-lab.info/open_leaderboard/open_rank/actor/chinese/${ year } .json` ) ;
@@ -41,7 +41,10 @@ async function writeRankingData(data) {
4141
4242// 主函数
4343async function main ( ) {
44- const year = new Date ( ) . getFullYear ( ) ;
44+ const date = new Date ( ) ;
45+ // 在每个月的 1 号获取上个月的年份
46+ date . setMonth ( date . getMonth ( ) - 1 ) ;
47+ const year = date . getFullYear ( ) ;
4548 console . log ( year ) ;
4649 const rankingData = await readRankingData ( ) ;
4750 const xlabData = await fetchXlab ( year ) ;
@@ -54,7 +57,7 @@ async function main() {
5457 const yearIndex = rankingData . findIndex ( v => Number ( v . year ) === year ) ;
5558 // 获取当前时间戳
5659 const update = `${ new Date ( ) . getFullYear ( ) } 年 ${ new Date ( ) . getMonth ( ) + 1 } 月` ;
57- const ranking = {
60+ const ranking = {
5861 year,
5962 update : update ,
6063 annualRanking : xlabData ,
@@ -67,7 +70,7 @@ async function main() {
6770 rankingData . push ( ranking ) ;
6871 }
6972
70- console . log ( `Update ${ year } ranking data successfully!` , yearIndex , ranking ) ;
73+ console . log ( `Update ${ year } ranking data successfully!` , yearIndex , ranking ) ;
7174
7275 // 写入 JSON 数据
7376 await writeRankingData ( rankingData ) ;
0 commit comments