UNPKG

@intlayer/core

Version:

Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.

23 lines (21 loc) 734 B
import { parseYaml } from "../../utils/parseYaml.mjs"; //#region src/transpiler/markdown/getMarkdownMetadata.ts const getMarkdownMetadata = (markdown) => { try { const lines = markdown.split(/\r?\n/); const firstNonEmptyLine = lines.find((line) => line.trim() !== ""); if (!firstNonEmptyLine || firstNonEmptyLine.trim() !== "---") return {}; let metadataEndIndex = -1; for (let i = 1; i < lines.length; i++) if (lines[i].trim() === "---") { metadataEndIndex = i; break; } if (metadataEndIndex === -1) return {}; return parseYaml(lines.slice(1, metadataEndIndex).join("\n")) ?? {}; } catch (_e) { return {}; } }; //#endregion export { getMarkdownMetadata }; //# sourceMappingURL=getMarkdownMetadata.mjs.map