| 1 | export function splitRootDirFiles(dir: MediaFile, hasCotyledonCookie: boolean) { |
| 2 | const children = dir.getPublicChildren(); |
| 3 | let readme: MediaFile | null = null; |
| 4 | |
| 5 | const groups = { |
| 6 | // years 2025 and onwards |
| 7 | years: [] as MediaFile[], |
| 8 | // named categories |
| 9 | categories: [] as MediaFile[], |
| 10 | // years 2017 to 2024 |
| 11 | cotyledon: [] as MediaFile[], |
| 12 | }; |
| 13 | const colorMap: Record<string, string> = { |
| 14 | years: "#a2ff91", |
| 15 | categories: "#9c91ff", |
| 16 | cotyledon: "#ff91ca", |
| 17 | }; |
| 18 | for (const child of children) { |
| 19 | const basename = child.basename; |
| 20 | if (basename === "readme.txt") { |
| 21 | readme = child; |
| 22 | continue; |
| 23 | } |
| 24 | |
| 25 | const year = basename.match(/^(\d{4})/); |
| 26 | if (year) { |
| 27 | const n = parseInt(year[1]); |
| 28 | if (n >= 2025) { |
| 29 | groups.years.push(child); |
| 30 | } else { |
| 31 | groups.cotyledon.push(child); |
| 32 | } |
| 33 | } else { |
| 34 | groups.categories.push(child); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | let sections = []; |
| 39 | for (const [key, files] of Object.entries(groups)) { |
| 40 | if (key === "cotyledon" && !hasCotyledonCookie) { |
| 41 | continue; |
| 42 | } |
| 43 | if (key === "years" || key === "cotyledon") { |
| 44 | files.sort((a, b) => { |
| 45 | return b.basename.localeCompare(a.basename); |
| 46 | }); |
| 47 | } else { |
| 48 | files.sort((a, b) => { |
| 49 | return a.basename.localeCompare(b.basename); |
| 50 | }); |
| 51 | } |
| 52 | sections.push({ key, titleColor: colorMap[key], files }); |
| 53 | } |
| 54 | |
| 55 | return { readme, sections }; |
| 56 | } |
| 57 | |
| 58 | import { MediaFile } from "./models/MediaFile.ts"; |