domain/converters/chapter.converter.ts
domain/converters/chapter.converter.ts is a file in Bane's Lab Site. 28 lines of code and 3 definitions.
import { CHAPTER_FACE, CHAPTER_KIND } from "#configuration/constants/vocabulary.constants";
import type { PageContent, VocabularyEntry } from "#types/vocabulary.types";
import { FACE_SEPARATOR } from "@govlab/constants";
import type { Tab } from "#types/document.types";
import { tabPath } from "#core/assets/link.assets";
const ANCHOR = "#";
export const chapterRef = function chapterRef(
page: string,
tabs: readonly Tab[],
tab: string,
section: string,
): string {
return CHAPTER_FACE + FACE_SEPARATOR + tabPath(page, tabs, tab) + ANCHOR + section;
};
export const chapterVocabulary = function chapterVocabulary(pages: readonly PageContent[]): readonly VocabularyEntry[] {
return pages.flatMap(({ page, tabs }) =>
tabs.flatMap((tab) =>
tab.sections.map((section) => ({
code: null,
kind: CHAPTER_KIND,
layer: null,
phrase: section.title,
prose: true,
ref: chapterRef(page, tabs, tab.id, section.id),
})),
),
);
};