Non-official site for The Life Series Minecraft hardcore survival multiplayer series housing every video www.life-series.online

Add redirects from old number based season paths to new paths (#71)

authored by ghustvn.com and committed by

GitHub a40627df cbefc912

+52
+52
astro.config.mjs
··· 1 1 // @ts-check 2 + import { readFileSync } from 'node:fs'; 2 3 import sitemap from '@astrojs/sitemap'; 3 4 import { defineConfig, fontProviders } from 'astro/config'; 4 5 import icon from 'astro-icon'; 5 6 import og from 'astro-og'; 6 7 8 + /** 9 + * @typedef {object} Season 10 + * @property {string} id 11 + * @property {number | undefined} sessionCount 12 + * @property {Record<string, Array<unknown>>} videos 13 + */ 14 + 15 + const seasonIdByLegacyNumber = { 16 + 1: '3rd-life', 17 + 2: 'last-life', 18 + 3: 'double-life', 19 + 4: 'limited-life', 20 + 5: 'secret-life', 21 + 6: 'wild-life', 22 + 7: 'past-life', 23 + }; 24 + 25 + /** @type {Season[]} */ 26 + const seasons = JSON.parse( 27 + readFileSync(new URL('./src/data/seasons.json', import.meta.url), 'utf8'), 28 + ); 29 + /** @type {Map<string, Season>} */ 30 + const seasonsById = new Map(seasons.map((season) => [season.id, season])); 31 + 32 + /** @type {Record<string, string>} */ 33 + const redirects = {}; 34 + 35 + for (const [legacySeasonNumber, seasonId] of Object.entries( 36 + seasonIdByLegacyNumber, 37 + )) { 38 + const season = seasonsById.get(seasonId); 39 + if (!season) continue; 40 + 41 + redirects[`/seasons/${legacySeasonNumber}`] = `/seasons/${seasonId}`; 42 + 43 + for (const memberName of Object.keys(season.videos)) { 44 + redirects[`/seasons/${legacySeasonNumber}/${memberName}`] = 45 + `/seasons/${seasonId}/${memberName}`; 46 + } 47 + 48 + for ( 49 + let sessionNumber = 1; 50 + sessionNumber <= (season.sessionCount ?? 0); 51 + sessionNumber += 1 52 + ) { 53 + redirects[`/seasons/${legacySeasonNumber}/sessions/${sessionNumber}`] = 54 + `/seasons/${seasonId}/sessions/${sessionNumber}`; 55 + } 56 + } 57 + 7 58 export default defineConfig({ 8 59 site: 'https://www.life-series.online', 9 60 trailingSlash: 'never', ··· 24 75 }, 25 76 ], 26 77 }, 78 + redirects, 27 79 });