Skip to content
Open
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
36 changes: 36 additions & 0 deletions .github/workflows/link-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Link Validation (Weekly Check)

on:
schedule:
- cron: '0 6 * * 1' # Mondays at 06:00 UTC
workflow_dispatch: # Manual trigger

jobs:
validate-links:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Set up Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.2.0
with:
go-version: stable

- name: Set up mdox
run: |
go install github.com/bwplotka/mdox@latest
export PATH="$(go env GOPATH)/bin:$PATH"
echo "PATH=$PATH" >> $GITHUB_ENV

- name: Check for broken links (no file modification)
run: |
export PATH="$(go env GOPATH)/bin:$PATH"
md_files=$(find . -type d -name node_modules -prune -o -name '*.md' -print)
mdox fmt --links.validate --check $md_files > link-report.txt 2>&1 || true

- name: Upload link check report
uses: actions/upload-artifact@v4
with:
name: link-report
path: link-report.txt
25 changes: 25 additions & 0 deletions scripts/remove-broken-links.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -e

echo "Running link validation and removing broken links..."

# Run mdox and capture output
output=$(mdox fmt --links.validate --links.validate.config-file=.mdoxlintrc.yaml --check $(find . -name "*.md" -not -path "./node_modules/*" -not -path "./.next/*" -not -path "./.git/*") 2>&1 || true)

# Parse broken HTTP/HTTPS links and remove them
echo "$output" | grep -E '"https?://[^"]*" not accessible' | while read -r line; do
file=$(echo "$line" | cut -d: -f1)
url=$(echo "$line" | grep -oP '"https?://[^"]*"' | tr -d '"')

if [ -f "$file" ] && [ -n "$url" ]; then
echo "Removing broken link: $url from $file"
# Escape special characters for sed
escaped_url=$(echo "$url" | sed 's/[&/\]/\\&/g')
# Remove the link but keep the text if it's a markdown link [text](url)
sed -i -E "s|\[([^\]]*)\]\($escaped_url\)|\1|g" "$file"
# Remove plain URLs
sed -i "s|$escaped_url||g" "$file"
fi
done

echo "Broken link removal complete"