Skip to content

Commit

Permalink
chore: improve dead links check (#3040)
Browse files Browse the repository at this point in the history
* chore: remove unused check-docs.ts

* chore: update check-docs script

* also check relative links and achors using markdown-link-check
  (we didn't use it before because of the issue below,
  see: tcort/markdown-link-check#91)
* actually check for achor and relative link errors
  (previously the errors were ignored in the script)
* add else statement that logs if nothing was checked due to no changes

* chore: remove remark

now we check all the links with markdown-link-check
  • Loading branch information
Orzelius authored Jul 7, 2022
1 parent 9d431cb commit 4e7a479
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 623 deletions.
8 changes: 0 additions & 8 deletions markdown-link-check-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
{
"pattern": "^https://docs\\.github\\.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads$",
"reason": "Ignore this particular GitHub URL, it fails consistently with HTTP 403 code despite the link works fine"
},
{
"pattern": "^[^\/]+\/[^\/].*$|^\/[^\/].*$",
"reason": "Ignore relative paths. Those are handled by another tool due to: https://github.com/tcort/markdown-link-check/issues/65"
},
{
"pattern": "^#",
"reason": "Ignore relative paths. Those are handled by another tool due to: https://github.com/tcort/markdown-link-check/issues/65"
}
]
}
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@
"markdown-link-check": "^3.9.3",
"minimatch": "^3.0.4",
"minimist": "^1.2.6",
"npm-license-crawler": "^0.2.1",
"node-jsonl": "^0.1.0",
"npm-license-crawler": "^0.2.1",
"prettier": "^2.1.1",
"remark-cli": "^8.0.0",
"remark-validate-links": "^10.0.0",
"replace-in-file": "^6.0.0",
"semver": "^7.3.2",
"shx": "^0.3.2",
Expand Down
27 changes: 10 additions & 17 deletions scripts/check-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ git diff --quiet HEAD -- docs/ || (echo 'generated docs are not up-to-date! run
modified_docs=$(git diff --name-status master docs README.md) || true
modified_examples=$(git diff --name-status master examples | grep "examples.*\README.md$") || true

check_relative_links() {
./node_modules/.bin/remark --use validate-links --frail --quiet --no-stdout "$@"
}

error_in_external_links=false
check_external_links() {
found_dead_links=false
check_links() {
for file in $@; do
# markdown-link-check is configured to ignore relative links
./node_modules/.bin/markdown-link-check --config markdown-link-check-config.json $file || error_in_external_links=true
./node_modules/.bin/markdown-link-check --config markdown-link-check-config.json $file || found_dead_links=true
done
}

export -f check_relative_links
export -f check_external_links
export -f check_links

# Only check links if docs or examples were modified
if !([ -z "$modified_docs" ] && [ -z "$modified_examples" ]); then
Expand All @@ -31,18 +26,16 @@ if !([ -z "$modified_docs" ] && [ -z "$modified_examples" ]); then
examples=$(find examples -name 'README.md' -type f -not -path "*/.garden/*" -not -path "*/node_modules/*" | xargs)
readme="./README.md"

check_relative_links $docs
check_relative_links $examples
check_relative_links $readme

check_external_links $docs
check_external_links $examples
check_external_links $readme
check_links $readme
check_links $docs
check_links $examples

if $error_in_external_links; then
if $found_dead_links; then
echo ""
echo "Error: Dead links found. See the output above for details."
echo ""
exit 1
fi
else
echo "Skipping dead link check as docs or examples were not modified"
fi
130 changes: 0 additions & 130 deletions scripts/check-docs.ts

This file was deleted.

Loading

0 comments on commit 4e7a479

Please sign in to comment.