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 23 24 25 26 | 2x 2x 10x 7x 5x 7x | import type { Entry, Page } from "@joinery/content";
import type { ArticleSearch } from "../../shared/types/ArticleSearch";
import type { ArticleSummary } from "../../shared/types/ArticleSummary";
import type { Category } from "../../shared/types/Category";
import { toArticleSummary } from "./articleSummary";
import { toFacets } from "./facet";
const SUGGESTED_SUBJECTS = 4;
export const toSuggestedSubjects = (index: ArticleSummary[]): Category[] =>
toFacets(index.flatMap(({ category }) => category ?? []))
.sort((a, b) => b.count - a.count)
.slice(0, SUGGESTED_SUBJECTS)
.map(({ value }) => value);
// WordPress reports zero pages for zero matches, which would put the first page past the end
export const toArticleSearch = (query: string, page: Page<Entry>): ArticleSearch => ({
items: page.items.map(toArticleSummary),
page: page.page,
perPage: page.perPage,
total: page.total,
totalPages: Math.max(1, page.totalPages),
query,
subjects: [],
});
|