UNPKG

myst-cli

Version:
19 lines (18 loc) 656 B
import { castSession } from '../session/cache.js'; /** * Load frontmatter parts from session and return part:node lookup */ export function resolveFrontmatterParts(session, pageFrontmatter) { const { parts } = pageFrontmatter ?? {}; if (!parts || Object.keys(parts).length === 0) return undefined; const partsMdast = {}; Object.entries(parts).forEach(([part, content]) => { if (content.length !== 1) return; const { mdast, frontmatter } = castSession(session).$getMdast(content[0])?.post ?? {}; if (mdast) partsMdast[part] = { mdast, frontmatter }; }); return partsMdast; }