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 "#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), })), ), ); };