@mintlify/common
Version:
Commonly shared code within Mintlify
56 lines (55 loc) • 2.37 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { getAST } from '../mdx/remark.js';
import { UPDATE_MAX } from './constants.js';
import { getDateForNode, getMostRepresentativeDate } from './dates.js';
import { enhanceSnippetsWithImportNames } from './enhanceSnippetsWithImportNames.js';
import { isUpdate } from './index.js';
import { processUpdateNode } from './processUpdateNode.js';
import { resolveSnippets } from './resolveSnippets.js';
export const getV4FeedUpdates = (rssFile) => __awaiter(void 0, void 0, void 0, function* () {
const { content, lineBlame, snippets } = rssFile;
if (!content) {
return [];
}
if (Object.keys(lineBlame).length === 0) {
return [];
}
let ast;
try {
ast = getAST(content);
}
catch (error) {
return [];
}
if (snippets && snippets.length > 0) {
try {
const enhancedSnippets = yield enhanceSnippetsWithImportNames(ast, snippets);
ast = resolveSnippets(ast, enhancedSnippets);
}
catch (_a) { }
}
const updateComponents = ast.children.filter((child) => isUpdate(child));
if (updateComponents.length === 0) {
return [];
}
const allUpdates = [];
for (const updateComponent of updateComponents) {
const componentDate = getDateForNode(updateComponent, lineBlame);
const representativeDate = getMostRepresentativeDate(updateComponent, lineBlame, componentDate);
const updates = processUpdateNode({
updateNode: updateComponent,
date: representativeDate,
});
allUpdates.push(...updates);
}
const limitedUpdates = allUpdates.slice(0, UPDATE_MAX);
return limitedUpdates;
});