@mintlify/prebuild
Version:
Helpful functions for Mintlify's prebuild step
23 lines (22 loc) • 947 B
JavaScript
import { parseFrontmatter } from '@mintlify/common';
/**
* When user MDX doesn't explicitly set title/description, preserve the
* auto-generated values (e.g. from OpenAPI schemas) that already exist
* in pagesAcc. Mutates pageMetadata and pagesAcc in place.
*/
export const preserveAutoGeneratedMetadata = (contentStr, slug, pageMetadata, pagesAcc) => {
const existing = pagesAcc[slug];
if (existing) {
try {
const frontmatter = parseFrontmatter(contentStr).attributes;
if (!frontmatter.title && existing.title)
pageMetadata.title = existing.title;
if (!frontmatter.description && existing.description)
pageMetadata.description = existing.description;
if (!frontmatter.sidebarTitle && existing.sidebarTitle)
pageMetadata.sidebarTitle = existing.sidebarTitle;
}
catch { }
}
pagesAcc[slug] = pageMetadata;
};