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={}";
|
|
|
|
|
2023-11-08 00:49:43 +00:00
|
|
|
// todo: cache this somehow?
|
2023-11-07 23:05:11 +00:00
|
|
|
async function getTopPlayers() {
|
|
|
|
console.log("Fetching top players...");
|
|
|
|
const players = [];
|
2023-11-08 00:49:43 +00:00
|
|
|
const pagesToFetch = 30;
|
2023-11-07 23:05:11 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-11-07 23:58:24 +00:00
|
|
|
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}`,
|
2023-11-07 23:58:24 +00:00
|
|
|
...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}`,
|
2023-11-07 23:58:24 +00:00
|
|
|
...additionalData,
|
2023-11-07 23:05:11 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-08 00:49:43 +00:00
|
|
|
const sortTypes = ["top", "recent"];
|
|
|
|
|
2023-11-07 23:05:11 +00:00
|
|
|
// Add top players
|
|
|
|
const players = await getTopPlayers();
|
2023-11-08 00:49:43 +00:00
|
|
|
for (const sortType of sortTypes) {
|
|
|
|
for (const player of players) {
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
|
paths.push({
|
|
|
|
loc: `/player/${player.id}/${sortType}/${i + 1}`,
|
|
|
|
...additionalData,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2023-11-07 23:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return paths;
|
|
|
|
},
|
|
|
|
};
|