2025-07-07 20:58:02 -07:00
|
|
|
export function splitRootDirFiles(dir: MediaFile, hasCotyledonCookie: boolean) {
|
|
|
|
const children = dir.getPublicChildren();
|
|
|
|
let readme: MediaFile | null = null;
|
|
|
|
|
|
|
|
const groups = {
|
|
|
|
// years 2025 and onwards
|
|
|
|
years: [] as MediaFile[],
|
|
|
|
// named categories
|
|
|
|
categories: [] as MediaFile[],
|
|
|
|
// years 2017 to 2024
|
|
|
|
cotyledon: [] as MediaFile[],
|
|
|
|
};
|
|
|
|
const colorMap: Record<string, string> = {
|
|
|
|
years: "#a2ff91",
|
|
|
|
categories: "#9c91ff",
|
|
|
|
cotyledon: "#ff91ca",
|
|
|
|
};
|
|
|
|
for (const child of children) {
|
|
|
|
const basename = child.basename;
|
|
|
|
if (basename === "readme.txt") {
|
|
|
|
readme = child;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const year = basename.match(/^(\d{4})/);
|
|
|
|
if (year) {
|
|
|
|
const n = parseInt(year[1]);
|
|
|
|
if (n >= 2025) {
|
|
|
|
groups.years.push(child);
|
|
|
|
} else {
|
|
|
|
groups.cotyledon.push(child);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
groups.categories.push(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let sections = [];
|
|
|
|
for (const [key, files] of Object.entries(groups)) {
|
|
|
|
if (key === "cotyledon" && !hasCotyledonCookie) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (key === "years" || key === "cotyledon") {
|
|
|
|
files.sort((a, b) => {
|
|
|
|
return b.basename.localeCompare(a.basename);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
files.sort((a, b) => {
|
|
|
|
return a.basename.localeCompare(b.basename);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
sections.push({ key, titleColor: colorMap[key], files });
|
|
|
|
}
|
|
|
|
|
|
|
|
return { readme, sections };
|
|
|
|
}
|
|
|
|
|
|
|
|
import { MediaFile } from "./models/MediaFile.ts";
|