Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 2x 21x 6x 8x 10x 4x | import type { ArticleSummary } from "../../shared/types/ArticleSummary";
import type { Category } from "../../shared/types/Category";
import type { SubjectIndex } from "../../shared/types/SubjectIndex";
import { toFormats, toSubjects } from "./articleListing";
import { isTopic } from "./articleSummary";
import { byName, toFacets } from "./facet";
export const toSubjectIndex = (index: ArticleSummary[], categories: Category[]): SubjectIndex => {
const described = new Map(categories.map((category) => [category.id, category]));
return {
subjects: toSubjects(index).map(({ value, count }) => ({
value: described.get(value.id) ?? value,
count,
})),
formats: toFormats(index),
topics: toFacets(index.flatMap(({ tags }) => tags))
.filter(({ value }) => isTopic(value))
.sort(byName),
};
};
|