Skip to content

Commit ff7a225

Browse files
authored
Add workflow to check for internal links before publish (#82)
* Add workflow to check for internal links before publish Signed-off-by: Andy Piper <andypiper@users.noreply.github.com>
1 parent 9c10e43 commit ff7a225

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Check for internal (non-public) links
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- 'content/posts/**/*.md'
9+
pull_request:
10+
branches:
11+
- master
12+
paths:
13+
- 'content/posts/**/*.md'
14+
15+
jobs:
16+
check-internal-links:
17+
permissions:
18+
contents: read
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Check for internal-only links in posts
24+
run: bash scripts/check-internal-links.sh

scripts/check-internal-links.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
# check-internal-links.sh
3+
# Scans markdown files in content/posts/ for non-public links.
4+
# Exits with code 1 if any are found, 0 if clean.
5+
#
6+
# Usage:
7+
# ./scripts/check-internal-links.sh # scans all posts
8+
# ./scripts/check-internal-links.sh file.md ... # scans specific files
9+
10+
set -euo pipefail
11+
12+
INTERNAL_PATTERNS=(
13+
'notion\.so'
14+
'linear\.app'
15+
'figma\.com/file'
16+
)
17+
18+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
19+
20+
if [[ $# -gt 0 ]]; then
21+
files=("$@")
22+
else
23+
mapfile -t files < <(find "$REPO_ROOT/content/posts" -name "*.md" -type f)
24+
fi
25+
26+
found=0
27+
28+
for file in "${files[@]}"; do
29+
for pattern in "${INTERNAL_PATTERNS[@]}"; do
30+
matches=$(grep -En "$pattern" "$file" 2>/dev/null || true)
31+
if [[ -n "$matches" ]]; then
32+
echo "ERROR: internal pattern '$pattern' found in ${file}:"
33+
while IFS= read -r line; do
34+
echo " $line"
35+
done <<< "$matches"
36+
found=1
37+
fi
38+
done
39+
done
40+
41+
if [[ $found -eq 1 ]]; then
42+
echo ""
43+
echo "The above links are internal-only and must not be published."
44+
echo "Please remove or replace them before committing."
45+
exit 1
46+
fi
47+
48+
echo "OK: no internal-only links found."
49+
exit 0

0 commit comments

Comments
 (0)