Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Check cross-references in repository documents

License

NotificationsYou must be signed in to change notification settings

serokell/xrefcheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build status

Xrefcheck is a tool for verifying local and external references in a repository's documentation that is quick, easy to setup, and suitable to be run on a CI pipeline.

Output sample

Motivation

As a project evolves, links in markdown documentation have a tendency to become broken. This is usually because:

  1. A file has been moved;
  2. A markdown header has been renamed;
  3. An external site has ceased to exist.

This tool will help you to keep references in order.You can runxrefcheck continuously in your CI pipeline,and it will let you know when it finds a broken link.

Aims

Comparing to alternative solutions, this tool tries to achieve the following points:

  • Quickness
    • References are verified in parallel.
    • References with the same target URI are only verified once.
    • It first attempts to verify external links with aHEAD request; only when that fails does it try aGET request.
  • Resilience
    • When you have many links to the same domain, the service is likely to start replying with "429 Too Many Requests".When this happens,xrefcheck will wait the requested amount of seconds before retrying.
  • Easy setup - no extra actions required, just runxrefcheck in the repository root.
  • Conservative verifier allows using this tool in CI, no false positives (e.g. on sites which require authentication) should be reported.

Features

  • Supports both GitHub and GitLab flavored markdown.
  • Supports Windows and Unix systems.
  • Supports relative and absolute local links.
  • Supports external links (http,https,ftp andftps).
  • Detects broken and ambiguous anchors in local links.
  • Integration with GitHub Actions.

Dependencies

Xrefcheck requires you to havegit version 2.18.0 or later in your PATH.

Usage

We provide the following ways for you to use xrefcheck:

  • GitHub Actions
  • Statically linked binaries, e. g. on Linux:
    mkdir -p bin/wget --quiet -O bin/xrefcheck https://serokell.gateway.scarf.sh/xrefcheck/latest/xrefcheck-x86_64-linuxchmod +x bin/xrefcheckbin/xrefcheck
  • Docker image
    docker pull serokell.docker.scarf.sh/serokell/xrefcheck
  • Building from source
  • Nix
    nix shell -f https://github.com/serokell/xrefcheck/archive/master.tar.gz -c xrefcheck

If none of those are suitable for you, please open an issue!

To find all broken links in a repository, simply runxrefcheck from its root folder:

xrefcheck

To also display a list of all links and anchors:

xrefcheck --verbose

For description of other options:

xrefcheck --help

To configurexrefcheck, run:

xrefcheck dump-config --type GitHub

This will create a.xrefcheck.yaml file with all the configurationoptions,here's an example.This file should be committed to your repository.

Build instructions

Runstack install to build everything and install the executable.If you wish to usecabal, you need to runstack2cabal first!

Run on Windows

On Windows, executable requires some dynamic libraries (DLLs).They are shipped together with executable inreleases page.If you have built executable from source usingstack install,those DLLs are downloaded by stack to a location that is not on%PATH% by default.There are several ways to fix this:

  • Add%LocalAppData%\Programs\stack\x86_64-windows\msys2-<...>\mingw64\bin to your PATH
  • runstack exec xrefcheck.exe -- <args> instead ofxrefcheck.exe <args>
  • add DLLs from archive from releases page to a folder containingxrefcheck.exe

FAQ

  1. How do I ignore specific files?

    • To ignore a specific file, you can either use the--ignore <glob pattern> command-line option,or theignore list in the config file. Linksto those files will be reported as errors, linksfrom those files will not be verified.
  2. How do I ignore specific links?

    • Add an entry to theignoreLocalRefsTo orignoreExternalRefsTo lists in the config file.
    • Alternatively, add a<!-- xrefcheck: ignore link --> annotation before the link:
      <!-- xrefcheck: ignore link-->Link to some[invalid resource](https://fictitious.uri/).
      A[valid link](https://www.google.com)followed by an<!-- xrefcheck: ignore link-->[invalid link](https://fictitious.uri/).
    • You can also use a<!-- xrefcheck: ignore paragraph --> annotation to ignore all links in a paragraph.
  3. How do I ignore all links from a specific markdown file?

    • Add a glob pattern to theignoreRefsFrom list in the config file.
    • Or add a<!-- xrefcheck: ignore all --> at the top of the file.
  4. How do I ignore all external links?

    • If you wish to ignore all http/ftp links, you can use--mode local-only.
  5. How doesxrefcheck handle links that require authentication?

    • It's common for projects to contain links to protected resources.By default, whenxrefcheck attempts to verify a link and is faced with a403 Forbidden or a401 Unauthorized, it assumes the link is valid.
    • This behavior can be disabled by settingignoreAuthFailures: false in the config file.
  6. How doesxrefcheck handle redirects?

    • The rules from the default configuration are as follows:

      • Permanent redirects (i.e. 301 and 308) are reported as errors.
      • There are no rules for other redirects, except for a special GitLab case, so they are assumed to be valid.
    • Redirect rules can be specified with theexternalRefRedirects parameter withinnetworking, which accepts an array ofrules with keysfrom,to,on andoutcome. The rule applied is the first one that matches withthefrom,to andon fields, if any, where

      • from is a regular expression, as inignoreExternalRefsTo, for the source link in a single redirection step. Its absence means thatevery link matches.
      • to is a regular expression for the target link in a single redirection step. Its absence also means that every link matches.
      • on acceptstemporary,permanent or a specific redirect HTTP code. Its absence also means thatevery response code matches.
      • Theoutcome parameter acceptsvalid,invalid orfollow. The last one follows the redirect by applying thesame configuration rules.

      For example, this configuration forbids 307 redirects to a specific domain and makes redirections from HTTP to HTTPS to be followed:

      externalRefRedirects:  - to: "https?://forbidden.com.*"    on: 307    outcome: invalid  - from: "http://.*"    to: "https://.*"    outcome: follow

      The first one applies if both of them match.

    • The number of redirects allowed in a single redirect chain is limited and can be configured with themaxRedirectFollows parameter, also withinnetworking. A number smaller than 0 disables the limit.

  7. How doesxrefcheck handle localhost links?

    • By default,xrefcheck will ignore links to localhost.
    • This behavior can be disabled by removing the corresponding entry from theignoreExternalRefsTo list in the config file.

Further work

  • Support link detection in different languages, not only Markdown.
    • Haskell Haddock is first in turn.

A comparison with other solutions

  • linky - a well-configurable verifier written in Rust, scans one specified file at a time and works well with system utilities likefind.This tool requires some configuring before it can be applied to a repository or added to CI.
  • awesome_bot - a solution written in Ruby that can be easily included in CI or integrated into GitHub.Its features include duplicated URLs detection, specifying allowed HTTP error codes and reporting generation.At the moment of writing, it scans only external references and checking anchors is not possible.
  • remark-validate-links andremark-lint-no-dead-urls - highly configurable JavaScript solution for checking local and external links respectively.It is able to check multiple repositories at once if they are gathered in one folder.Doesn't handle "429 Too Many Requests", so false positives are likely when you have many links to the same domain.
  • markdown-link-check - another checker written in JavaScript, scans one specific file at a time.Supportsmailto: link resolution.
  • url-checker - GitHub Action which checks external links in specified files.Does not check local links.
  • linkcheck - advanced site crawler, verifies links inHTML files. There are other solutions for this particular task which we don't mention here.

At the moment of writing, the listed solutions don't support ftp/ftps links.

Issue tracker

We use GitHub issues as our issue tracker.You can login using your GitHub account to leave a comment or create a new issue.

For Contributors

Please seeCONTRIBUTING.md for more information.

About Serokell

Xrefcheck is maintained and funded with ❤️ bySerokell.The names and logo for Serokell are trademark of Serokell OÜ.

We love open source software! Seeour other projects orhire us to design, develop and grow your idea!


[8]ページ先頭

©2009-2025 Movatter.jp