Skip to content

Commit

Permalink
Merge pull request #19 from gruntwork-io/yori-markdown-link-check
Browse files Browse the repository at this point in the history
Markdown link check
  • Loading branch information
yorinasub17 authored Feb 7, 2020
2 parents f6d9d62 + f0f78b6 commit 911f8e2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
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

0 comments on commit 911f8e2

Please sign in to comment.