UNPKG

@intlayer/chokidar

Version:

Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.

45 lines (43 loc) 1.82 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const require_runtime = require('../_virtual/_rolldown/runtime.cjs'); let node_fs_promises = require("node:fs/promises"); let node_path = require("node:path"); let _intlayer_core_markdown = require("@intlayer/core/markdown"); let _intlayer_types_nodeType = require("@intlayer/types/nodeType"); //#region src/loadDictionaries/loadMarkdownContentDeclaration.ts const loadMarkdownContentDeclaration = async (path) => { try { const fileContent = await (0, node_fs_promises.readFile)(path, "utf-8"); const frontmatter = (0, _intlayer_core_markdown.getMarkdownMetadata)(fileContent); const fileName = (0, node_path.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: _intlayer_types_nodeType.MARKDOWN, [_intlayer_types_nodeType.MARKDOWN]: fileContent, metadata: frontmatter } }; } catch (error) { console.error(`Error loading markdown content declaration at ${path}:`, error); return; } }; //#endregion exports.loadMarkdownContentDeclaration = loadMarkdownContentDeclaration; //# sourceMappingURL=loadMarkdownContentDeclaration.cjs.map