@mintlify/prebuild
Advanced tools
Comparing version 1.0.59 to 1.0.60
import { OpenApiFile } from '@mintlify/models'; | ||
export declare const createPage: (pagePath: string, pageContent: string, contentDirectoryPath: string, openApiFiles: OpenApiFile[]) => Promise<{ | ||
export declare const createPage: (pagePath: string, pageContent: string, contentDirectoryPath: string, openApiFiles: OpenApiFile[], suppressErrLog?: boolean) => Promise<{ | ||
pageMetadata: { | ||
@@ -19,2 +19,2 @@ href: string; | ||
}; | ||
export declare const preParseMdx: (fileContent: string, contentDirectoryPath: string) => Promise<string>; | ||
export declare const preParseMdx: (fileContent: string, contentDirectoryPath: string, filePath: string, suppressErrLog?: boolean) => Promise<string>; |
import matter from 'gray-matter'; | ||
import isAbsoluteUrl from 'is-absolute-url'; | ||
import { isAbsolute, sep, relative } from 'path'; | ||
import { remark } from 'remark'; | ||
@@ -10,9 +11,14 @@ import remarkFrontmatter from 'remark-frontmatter'; | ||
import { slugToTitle, optionallyAddLeadingSlash } from '../generate.js'; | ||
export const createPage = async (pagePath, pageContent, contentDirectoryPath, openApiFiles) => { | ||
const { data: metadata } = matter(pageContent); | ||
export const createPage = async (pagePath, pageContent, contentDirectoryPath, openApiFiles, suppressErrLog = false) => { | ||
let metadata = {}; | ||
try { | ||
pageContent = await preParseMdx(pageContent, contentDirectoryPath); | ||
const { data } = matter(pageContent); | ||
metadata = data; | ||
pageContent = await preParseMdx(pageContent, contentDirectoryPath, pagePath, suppressErrLog); | ||
} | ||
catch (error) { | ||
pageContent = `🚧 A parsing error occured. Please contact the owner of this website.`; | ||
catch (err) { | ||
console.log(`\n ⚠️ Parsing error in the frontmatter: ${getLocationErrString(pagePath, contentDirectoryPath, err)}: `); | ||
// TODO - pages completely break in our backend when frontmatter is broken. | ||
// Unify "createPage" function across applications and properly catch errors | ||
throw err; | ||
} | ||
@@ -66,3 +72,3 @@ // Replace .mdx so we can pass file paths into this function | ||
}; | ||
export const preParseMdx = async (fileContent, contentDirectoryPath) => { | ||
export const preParseMdx = async (fileContent, contentDirectoryPath, filePath, suppressErrLog = false) => { | ||
try { | ||
@@ -72,2 +78,5 @@ fileContent = await preParseMdxHelper(fileContent, contentDirectoryPath); | ||
catch (error) { | ||
if (!suppressErrLog) { | ||
console.error(formatError(error, filePath, contentDirectoryPath)); | ||
} | ||
fileContent = `🚧 A parsing error occured. Please contact the owner of this website.`; | ||
@@ -189,1 +198,20 @@ } | ||
}; | ||
const getLocationErrString = (filePath, contentDirectoryPath, error) => { | ||
filePath = isAbsolute(filePath) ? relative(contentDirectoryPath, filePath) : filePath; | ||
let location = filePath.startsWith(`.${sep}`) || isAbsolute(filePath) ? filePath : `.${sep}${filePath}`; | ||
if (typeof error === 'object' && error != null && 'line' in error && error.line != null) { | ||
location += `:${error.line}`; | ||
if ('column' in error && error.column != null) { | ||
location += `:${error.column}`; | ||
} | ||
} | ||
return location; | ||
}; | ||
const formatError = (error, filePath, contentDirectoryPath) => { | ||
if (typeof error !== 'object' || error == null) { | ||
return `\n ⚠️ Parsing error: ${filePath} - ${error}`; | ||
} | ||
const location = getLocationErrString(filePath, contentDirectoryPath, error); | ||
const errorString = 'reason' in error && error.reason != null ? error.reason : error; | ||
return `\n ⚠️ Parsing error: ${location} - ${errorString}`; | ||
}; |
@@ -111,3 +111,3 @@ import SwaggerParser from '@apidevtools/swagger-parser'; | ||
const contentStr = (await readFile(sourcePath)).toString(); | ||
const fileContent = await preParseMdx(contentStr, contentDirectoryPath); | ||
const fileContent = await preParseMdx(contentStr, contentDirectoryPath, sourcePath); | ||
const { slug, pageMetadata } = getPageMetadataAndSlug(filename, contentStr, openApiFiles); | ||
@@ -114,0 +114,0 @@ await outputFile(targetPath, fileContent, { |
{ | ||
"name": "@mintlify/prebuild", | ||
"type": "module", | ||
"version": "1.0.59", | ||
"version": "1.0.60", | ||
"description": "Helpful functions for Mintlify's prebuild step", | ||
@@ -71,3 +71,3 @@ "author": "Mintlify, Inc.", | ||
}, | ||
"gitHead": "e7b25227042c8329d0b98d111c6f958c24c3c2c8" | ||
"gitHead": "e2ed8063f572f4759043dfa42113f774325b92d0" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97438
780