{"library":"next-validate-link","title":"Markdown Link Validator","description":"next-validate-link is a utility designed to check and ensure the validity of links within Markdown files. It supports various modern web frameworks, including Next.js, Astro, Nuxt, Waku, and React Router, by offering specialized presets for their routing conventions. The package is currently stable at version 1.6.4, with a consistent release cadence of minor and patch updates, indicating active development and continuous improvement. Its core functionality involves scanning specified directories for Markdown files and then validating both internal and external URLs, as well as relative file paths, providing comprehensive link integrity checks essential for documentation sites and content-heavy applications. A key differentiator is its extensibility with custom remark plugins and customizable Markdown validators, ensuring flexibility for diverse project needs.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install next-validate-link"],"cli":{"name":"next-validate-link","version":null}},"imports":["import { validateFiles } from 'next-validate-link';","import { scanURLs } from 'next-validate-link';","import { printErrors } from 'next-validate-link';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { validateFiles, scanURLs, printErrors, readFiles } from 'next-validate-link';\nimport path from 'node:path';\nimport process from 'node:process';\n\nasync function runValidation() {\n  const projectRoot = process.cwd(); // Adjust to your project root if necessary\n  // Example: target all markdown and mdx files in a 'docs' directory\n  const markdownGlob = path.join(projectRoot, 'docs/**/*.{md,mdx}'); \n\n  // Scan available URLs based on your framework (e.g., 'next', 'astro', 'nuxt', 'waku', 'react-router')\n  // For Next.js, it will auto-detect pages from your file system.\n  const scannedUrls = await scanURLs({ \n    preset: 'next', // Use 'next' for Next.js projects\n    // pages: ['/custom-page-path', '/another-page'], // Override auto-detected pages if needed\n  });\n  \n  // Read the markdown files to be validated\n  const filesToValidate = await readFiles(markdownGlob);\n\n  const validationOptions = {\n    scanned: scannedUrls, // Provide the URLs scanned from your project\n    checkRelativePaths: true, // Validate relative file paths (e.g., `../foo.md`)\n    checkRelativeUrls: true,  // Validate relative URLs (e.g., `/some-page`)\n    checkExternal: true,      // Validate external HTTP/HTTPS links (requires network access)\n    baseUrl: 'https://your-live-site.com', // Base URL for resolving absolute paths\n    // pathToUrl: (file) => `/docs/${path.basename(file, path.extname(file))}`, // Custom path-to-URL resolver\n    // You can also pass custom remark plugins or a custom Markdown validator function\n  };\n\n  console.log(`\nValidating markdown links in: ${markdownGlob}...`);\n  const results = await validateFiles(filesToValidate, validationOptions);\n\n  // Print errors and optionally exit with a non-zero code if issues are found\n  const hasErrors = printErrors(results, true); // true means exit with code 1 on errors\n\n  if (hasErrors) {\n    console.error('\\nValidation completed with errors.');\n  } else {\n    console.log('\\nAll markdown links are valid!');\n  }\n}\n\nrunValidation().catch(console.error);\n","lang":"typescript","description":"This quickstart demonstrates how to set up `next-validate-link` to scan your project's Markdown files, resolve internal and external links using framework presets, and report any validation errors. It includes common configuration options for different link types and integrates the `printErrors` helper for clear output.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}