UNPKG

@mintlify/link-rot

Version:

Static checking for broken internal links

32 lines (31 loc) 1.72 kB
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 { validateDocsConfig, validateMintConfig } from '@mintlify/validation'; import fs from 'fs-extra'; import path from 'path'; export const getRedirects = (baseDir) => __awaiter(void 0, void 0, void 0, function* () { const configRedirects = []; // read docs.json or mint.json to get redirects if (fs.existsSync(path.join(baseDir, 'docs.json'))) { const docsJson = yield fs.readJSON(path.join(baseDir, 'docs.json')); const result = validateDocsConfig(docsJson); if (result.success && 'redirects' in result.data && result.data.redirects) { configRedirects.push(...result.data.redirects); } } else if (fs.existsSync(path.join(baseDir, 'mint.json'))) { const mintJson = yield fs.readJSON(path.join(baseDir, 'mint.json')); const result = validateMintConfig(mintJson); if (result.success && 'redirects' in result.data && result.data.redirects) { configRedirects.push(...result.data.redirects); } } return configRedirects; });