Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown link check #19

Merged
merged 7 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@
entry: hooks/helmlint.sh
language: script
files: \.((ya?ml)|(tpl))$

- id: markdown-link-check
name: markdown-link-check
description: Run markdown-link-check to check all the relative and absolute links in markdown docs.
entry: hooks/mdlink-check.sh
language: script
files: \.md$
exclude: vendor\/.*$
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ supported hooks are:
* **golint**: Automatically run `golint` on all Golang code (`*.go` files)
* **yapf**: Automatically run [`yapf`](https://github.com/google/yapf) on all python code (`*.py` files).
* **helmlint** Automatically run [`helm lint`](https://github.com/helm/helm/blob/master/docs/helm/helm_lint.md) on your
helm charts.
* **markdown-link-check** Automatically run [markdown-link-check](https://github.com/tcort/markdown-link-check) on
markdown doc files.



Expand Down
32 changes: 32 additions & 0 deletions hooks/mdlink-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

set -e

# OSX GUI apps do not pick up environment variables the same way as Terminal apps and there are no easy solutions,
# especially as Apple changes the GUI app behavior every release (see https://stackoverflow.com/q/135688/483528). As a
# workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here.
export PATH=$PATH:/usr/local/bin

if ! command -v markdown-link-check; then
>&2 echo "markdown-link-check is not available on this system."
>&2 echo "Please install it by running 'npm install -g markdown-link-check'"
exit 1
fi

# This is the recommended way to set the project root for properly resolving absolute paths. See
# https://github.com/tcort/markdown-link-check/issues/16 for more info.
TMP_CONFIG="$(mktemp)"
cat > "$TMP_CONFIG" <<EOF
{
"replacementPatterns": [
{
"pattern": "^/",
"replacement": "file://$(pwd)/"
}
]
}
EOF

for file in "$@"; do
markdown-link-check -c "$TMP_CONFIG" "$file"
done