Skip to content

Commit

Permalink
fix: dead-link-checker can't find out dead links (#596) (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
xujiajiadexiaokeai authored May 30, 2022
1 parent f39dec2 commit d991eba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .dlc.json → .github/dead_link_check_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
},
{
"pattern": "^https://console.cloud.tencent.com/cos/bucket"
},
{
"pattern": "^#"
}
],
"replacementPatterns": [
Expand All @@ -33,6 +36,7 @@
"fallbackRetryDelay": "1s",
"aliveStatusCodes": [
200,
401
401,
403
]
}
2 changes: 1 addition & 1 deletion .github/workflows/dead-link-checker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
uses: actions/checkout@v2

- name: Install markdown-link-check
run: sudo npm install -g markdown-link-check@3.8.7
run: sudo npm install -g markdown-link-check@3

- name: Install and start docsify server
run: |
Expand Down
32 changes: 30 additions & 2 deletions etc/script/check-dead-link.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
#!/usr/bin/env bash

set -u

NC='\033[0m' # No Color
GREEN='\033[0;32m'
YELLOW='\033[0;33m'

for file in $(find . -name "*.md"); do
markdown-link-check -c .dlc.json -q "$file"
done
markdown-link-check -c .github/dead_link_check_config.json -q "$file" >> result.txt 2>&1
done

if [ -e result.txt ] ; then
cat result.txt
if grep -q "ERROR:" result.txt; then
echo -e "${YELLOW}=========================> MARKDOWN LINK CHECK RESULT<=========================${NC}"
printf "\n"
awk -F ' ' '/links checked/{sum+=$1}END{print "Total "sum" links checked.\n"}' result.txt
awk -F ' ' '/ERROR/{sum+=$2}END{print "[✖] Found "sum " dead links.\n"}' result.txt
echo -e "${YELLOW}=========================================================================${NC}"
exit 2
else
echo -e "${YELLOW}=========================> MARKDOWN LINK CHECK RESULT<=========================${NC}"
printf "\n"
awk -F ' ' '/links checked/{sum+=$1}END{print "Total "sum" links checked.\n"}' result.txt
echo -e "${GREEN}[✔] All links are good!${NC}"
echo -e "${YELLOW}=========================================================================${NC}"
fi
else
echo -e "${GREEN}No link need check!${NC}"
fi

0 comments on commit d991eba

Please sign in to comment.