// what a repo may cost on disk. pages past it aren't written and those urls get the SPA
// shell, which renders them in the browser like any other route
export const BUDGET_OPTIONS = {
"max-pages": { type: "string", default: "1000" },
"max-repo-bytes": { type: "string", default: String(20 << 20) },
// the whole site: each repo gets at most an even share of it
"max-total-bytes": { type: "string", default: String(2 * 2 ** 30) },
"max-blob-bytes": { type: "string", default: String(128 << 10) },
"max-commits": { type: "string", default: "60" }
};
export const budgetFrom = (opts, repos) => ({
pages: Number(opts["max-pages"]),
bytes: Math.min(Number(opts["max-repo-bytes"]), Math.floor(Number(opts["max-total-bytes"]) / Math.max(1, repos))),
blobBytes: Number(opts["max-blob-bytes"]),
commits: Number(opts["max-commits"])
});
// which pages a repo keeps when it can't keep all: its front pages, then folders and files
// nearest the root, then commits, newest first as the log lists them, then the later pages
// of the lists, nearest first
const RANK = { "": 0, issues: 1, pulls: 1, branches: 1, tags: 1, languages: 1, commits: 2, tree: 3, blob: 4, commit: 5, page: 6 };
export const rankOf = (view, depth) => (RANK[view] ?? 6) * 1000 + Math.min(depth, 999);