### Install LinkValidator using Bash script Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Recommended installation method for Linux/macOS using a Bash script to download and install the tool. ```bash curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/dev/install.sh | bash ``` -------------------------------- ### Multi-stage Docker Build with Link Validation Source: https://github.com/aaronontheweb/link-validator/blob/dev/docs/cicd-integration.md Integrate link validation into a multi-stage Docker build process. This example demonstrates installing LinkValidator, building a site, validating its links, and then copying the validated site into a production Nginx image. ```docker # Build stage FROM node:18-alpine AS builder WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . RUN npm run build # Validation stage FROM node:18-alpine AS validator WORKDIR /app # Install LinkValidator RUN apk add --no-cache curl bash powershell && \ curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/main/install.sh | bash -s -- --dir /usr/local/bin # Copy built site COPY --from=builder /app/dist ./ # Validate links before final image RUN npm install -g http-server && \ http-server ./dist -p 8080 -s & \ SERVER_PID=$! && \ sleep 5 && \ link-validator --url http://localhost:8080 \ --output /tmp/sitemap.md \ --strict \ --max-external-retries 2 \ --retry-delay-seconds 5 && \ kill $SERVER_PID # Production stage FROM nginx:alpine COPY --from=builder /app/dist /usr/share/nginx/html COPY --from=validator /tmp/sitemap.md /usr/share/nginx/html/sitemap.md EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] ``` -------------------------------- ### Install LinkValidator (Windows PowerShell) Source: https://context7.com/aaronontheweb/link-validator/llms.txt Installs the link-validator tool using PowerShell. Options include default installation with PATH setup, custom installation path, or installation without adding to PATH. ```powershell # Default installation with PATH setup irm https://raw.githubusercontent.com/Aaronontheweb/link-validator/dev/install.ps1 | iex ``` ```powershell # Install to custom location irm https://raw.githubusercontent.com/Aaronontheweb/link-validator/dev/install.ps1 | iex -ArgumentList ",InstallPath", "C:\\tools\\linkvalidator" ``` ```powershell # Install without adding to PATH irm https://raw.githubusercontent.com/Aaronontheweb/link-validator/dev/install.ps1 | iex -ArgumentList "-SkipPath" ``` -------------------------------- ### Development environment setup Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Commands to clone, build, and run the project locally. ```bash # Clone the repository git clone https://github.com/Aaronontheweb/link-validator.git cd link-validator # Install .NET 9 SDK # Build and test dotnet build dotnet test # Run locally dotnet run --project src/LinkValidator -- --url https://example.com ``` -------------------------------- ### Install LinkValidator using PowerShell script Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Recommended installation method for Windows using a PowerShell script to download and install the tool. ```powershell irm https://raw.githubusercontent.com/Aaronontheweb/link-validator/dev/install.ps1 | iex ``` -------------------------------- ### Authenticated CI/CD Example Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Example configuration for GitHub Actions using authentication cookies. ```yaml - name: "Get auth cookie" run: curl -c cookies.txt -L -s http://localhost:5000/dev-login - name: "Validate links" run: | link-validator \ --url http://localhost:5000 \ --cookie-file cookies.txt \ --output link-report.md \ --max-external-retries 3 ``` -------------------------------- ### Common CLI Examples Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Standard commands for crawling, saving reports, and CI integration. ```bash link-validator --url https://aaronstannard.com ``` ```bash link-validator --url https://aaronstannard.com --output sitemap.md ``` ```bash link-validator --url https://aaronstannard.com --strict ``` ```bash # First crawl link-validator --url https://aaronstannard.com --output baseline.md ``` -------------------------------- ### Install LinkValidator to custom location (Bash) Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Advanced installation option for Linux/macOS to install LinkValidator to a specified directory. ```bash curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/dev/install.sh | bash -s -- --dir ~/.local/bin ``` -------------------------------- ### Install and Run LinkValidator in GitHub Actions Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Use these steps to install the tool and validate links within a CI pipeline. ```yaml - name: Install LinkValidator run: curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/dev/install.sh | bash - name: Validate Links run: link-validator --url http://localhost:3000 --strict ``` -------------------------------- ### Install LinkValidator without adding to PATH (Bash) Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Advanced installation option for Linux/macOS to install LinkValidator without automatically adding the installation directory to the system PATH. ```bash curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/dev/install.sh | bash -s -- --skip-path ``` -------------------------------- ### Install LinkValidator without adding to PATH (PowerShell) Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Advanced installation option for Windows to install LinkValidator without automatically adding the installation directory to the system PATH. ```powershell irm https://raw.githubusercontent.com/Aaronontheweb/link-validator/dev/install.ps1 | iex -ArgumentList "-SkipPath" ``` -------------------------------- ### Docker Installation for Link Validator Source: https://github.com/aaronontheweb/link-validator/blob/dev/docs/cicd-integration.md Installs the Link Validator tool within a Docker container using an Alpine-based image. ```dockerfile FROM mcr.microsoft.com/dotnet/runtime:9.0-alpine AS base WORKDIR /app # Install LinkValidator RUN apk add --no-cache curl bash && \ curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/main/install.sh | bash -s -- --dir /usr/local/bin ``` -------------------------------- ### Crawl a website with LinkValidator Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Basic command to start crawling a website and validating its links. ```bash link-validator --url https://example.com ``` -------------------------------- ### Install LinkValidator to custom location (PowerShell) Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Advanced installation option for Windows to install LinkValidator to a specified directory without adding it to the system PATH. ```powershell irm https://raw.githubusercontent.com/Aaronontheweb/link-validator/dev/install.ps1 | iex -ArgumentList "-InstallPath", "C:\tools\linkvalidator" ``` -------------------------------- ### CircleCI: Install LinkValidator Source: https://github.com/aaronontheweb/link-validator/blob/dev/docs/cicd-integration.md A CircleCI job to install the LinkValidator binary into a specified directory. This step ensures the validator is available for subsequent jobs in the pipeline. ```yaml version: 2.1 executors: node-executor: docker: - image: cimg/node:18.17 working_directory: ~/ jobs: install_linkvalidator: executor: node-executor steps: - checkout - run: name: Install LinkValidator command: | curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/main/install.sh | bash -s -- --dir ~/linkvalidator - persist_to_workspace: root: ~/ paths: - linkvalidator ``` -------------------------------- ### Build Docker Image with Link Validator Source: https://context7.com/aaronontheweb/link-validator/llms.txt This Dockerfile defines stages for building and running the link validator. It installs necessary tools, downloads the validator, and then runs it against a local http-server instance. ```dockerfile FROM node:18-alpine AS validator WORKDIR /app RUN apk add --no-cache curl bash && \ curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/main/install.sh | bash -s -- --dir /usr/local/bin COPY --from=builder /app/dist ./dist RUN npm install -g http-server && \ http-server ./dist -p 8080 & \ sleep 5 && \ link-validator --url http://localhost:8080 \ --output /tmp/sitemap.md \ --strict \ --max-external-retries 2 # Production stage FROM nginx:alpine COPY --from=builder /app/dist /usr/share/nginx/html COPY --from=validator /tmp/sitemap.md /usr/share/nginx/html/sitemap.md EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] ``` -------------------------------- ### Build LinkValidator from Source Source: https://context7.com/aaronontheweb/link-validator/llms.txt Builds the link-validator tool from source code. Requires cloning the repository and having the .NET 9 SDK installed. Supports direct execution and publishing as a self-contained binary. ```bash # Clone and build git clone https://github.com/Aaronontheweb/link-validator.git cd link-validator ``` ```bash # Run directly (requires .NET 9 SDK) dotnet run --project src/LinkValidator -- --url https://example.com ``` ```bash # Publish as single-file binary dotnet publish src/LinkValidator -c Release -r linux-x64 --self-contained false # Binary at: src/LinkValidator/bin/Release/net9.0/linux-x64/publish/link-validator ``` ```bash # Run tests dotnet test ``` -------------------------------- ### Docker Multi-Stage Build for Link Validation Source: https://context7.com/aaronontheweb/link-validator/llms.txt Demonstrates using a Docker multi-stage build to validate links. The builder stage installs dependencies and builds the site, allowing for link validation before creating the final production image. ```dockerfile # Build stage FROM node:18-alpine AS builder WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . RUN npm run build ``` -------------------------------- ### GitLab CI Pipeline Configuration Source: https://github.com/aaronontheweb/link-validator/blob/dev/docs/cicd-integration.md Defines stages for installing the validator, building the site, and validating links within a GitLab CI environment. ```yaml stages: - setup - build - validate variables: LINK_VALIDATOR_MAX_EXTERNAL_RETRIES: "3" LINK_VALIDATOR_RETRY_DELAY_SECONDS: "10" install_linkvalidator: stage: setup script: - curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/main/install.sh | bash -s -- --dir ./linkvalidator artifacts: paths: - linkvalidator/ expire_in: 1 hour build_site: stage: build script: - npm install - npm run build artifacts: paths: - dist/ expire_in: 1 hour validate_links: stage: validate dependencies: - install_linkvalidator - build_site script: - npm run serve & - sleep 5 - | if [ "$CI_COMMIT_REF_NAME" != "main" ] && [ -f baseline-sitemap.md ]; then ./linkvalidator/link-validator --url http://localhost:3000 \ --output current-sitemap.md \ --diff baseline-sitemap.md \ --strict else ./linkvalidator/link-validator --url http://localhost:3000 \ --output sitemap.md \ --strict fi artifacts: when: always paths: - "*.md" reports: junit: sitemap.xml only: - main - merge_requests ``` -------------------------------- ### CircleCI: Build Site Source: https://github.com/aaronontheweb/link-validator/blob/dev/docs/cicd-integration.md A CircleCI job to install project dependencies and build the site. It utilizes caching for npm dependencies to speed up subsequent builds. ```yaml build_site: executor: node-executor steps: - checkout - restore_cache: keys: - npm-deps-{{ checksum "package-lock.json" }} - run: name: Install Dependencies command: npm ci - save_cache: key: npm-deps-{{ checksum "package-lock.json" }} paths: - node_modules - run: name: Build Site command: npm run build - persist_to_workspace: root: ~/project paths: - dist ``` -------------------------------- ### Azure DevOps Pipeline for Link Validation Source: https://github.com/aaronontheweb/link-validator/blob/dev/docs/cicd-integration.md Configures a CI pipeline to download a baseline sitemap, install the link-validator, and run validation against a local build. ```yaml trigger: branches: include: - main - develop variables: linkValidatorVersion: 'latest' stages: - stage: ValidateLinks displayName: 'Link Validation' jobs: - job: Validate displayName: 'Validate Website Links' pool: vmImage: 'ubuntu-latest' steps: - checkout: self fetchDepth: 0 - task: DownloadBuildArtifacts@1 displayName: 'Download Baseline Sitemap' condition: ne(variables['Build.SourceBranch'], 'refs/heads/main') inputs: buildType: 'specific' project: '$(System.TeamProject)' pipeline: '$(System.DefinitionId)' buildVersionToDownload: 'latestFromBranch' branchName: 'refs/heads/main' downloadType: 'single' artifactName: 'baseline-sitemap' downloadPath: '$(System.ArtifactsDirectory)' continueOnError: true - task: Bash@3 displayName: 'Install and Configure LinkValidator' inputs: targetType: 'inline' script: | curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/main/install.sh | bash -s -- --version $(linkValidatorVersion) echo "##vso[task.prependpath]$HOME/.linkvalidator" # Set environment variables for retry configuration echo "##vso[task.setvariable variable=LINK_VALIDATOR_MAX_EXTERNAL_RETRIES]3" echo "##vso[task.setvariable variable=LINK_VALIDATOR_RETRY_DELAY_SECONDS]10" - task: Bash@3 displayName: 'Validate Links with Baseline Comparison' inputs: targetType: 'inline' script: | # Build and start site npm ci npm run build npm run serve & SERVER_PID=$! sleep 10 # Prepare validation command VALIDATION_CMD="link-validator --url http://localhost:3000 --output current-sitemap.md --strict" # Add baseline comparison if available if [ -f "$(System.ArtifactsDirectory)/baseline-sitemap/sitemap.md" ]; then VALIDATION_CMD="$VALIDATION_CMD --diff $(System.ArtifactsDirectory)/baseline-sitemap/sitemap.md" echo "Using baseline comparison" else echo "No baseline found, running without comparison" fi # Run validation eval $VALIDATION_CMD # Cleanup kill $SERVER_PID || true - task: PublishBuildArtifacts@1 displayName: 'Publish Current Sitemap' condition: always() inputs: pathtoPublish: 'current-sitemap.md' artifactName: '$(Build.SourceBranchName == "main" && "baseline-sitemap" || "current-sitemap")' ``` -------------------------------- ### Internal links report format Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Example of the markdown table structure for internal link validation results. ```markdown ## Internal Links | URL | Status | Status Code | |-----|--------|-------------| | https://example.com/ | ✅ Ok | 200 | | https://example.com/about | ✅ Ok | 200 | | https://example.com/missing | ❌ Error | 404 | ``` -------------------------------- ### External links report format Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Example of the markdown table structure for external link validation results. ```markdown ## External Links | URL | Status | Status Code | |-----|--------|-------------| | https://github.com/example | ✅ Ok | 200 | | https://api.example.com/v1 | ❌ Error | 500 | | https://slow-service.com | ⏸️ Retry Scheduled | 429 | ``` -------------------------------- ### Jenkins Pipeline for Link Validation Source: https://github.com/aaronontheweb/link-validator/blob/dev/docs/cicd-integration.md This pipeline installs the link-validator, builds and serves a static site, validates links, and cleans up. It conditionally uses a baseline sitemap for diffing links on branches other than 'main'. ```groovy pipeline { agent any environment { LINK_VALIDATOR_MAX_EXTERNAL_RETRIES = '3' LINK_VALIDATOR_RETRY_DELAY_SECONDS = '15' } stages { stage('Install LinkValidator') { steps { sh ''' curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/main/install.sh | bash -s -- --dir ./.linkvalidator ''' } } stage('Build Site') { steps { sh ''' # Build your static site npm install npm run build npm run serve & SERVER_PID=$! echo $SERVER_PID > server.pid sleep 5 ''' } } stage('Validate Links') { steps { script { def baselineExists = fileExists('baseline-sitemap.md') if (baselineExists && env.BRANCH_NAME != 'main') { sh ''' ./.linkvalidator/link-validator --url http://localhost:3000 \ --output current-sitemap.md \ --diff baseline-sitemap.md \ --strict ''' } else { sh ''' ./.linkvalidator/link-validator --url http://localhost:3000 \ --output sitemap.md \ --strict ''' } } } post { always { sh ''' if [ -f server.pid ]; then kill $(cat server.pid) || true rm server.pid fi ''' archiveArtifacts artifacts: '*.md', fingerprint: true } failure { emailext ( subject: "Link Validation Failed: ${env.JOB_NAME} - ${env.BUILD_NUMBER}", body: "Link validation failed for ${env.BUILD_URL}. Check the console output for details.", to: "${env.CHANGE_AUTHOR_EMAIL}" ) } } } } } ``` -------------------------------- ### Azure DevOps Pipeline Integration Source: https://github.com/aaronontheweb/link-validator/blob/dev/docs/cicd-integration.md Pipeline configuration for Azure DevOps using Bash tasks to install and run LinkValidator with baseline comparison. ```yaml trigger: branches: include: - main - develop pool: vmImage: 'ubuntu-latest' steps: - task: Bash@3 displayName: 'Install LinkValidator' inputs: targetType: 'inline' script: | curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/main/install.sh | bash echo "##vso[task.prependpath]$HOME/.linkvalidator" - task: Bash@3 displayName: 'Build Site' inputs: targetType: 'inline' script: | # Start your local server npm run build npm run serve & sleep 5 - task: Bash@3 displayName: 'Validate Links' inputs: targetType: 'inline' script: | # Validate with comparison against baseline link-validator --url http://localhost:3000 \ --output current-sitemap.md \ --diff baseline-sitemap.md \ --strict \ --max-external-retries 5 \ --retry-delay-seconds 10 - task: PublishBuildArtifacts@1 displayName: 'Publish Sitemap' condition: always() inputs: pathtoPublish: 'current-sitemap.md' artifactName: 'sitemap' ``` -------------------------------- ### Declarative Jenkins Pipeline with Parallel Validation Source: https://github.com/aaronontheweb/link-validator/blob/dev/docs/cicd-integration.md Configures a Jenkins pipeline to install the validator, build the site, and run validation with optional baseline comparison. ```groovy pipeline { agent any parameters { choice(name: 'VALIDATION_MODE', choices: ['strict', 'warning'], description: 'Link validation mode') string(name: 'MAX_RETRIES', defaultValue: '3', description: 'Maximum external link retries') string(name: 'RETRY_DELAY', defaultValue: '10', description: 'Retry delay in seconds') } stages { stage('Setup') { parallel { stage('Install LinkValidator') { steps { sh ''' curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/main/install.sh | bash -s -- --dir ./tools/linkvalidator ''' } } stage('Download Baseline') { when { not { branch 'main' } } steps { copyArtifacts( projectName: env.JOB_NAME, selector: lastSuccessful(), target: 'baseline/', optional: true, filter: 'sitemap.md' ) } } } } stage('Build and Validate') { steps { sh ''' # Build site npm ci npm run build npm run serve & echo $! > server.pid sleep 10 # Prepare validation command VALIDATION_CMD="./tools/linkvalidator/link-validator --url http://localhost:3000 --output sitemap.md" VALIDATION_CMD="$VALIDATION_CMD --max-external-retries ${MAX_RETRIES}" VALIDATION_CMD="$VALIDATION_CMD --retry-delay-seconds ${RETRY_DELAY}" # Add strict mode if selected if [ "${VALIDATION_MODE}" = "strict" ]; then VALIDATION_CMD="$VALIDATION_CMD --strict" fi # Add baseline comparison if available if [ -f "baseline/sitemap.md" ]; then VALIDATION_CMD="$VALIDATION_CMD --diff baseline/sitemap.md" fi # Run validation echo "Running: $VALIDATION_CMD" eval $VALIDATION_CMD ''' } post { always { sh ''' if [ -f server.pid ]; then kill $(cat server.pid) || true fi ''' } } } } post { always { archiveArtifacts artifacts: 'sitemap.md', fingerprint: true publishHTML([ allowMissing: false, alwaysLinkToLastBuild: true, keepAll: true, reportDir: '.', reportFiles: 'sitemap.md', reportName: 'Link Validation Report' ]) } } } ``` -------------------------------- ### GitHub Actions: Basic Link Validation Source: https://context7.com/aaronontheweb/link-validator/llms.txt A basic GitHub Actions workflow to validate links on a static site during pull requests. It checks out the code, installs the validator, builds and serves the site, validates links, and uploads the sitemap as an artifact. ```yaml name: Link Validation on: push: branches: [ main ] pull_request: branches: [ main ] jobs: validate-links: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Install LinkValidator run: | curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/main/install.sh | bash echo "$HOME/.linkvalidator" >> $GITHUB_PATH - name: Build and Serve Site run: | npm install && npm run build npm run serve & sleep 10 - name: Validate Links run: link-validator --url http://localhost:3000 --output sitemap.md --strict - name: Upload Sitemap Artifact if: always() uses: actions/upload-artifact@v4 with: name: sitemap path: sitemap.md ``` -------------------------------- ### CircleCI: Validate Links Source: https://github.com/aaronontheweb/link-validator/blob/dev/docs/cicd-integration.md A CircleCI job that starts a local server, validates links using LinkValidator, and cleans up. It conditionally performs a diff against a baseline if not on the main branch. ```yaml validate_links: executor: node-executor steps: - checkout - attach_workspace: at: ~/ - attach_workspace: at: ~/project - run: name: Start Local Server command: | npm install -g http-server http-server ~/project/dist -p 8080 & echo $! > server.pid sleep 5 - run: name: Validate Links command: | export PATH=~/linkvalidator:$PATH export LINK_VALIDATOR_MAX_EXTERNAL_RETRIES=3 export LINK_VALIDATOR_RETRY_DELAY_SECONDS=10 if [ "$CIRCLE_BRANCH" != "main" ] && [ -f baseline-sitemap.md ]; then link-validator --url http://localhost:8080 \ --output current-sitemap.md \ --diff baseline-sitemap.md \ --strict else link-validator --url http://localhost:8080 \ --output sitemap.md \ --strict fi - run: name: Cleanup command: | if [ -f server.pid ]; then kill $(cat server.pid) || true fi when: always - store_artifacts: path: ~/project/*.md destination: sitemaps ``` -------------------------------- ### Azure DevOps: Link Validation Integration Source: https://context7.com/aaronontheweb/link-validator/llms.txt Integrates link validation into an Azure DevOps pipeline. It installs the link-validator tool, serves the site, performs validation with custom retry settings, and publishes the resulting sitemap as a build artifact. ```yaml trigger: branches: include: - main - develop pool: vmImage: 'ubuntu-latest' steps: - task: Bash@3 displayName: 'Install LinkValidator' inputs: targetType: 'inline' script: | curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/main/install.sh | bash echo "##vso[task.prependpath]$HOME/.linkvalidator" - task: Bash@3 displayName: 'Validate Links' inputs: targetType: 'inline' script: | npm run serve & sleep 5 link-validator --url http://localhost:3000 \ --output current-sitemap.md \ --strict \ --max-external-retries 5 - task: PublishBuildArtifacts@1 displayName: 'Publish Sitemap' condition: always() inputs: pathtoPublish: 'current-sitemap.md' artifactName: 'sitemap' ``` -------------------------------- ### Build and run LinkValidator from source Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Instructions for building the LinkValidator project from source using the .NET CLI and running it locally. ```bash git clone https://github.com/Aaronontheweb/link-validator.git cd link-validator # Build and run locally dotnet run --project src/LinkValidator -- --url https://example.com # Or publish as single-file binary dotnet publish src/LinkValidator -c Release -r --self-contained false # Where is: win-x64, linux-x64, osx-x64, or osx-arm64 ``` -------------------------------- ### Basic CLI Usage Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md The standard syntax for running the validator. ```bash link-validator --url [OPTIONS] ``` -------------------------------- ### Configure via Environment Variables Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Override default settings using environment variables. ```bash export LINK_VALIDATOR_MAX_EXTERNAL_RETRIES=5 export LINK_VALIDATOR_RETRY_DELAY_SECONDS=15 link-validator --url https://example.com ``` -------------------------------- ### Run with debug logging Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Executes the tool with output directed to a debug sitemap file. ```bash # The tool outputs detailed logs during crawling LinkValidator --url https://example.com --output debug-sitemap.md ``` -------------------------------- ### CrawlerHelper API (.NET) Source: https://context7.com/aaronontheweb/link-validator/llms.txt Demonstrates how to use the CrawlerHelper in .NET to programmatically crawl websites, generate reports, and access crawl results. ```APIDOC ## CrawlerHelper API (.NET) ### Description Use the crawler programmatically in .NET applications to integrate link validation into custom tooling or tests. This API allows for detailed control over the crawling process and access to the results. ### Usage 1. **Initialize Actor System**: Create an Akka Actor System. 2. **Define Base URL**: Specify the starting URL for the crawl. 3. **Configure Crawl Settings**: Set parameters like concurrency, timeouts, retries, and cookies. 4. **Execute Crawl**: Call `CrawlerHelper.CrawlWebsite` with the system, base URL, and settings. 5. **Generate Markdown Report**: Use `MarkdownHelper.GenerateMarkdown` to create a report from the crawl results. 6. **Access Results Programmatically**: Iterate through `CrawlReport` to get link details and status codes. 7. **Check for Broken Links**: Filter results to identify links with status codes >= 400. 8. **Terminate Actor System**: Clean up resources by terminating the actor system. ### Code Example ```csharp using Akka.Actor; using LinkValidator.Actors; using LinkValidator.Util; using static LinkValidator.Util.MarkdownHelper; // Create actor system var system = ActorSystem.Create("CrawlerSystem", "akka.loglevel = INFO"); var baseUrl = new AbsoluteUri(new Uri("https://example.com")); // Configure crawl settings var crawlSettings = new CrawlConfiguration( BaseUrl: baseUrl, MaxInflightRequests: 10, // Concurrent requests per domain RequestTimeout: TimeSpan.FromSeconds(5), MaxExternalRetries: 3, // Retries for 429 responses DefaultExternalRetryDelay: TimeSpan.FromSeconds(10), Cookies: null // Optional CookieContainer for auth ); // Execute crawl CrawlReport results = await CrawlerHelper.CrawlWebsite(system, baseUrl, crawlSettings); // Generate markdown report string markdown = GenerateMarkdown(results); await File.WriteAllTextAsync("sitemap.md", markdown); // Access results programmatically foreach (var (url, record) in results.InternalLinks) { Console.WriteLine($"{url}: {record.StatusCode}"); // record.LinksToPage contains pages that link to this URL } // Check for broken links var brokenLinks = results.InternalLinks .Concat(results.ExternalLinks) .Where(kvp => (int)kvp.Value.StatusCode >= 400); await system.Terminate(); ``` ``` -------------------------------- ### Basic Website Crawl with LinkValidator Source: https://context7.com/aaronontheweb/link-validator/llms.txt Crawl a website and output link validation results to the terminal or a file. Use --strict mode to fail builds on broken links. ```bash # Basic crawl - outputs results to terminal link-validator --url https://example.com ``` ```bash # Crawl with saved output link-validator --url https://example.com --output sitemap.md ``` ```bash # Strict mode - exits with error code 1 if broken links found link-validator --url https://example.com --output sitemap.md --strict ``` -------------------------------- ### Crawl with Cookie File Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Run the validator using a previously generated cookie file. ```bash link-validator --url http://localhost:5000 --cookie-file cookies.txt --output report.md ``` -------------------------------- ### Crawl Website with CrawlerHelper API (.NET) Source: https://context7.com/aaronontheweb/link-validator/llms.txt Integrates link validation into .NET applications. Configure crawl settings like concurrency, timeouts, and retries, then execute the crawl and generate a markdown report. ```csharp using Akka.Actor; using LinkValidator.Actors; using LinkValidator.Util; using static LinkValidator.Util.MarkdownHelper; // Create actor system var system = ActorSystem.Create("CrawlerSystem", "akka.loglevel = INFO"); var baseUrl = new AbsoluteUri(new Uri("https://example.com")); // Configure crawl settings var crawlSettings = new CrawlConfiguration( BaseUrl: baseUrl, MaxInflightRequests: 10, // Concurrent requests per domain RequestTimeout: TimeSpan.FromSeconds(5), MaxExternalRetries: 3, // Retries for 429 responses DefaultExternalRetryDelay: TimeSpan.FromSeconds(10), Cookies: null // Optional CookieContainer for auth ); // Execute crawl CrawlReport results = await CrawlerHelper.CrawlWebsite(system, baseUrl, crawlSettings); // Generate markdown report string markdown = GenerateMarkdown(results); await File.WriteAllTextAsync("sitemap.md", markdown); // Access results programmatically foreach (var (url, record) in results.InternalLinks) { Console.WriteLine($"{url}: {record.StatusCode}"); // record.LinksToPage contains pages that link to this URL } // Check for broken links var brokenLinks = results.InternalLinks .Concat(results.ExternalLinks) .Where(kvp => (int)kvp.Value.StatusCode >= 400); await system.Terminate(); ``` -------------------------------- ### Dockerfile for Link Validator Source: https://context7.com/aaronontheweb/link-validator/llms.txt This Dockerfile outlines the build process for the Link Validator, including stages for validation and production. ```APIDOC ## Dockerfile for Link Validator ### Description This Dockerfile defines the build process for the Link Validator application. It includes stages for installing dependencies, building the validator, and setting up the production environment using Nginx. ### Stages 1. **Validator Stage**: Installs `curl`, `bash`, downloads and installs `link-validator`, installs `http-server`, and runs the link validator against a local server. 2. **Production Stage**: Uses an Nginx image, copies the built application and the generated sitemap, and exposes port 80. ### Build Commands (Example) ```bash docker build -t link-validator . ``` ### Run Command (Example) ```bash docker run -p 80:80 link-validator ``` ``` -------------------------------- ### Configure custom retry settings Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Sets retry limits and delays for external link requests. ```bash link-validator --url https://example.com \ --max-external-retries 5 \ --retry-delay-seconds 30 ``` -------------------------------- ### Compare Sitemaps with Diff Helper (.NET) Source: https://context7.com/aaronontheweb/link-validator/llms.txt Compares two sitemap markdown files to detect changes between crawl runs. It identifies missing pages, new pages, and flags errors if new pages have status codes >= 400. ```csharp using LinkValidator.Util; string previousSitemap = await File.ReadAllTextAsync("baseline.md"); string currentSitemap = await File.ReadAllTextAsync("current.md"); var (differences, hasErrors) = DiffHelper.CompareSitemapsWithErrors(previousSitemap, currentSitemap); foreach (var diff in differences) { Console.WriteLine(diff); // Output examples: // "Missing: | `/old-page` | 200 | `/` |" // "New: | `/new-page` | 404 | `/about` |" } if (hasErrors) { // hasErrors is true when: // - Pages that existed before are now missing // - New pages have status codes >= 400 Environment.Exit(1); } ``` -------------------------------- ### Acquire Session Cookies Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Use curl to generate a cookie file for authenticated crawling. ```bash # For apps with a dev/test login endpoint curl -c cookies.txt -L http://localhost:5000/dev-login # For apps with a form-based login curl -c cookies.txt -L -d "username=admin&password=secret" http://localhost:5000/login # For APIs that return a Set-Cookie header curl -c cookies.txt -X POST http://localhost:5000/api/auth/login \ -H "Content-Type: application/json" \ -d '{"email":"admin@example.com","password":"secret"}' ``` -------------------------------- ### Configure retries via environment variables Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Uses environment variables to define retry behavior instead of command-line flags. ```bash export LINK_VALIDATOR_MAX_EXTERNAL_RETRIES=10 export LINK_VALIDATOR_RETRY_DELAY_SECONDS=5 link-validator --url https://example.com --strict ``` -------------------------------- ### Baseline Comparison for Link Validation Source: https://context7.com/aaronontheweb/link-validator/llms.txt Compare current crawl results against a baseline to detect new broken links or missing pages. Requires creating a baseline first, then performing a comparison with the --diff flag. ```bash # First, create a baseline link-validator --url https://example.com --output baseline.md ``` ```bash # Later, compare against baseline link-validator --url https://example.com --output current.md --diff baseline.md --strict ``` ```text # Expected output when differences found: # Missing: | `/about` | 200 | `/` | # New: | `/contact` | 404 | `/` | ``` -------------------------------- ### Cookie File Parser (.NET) Source: https://context7.com/aaronontheweb/link-validator/llms.txt Explains how to parse Netscape/Mozilla format cookie files using `CookieFileParser` for authenticated crawling. ```APIDOC ## Cookie File Parser (.NET) ### Description Parse Netscape/Mozilla format cookie files for authenticated crawling scenarios. This utility helps in loading existing cookies into a `CookieContainer` for use during website crawls. ### Usage 1. **Provide Cookie File Path**: Specify the path to the cookie file. 2. **Parse File**: Use `CookieFileParser.Parse()` to load cookies into a `CookieContainer`. 3. **Use with Crawl Configuration**: Pass the resulting `CookieContainer` to the `CrawlConfiguration`. ### Example Cookie File Format ``` .example.com TRUE / FALSE 1735689600 session_id abc123 #HttpOnly_.example.com TRUE / TRUE 0 auth_token xyz789 ``` ### Code Example ```csharp using System.Net; using LinkValidator.Util; // Parse cookie file (format: domain TAB flag TAB path TAB secure TAB expiry TAB name TAB value) // Example cookies.txt: // .example.com TRUE / FALSE 1735689600 session_id abc123 // #HttpOnly_.example.com TRUE / TRUE 0 auth_token xyz789 CookieContainer cookies = CookieFileParser.Parse("cookies.txt"); // Use with crawl configuration var crawlSettings = new CrawlConfiguration( BaseUrl: new AbsoluteUri(new Uri("https://example.com")), MaxInflightRequests: 10, RequestTimeout: TimeSpan.FromSeconds(5), Cookies: cookies // Pass the parsed cookies ); ``` ``` -------------------------------- ### Run link validation with comparison Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Performs a crawl and compares results against a baseline file in strict mode. ```bash link-validator --url https://aaronstannard.com --output current.md --diff baseline.md --strict ``` -------------------------------- ### Diff Helper (.NET) Source: https://context7.com/aaronontheweb/link-validator/llms.txt Details the `DiffHelper` utility for comparing two sitemap markdown reports to identify changes and errors between crawl runs. ```APIDOC ## Diff Helper (.NET) ### Description Compare two sitemap outputs to detect changes between crawl runs. This utility is useful for identifying regressions or new issues introduced in website content or structure. ### Usage 1. **Read Sitemap Files**: Load the previous and current sitemap markdown files into strings. 2. **Compare Sitemaps**: Use `DiffHelper.CompareSitemapsWithErrors` to get a list of differences and an error flag. 3. **Process Differences**: Iterate through the returned differences and log them. 4. **Check for Errors**: Use the `hasErrors` flag to determine if critical changes (e.g., missing pages, new broken pages) have occurred. ### Output Examples - `"Missing: | `/old-page` | 200 | `/` |" - `"New: | `/new-page` | 404 | `/about` |" ### Error Conditions - Pages that existed in the previous report are now missing. - New pages introduced have status codes of 400 or higher. ### Code Example ```csharp using LinkValidator.Util; string previousSitemap = await File.ReadAllTextAsync("baseline.md"); string currentSitemap = await File.ReadAllTextAsync("current.md"); var (differences, hasErrors) = DiffHelper.CompareSitemapsWithErrors(previousSitemap, currentSitemap); foreach (var diff in differences) { Console.WriteLine(diff); // Output examples: // "Missing: | `/old-page` | 200 | `/` |" // "New: | `/new-page` | 404 | `/about` |" } if (hasErrors) { // hasErrors is true when: // - Pages that existed before are now missing // - New pages have status codes >= 400 Environment.Exit(1); } ``` ``` -------------------------------- ### GitHub Actions: Advanced Link Validation with Baseline Source: https://context7.com/aaronontheweb/link-validator/llms.txt An advanced GitHub Actions workflow for link validation that includes baseline comparison to detect regressions. It handles authentication, downloads a baseline sitemap, performs validation, and uploads artifacts for both PRs and baselines. ```yaml name: Advanced Link Validation on: push: branches: [ main ] pull_request: branches: [ main ] jobs: validate-links: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install LinkValidator run: | curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/main/install.sh | bash echo "$HOME/.linkvalidator" >> $GITHUB_PATH - name: Get Auth Cookie run: curl -c cookies.txt -L -s http://localhost:5000/dev-login - name: Download Baseline if: github.event_name == 'pull_request' run: gh run download --name sitemap-baseline --repo ${{ github.repository }} || echo "No baseline" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Validate Links run: | if [ -f "baseline-sitemap.md" ] && [ "${{ github.event_name }}" == "pull_request" ]; then link-validator --url http://localhost:3000 \ --output current-sitemap.md \ --diff baseline-sitemap.md \ --cookie-file cookies.txt \ --strict else link-validator --url http://localhost:3000 \ --output sitemap.md \ --cookie-file cookies.txt \ --strict fi - name: Upload Artifact if: always() uses: actions/upload-artifact@v4 with: name: sitemap-${{ github.event_name == 'pull_request' && 'pr' || 'baseline' }} path: "*.md" ``` -------------------------------- ### Save results and enable strict mode Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Command to save crawl results to a markdown file and enable strict mode, suitable for CI environments. ```bash link-validator --url https://example.com --output sitemap.md --strict ``` -------------------------------- ### Configure Retry Behavior for LinkValidator Source: https://context7.com/aaronontheweb/link-validator/llms.txt Customize retry settings for external links returning 429 errors using CLI flags or environment variables. The tool respects Retry-After headers and adds jitter. ```bash # Custom retry settings via CLI flags link-validator --url https://example.com \ --max-external-retries 5 \ --retry-delay-seconds 30 ``` ```bash # Custom retry settings via environment variables export LINK_VALIDATOR_MAX_EXTERNAL_RETRIES=5 export LINK_VALIDATOR_RETRY_DELAY_SECONDS=15 link-validator --url https://example.com --strict ``` -------------------------------- ### Compare crawl results with LinkValidator Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md Command to compare current crawl results against a previous run, outputting differences to a new markdown file. ```bash link-validator --url https://example.com --output new-sitemap.md --diff old-sitemap.md --strict ``` -------------------------------- ### CircleCI Workflow Definition Source: https://github.com/aaronontheweb/link-validator/blob/dev/docs/cicd-integration.md Defines a CircleCI workflow named 'build_and_validate' that orchestrates the execution of 'install_linkvalidator', 'build_site', and 'validate_links' jobs in sequence. ```yaml workflows: version: 2 build_and_validate: jobs: - install_linkvalidator - build_site - validate_links: requires: - install_linkvalidator - build_site ``` -------------------------------- ### GitHub Actions Advanced Link Validation Source: https://github.com/aaronontheweb/link-validator/blob/dev/docs/cicd-integration.md A comprehensive workflow featuring baseline sitemap comparison, retry logic, and automated PR commenting on failure. ```yaml name: Advanced Link Validation on: push: branches: [ main ] pull_request: branches: [ main ] jobs: validate-links: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Install LinkValidator run: | curl -fsSL https://raw.githubusercontent.com/Aaronontheweb/link-validator/main/install.sh | bash echo "$HOME/.linkvalidator" >> $GITHUB_PATH - name: Build Site run: | # Your site build process here npm install npm run build npm run serve & sleep 10 - name: Download baseline sitemap if: github.event_name == 'pull_request' run: | # Download baseline from main branch artifact gh run download --name sitemap-baseline --repo ${{ github.repository }} || echo "No baseline found" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Validate Links run: | if [ -f "baseline-sitemap.md" ] && [ "${{ github.event_name }}" == "pull_request" ]; then # Compare against baseline for PRs link-validator --url http://localhost:3000 \ --output current-sitemap.md \ --diff baseline-sitemap.md \ --strict \ --max-external-retries 3 \ --retry-delay-seconds 5 else # Just validate for main branch pushes link-validator --url http://localhost:3000 \ --output sitemap.md \ --strict fi - name: Upload sitemap artifact if: always() uses: actions/upload-artifact@v4 with: name: sitemap-${{ github.event_name == 'pull_request' && 'pr' || 'baseline' }} path: | *.md - name: Comment PR with results if: failure() && github.event_name == 'pull_request' uses: actions/github-script@v7 with: script: | github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: '❌ Link validation failed! Check the workflow logs for details.' }) ``` -------------------------------- ### CLI Command: link-validator Source: https://github.com/aaronontheweb/link-validator/blob/dev/README.md The primary command-line interface for executing the link validation process. ```APIDOC ## CLI Command: link-validator ### Description Executes the link validation crawler on a target URL. ### Method CLI Execution ### Parameters #### Query Parameters - **--url** (string) - Required - The URL to crawl. - **--output** (string) - Optional - Path to save the sitemap report file. - **--diff** (string) - Optional - Path to a previous sitemap file for comparison. - **--strict** (boolean) - Optional - Return error code if broken links are found. - **--cookie-file** (string) - Optional - Path to a Netscape/Mozilla cookie file for authenticated crawling. - **--max-external-retries** (integer) - Optional - Max retries for external 429 responses (Default: 3). - **--retry-delay-seconds** (integer) - Optional - Default retry delay in seconds (Default: 10). - **--help** (flag) - Optional - Show help information. - **--version** (flag) - Optional - Show version information. ### Request Example link-validator --url http://localhost:3000 --strict --output report.md ```