UNPKG

@inox-tools/content-utils

Version:

Utilities to work with content collections on an Astro project from an integration or library.

52 lines (50 loc) 1.7 kB
import { collectGitInfoForContentFiles } from '../chunk-JOKBL6FV.js'; import { getEntry } from 'astro:content'; var trackedInfo = new Map(await collectGitInfoForContentFiles()); async function getEntryGitInfoInner(args) { const params = args.length > 1 ? args : [args[0].collection, args[0].slug ?? args[0].id]; const entry = await getEntry(...params); const file = entry.filePath; const info = trackedInfo.get(file); if (!info) return [file]; return [ file, { earliest: new Date(info.earliest), latest: new Date(info.latest), authors: Array.from(info.authors), coAuthors: Array.from(info.coAuthors) } ]; } async function getEntryGitInfo(...args) { const [, info] = await getEntryGitInfoInner(args); return info; } var memoizedLatest = /* @__PURE__ */ new Map(); async function getLatestCommitDate(...args) { const [file, info] = await getEntryGitInfoInner(args); if (info !== void 0) return info.latest; const cached = memoizedLatest.get(file); if (cached !== void 0) { return cached; } const date = /* @__PURE__ */ new Date(); memoizedLatest.set(file, date); return date; } var memoizedOldest = /* @__PURE__ */ new Map(); async function getOldestCommitDate(...args) { const [file, info] = await getEntryGitInfoInner(args); if (info !== void 0) return info.latest; const cached = memoizedOldest.get(file); if (cached !== void 0) { return cached; } const date = /* @__PURE__ */ new Date(); memoizedOldest.set(file, date); return date; } export { getEntryGitInfo, getEntryGitInfoInner, getLatestCommitDate, getOldestCommitDate }; //# sourceMappingURL=liveGit.js.map //# sourceMappingURL=liveGit.js.map