Skip to content

Commit 911f8e2

Browse files
authored
Merge pull request gruntwork-io#19 from gruntwork-io/yori-markdown-link-check
Markdown link check
2 parents f6d9d62 + f0f78b6 commit 911f8e2

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

.pre-commit-hooks.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,11 @@
7474
entry: hooks/helmlint.sh
7575
language: script
7676
files: \.((ya?ml)|(tpl))$
77+
78+
- id: markdown-link-check
79+
name: markdown-link-check
80+
description: Run markdown-link-check to check all the relative and absolute links in markdown docs.
81+
entry: hooks/mdlink-check.sh
82+
language: script
83+
files: \.md$
84+
exclude: vendor\/.*$

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ supported hooks are:
1313
* **golint**: Automatically run `golint` on all Golang code (`*.go` files)
1414
* **yapf**: Automatically run [`yapf`](https://github.com/google/yapf) on all python code (`*.py` files).
1515
* **helmlint** Automatically run [`helm lint`](https://github.com/helm/helm/blob/master/docs/helm/helm_lint.md) on your
16-
helm charts.
16+
* **markdown-link-check** Automatically run [markdown-link-check](https://github.com/tcort/markdown-link-check) on
17+
markdown doc files.
1718

1819

1920

hooks/mdlink-check.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# OSX GUI apps do not pick up environment variables the same way as Terminal apps and there are no easy solutions,
6+
# especially as Apple changes the GUI app behavior every release (see https://stackoverflow.com/q/135688/483528). As a
7+
# workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here.
8+
export PATH=$PATH:/usr/local/bin
9+
10+
if ! command -v markdown-link-check; then
11+
>&2 echo "markdown-link-check is not available on this system."
12+
>&2 echo "Please install it by running 'npm install -g markdown-link-check'"
13+
exit 1
14+
fi
15+
16+
# This is the recommended way to set the project root for properly resolving absolute paths. See
17+
# https://github.com/tcort/markdown-link-check/issues/16 for more info.
18+
TMP_CONFIG="$(mktemp)"
19+
cat > "$TMP_CONFIG" <<EOF
20+
{
21+
"replacementPatterns": [
22+
{
23+
"pattern": "^/",
24+
"replacement": "file://$(pwd)/"
25+
}
26+
]
27+
}
28+
EOF
29+
30+
for file in "$@"; do
31+
markdown-link-check -c "$TMP_CONFIG" "$file"
32+
done

0 commit comments

Comments
 (0)