@intlayer/chokidar
Version:
Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.
43 lines (41 loc) • 1.5 kB
JavaScript
import { readFile } from "node:fs/promises";
import { basename } from "node:path";
import { getMarkdownMetadata } from "@intlayer/core/markdown";
import { MARKDOWN } from "@intlayer/types/nodeType";
//#region src/loadDictionaries/loadMarkdownContentDeclaration.ts
const loadMarkdownContentDeclaration = async (path) => {
try {
const fileContent = await readFile(path, "utf-8");
const frontmatter = getMarkdownMetadata(fileContent);
const fileName = basename(path).replace(/\.content\.md$/, "");
const key = frontmatter.key ?? fileName;
if (!key) {
console.error(`[intlayer] Missing key in markdown content declaration: ${path}`);
return;
}
const { key: _key, locale, title, description, tags, fill, importMode, location, priority, version } = frontmatter;
return {
key,
...locale !== void 0 && { locale },
...title !== void 0 && { title },
...description !== void 0 && { description },
...tags !== void 0 && { tags },
...fill !== void 0 && { fill },
...importMode !== void 0 && { importMode },
...location !== void 0 && { location },
...priority !== void 0 && { priority },
...version !== void 0 && { version },
content: {
nodeType: MARKDOWN,
[MARKDOWN]: fileContent,
metadata: frontmatter
}
};
} catch (error) {
console.error(`Error loading markdown content declaration at ${path}:`, error);
return;
}
};
//#endregion
export { loadMarkdownContentDeclaration };
//# sourceMappingURL=loadMarkdownContentDeclaration.mjs.map