scoresaber-reloaded-v2/next-sitemap.config.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-11-07 23:05:11 +00:00
const ssrSettings = require("./src/ssrSettings");
const { getCodeList } = require("country-list");
const SS_API_URL = ssrSettings.proxy + "/https://scoresaber.com/api";
const SS_GET_PLAYERS_URL = SS_API_URL + "/players?page={}";
async function getTopPlayers() {
console.log("Fetching top players...");
const players = [];
const pagesToFetch = 25;
for (let i = 0; i < pagesToFetch; i++) {
console.log(`Fetching page ${i + 1} of ${pagesToFetch}...`);
const response = await fetch(SS_GET_PLAYERS_URL.replace("{}", i));
const data = await response.json();
players.push(...data.players);
}
console.log("Done fetching top players.");
return players;
}
const additionalData = {
priority: 0.5,
changefreq: "monthly",
lastmod: new Date().toISOString(),
};
2023-11-07 23:05:11 +00:00
/** @type {import('next-sitemap').IConfig} */
module.exports = {
siteUrl: ssrSettings.siteUrl,
generateRobotsTxt: true,
additionalPaths: async (config) => {
const paths = [];
// Add the top 50 global ranking pages
for (let i = 0; i < 50; i++) {
paths.push({
loc: `/ranking/global/${i + 1}`,
...additionalData,
2023-11-07 23:05:11 +00:00
});
}
// Add the top 50 pages for all countries
const countries = Object.keys(getCodeList());
for (const country of countries) {
for (let i = 0; i < 50; i++) {
paths.push({
loc: `/ranking/country/${country}/${i + 1}`,
...additionalData,
2023-11-07 23:05:11 +00:00
});
}
}
// Add top players
const players = await getTopPlayers();
for (const player of players) {
paths.push({
loc: `/player/${player.id}/top/1`,
...additionalData,
2023-11-07 23:05:11 +00:00
});
}
return paths;
},
};