UNPKG

myst-cli

Version:
67 lines (66 loc) 3.31 kB
import { castSession } from '../../session/cache.js'; import { selectors } from '../../store/index.js'; import { fileTitle } from '../../utils/fileInfo.js'; export async function manifestPagesFromProject(session, projectPath) { const state = session.store.getState(); const proj = selectors.selectLocalProject(state, projectPath); if (!proj) return []; const cache = castSession(session); const pages = await Promise.all(proj.pages.map(async (page) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; if ('file' in page) { const fileInfo = selectors.selectFileInfo(state, page.file); const title = fileInfo.title || fileTitle(page.file); const short_title = (_a = fileInfo.short_title) !== null && _a !== void 0 ? _a : undefined; const description = (_b = fileInfo.description) !== null && _b !== void 0 ? _b : ''; const thumbnail = (_c = fileInfo.thumbnail) !== null && _c !== void 0 ? _c : ''; const thumbnailOptimized = (_d = fileInfo.thumbnailOptimized) !== null && _d !== void 0 ? _d : ''; const banner = (_e = fileInfo.banner) !== null && _e !== void 0 ? _e : ''; const bannerOptimized = (_f = fileInfo.bannerOptimized) !== null && _f !== void 0 ? _f : ''; const date = (_g = fileInfo.date) !== null && _g !== void 0 ? _g : ''; const tags = (_h = fileInfo.tags) !== null && _h !== void 0 ? _h : []; const { slug, level, file } = page; const { frontmatter } = (_k = (_j = cache.$getMdast(file)) === null || _j === void 0 ? void 0 : _j.post) !== null && _k !== void 0 ? _k : {}; const projectPage = { slug, title, short_title, description, date, thumbnail, thumbnailOptimized, banner, bannerOptimized, tags, level, enumerator: frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.enumerator, }; return projectPage; } return { ...page }; })); return pages; } export function manifestTitleFromProject(session, projectPath) { const state = session.store.getState(); const projConfig = selectors.selectLocalProjectConfig(state, projectPath); if (projConfig === null || projConfig === void 0 ? void 0 : projConfig.title) return projConfig.title; const proj = selectors.selectLocalProject(state, projectPath); if (!proj) return 'Untitled'; const projectFileInfo = selectors.selectFileInfo(session.store.getState(), proj.file); return projectFileInfo.title || proj.index || 'Untitled'; } export function indexFrontmatterFromProject(session, projectPath) { var _a, _b; const state = session.store.getState(); const cache = castSession(session); const proj = selectors.selectLocalProject(state, projectPath); if (!proj) return {}; const { file } = proj; const { frontmatter } = (_b = (_a = cache.$getMdast(file)) === null || _a === void 0 ? void 0 : _a.post) !== null && _b !== void 0 ? _b : {}; return frontmatter !== null && frontmatter !== void 0 ? frontmatter : {}; }