Skip to content

Conversation

eshanrnh
Copy link
Contributor

@eshanrnh eshanrnh commented Sep 2, 2025

📋 Description

Adding Lychee to check for broken links in incoming PRs.

To test:

  1. Run the choco install lychee command on Windows PowerShell to install Lychee. You might want to check the command for the Linux machine.
  2. Verify install using lychee --version.
  3. Go to the local UmbracoDocs repo.
  4. Add a Lychee config file in .github/lychee.toml.
  5. Add .lycheeignore at the repo root.
  6. Test Lychee locally. From the repo root, run: lychee --config .github/lychee.toml --format json --output lychee_output_cm.json "16/umbraco-cms/**/*.md".
  7. To export to Excel:
$json = Get-Content lychee_output_cm.json | ConvertFrom-Json

# Function to flatten a map
function Flatten-Map($map, $statusType) {
    $list = @()
    foreach ($file in $map.PSObject.Properties.Name) {
        foreach ($link in $map.$file) {
            $list += [PSCustomObject]@{
                file         = $file
                url          = $link.url
                status       = $statusType
                redirect_url = if ($link.PSObject.Properties.Match('redirect_url')) { $link.redirect_url } else { $null }
                line         = if ($link.PSObject.Properties.Match('line')) { $link.line } else { $null }
                reason       = if ($link.PSObject.Properties.Match('reason')) { $link.reason } else { $null }
            }
        }
    }
    return $list
}

# Flatten each map
$success = Flatten-Map $json.success_map 'Success'
$errors  = Flatten-Map $json.error_map 'Error'
$excluded = Flatten-Map $json.excluded_map 'Excluded'

# Combine all
$allLinks = $success + $errors + $excluded

# Export to CSV
$allLinks | Export-Csv -Path lychee_links_cms.csv -NoTypeInformation
  1. The other 2 config files are for GitHub Actions. If you want to test, add those files to:
  • .github/lychee.toml
  • .github/workflows/check-broken-pr-links.yml
  1. Create a PR with the following use cases. If there are broken links, a comment should appear from [github-actions] listing the broken links, and the workflow should fail.
  • Clean file without broken links
  • File with broken internal or external links
  • File has only internal anchors
  • Redirects (301/302)
  • Any other

📎 Related Issues (if applicable)

✅ Contributor Checklist

I've followed the Umbraco Documentation Style Guide and can confirm that:

  • Code blocks are correctly formatted.
  • Sentences are short and clear (preferably under 25 words).
  • Passive voice and first-person language (“we”, “I”) are avoided.
  • Relevant pages are linked.
  • All links work and point to the correct resources.
  • Screenshots or diagrams are included if useful.
  • Any code examples or instructions have been tested.
  • Typos, broken links, and broken images are fixed.

Product & Version (if relevant)

Deadline (if relevant)

Anytime

📚 Helpful Resources

Copy link
Contributor

@sofietoft sofietoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So great to have a rule that checks for broken links!
I'm very excited to see how this will help us out 💪

I've made some suggestions to the YAML file.
See how a comment looks with the suggested changes here: sofietoft#91 (comment)

@eshanrnh
Copy link
Contributor Author

eshanrnh commented Sep 4, 2025

Thank you for testing it out and adding your suggestions, @sofietoft 🙌 The output message definitely looks fantastic, it's well-spaced and easy to read 💪

I've incorporated all your suggestions.

Copy link
Contributor

@sofietoft sofietoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Let's get this merged, so we can start informing contributors about potential broken links in their PRs 👏

@eshanrnh eshanrnh merged commit a9073fd into main Sep 4, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants