-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (82 loc) · 3.1 KB
/
Copy pathlychee.yml
File metadata and controls
105 lines (82 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Link Check
on:
push:
branches:
- 6x
- 7x
pull_request:
branches:
- 6x
- 7x
permissions:
contents: read
jobs:
links:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Normalize docs
run: |
set -euo pipefail
INPUT_DIR="docs"
OUTPUT_DIR=".docs-clean"
MEDIA_DIR="media"
MEDIA_OUT="${OUTPUT_DIR}/media"
# --- reset output dir -------------------------------------------
rm -rf "${OUTPUT_DIR}"
mkdir -p "${OUTPUT_DIR}"
# --- walk docs/, transform .md files into .docs-clean -----------
if [ -d "${INPUT_DIR}" ]; then
find "${INPUT_DIR}" -type f -name "*.md" -print0 | while IFS= read -r -d '' file; do
rel="${file#${INPUT_DIR}/}"
out="${OUTPUT_DIR}/${rel}"
mkdir -p "$(dirname "${out}")"
perl -CSD -pe '
BEGIN {
sub rewrite_link {
my ($link) = @_;
return $link unless defined $link && length $link;
# leave external / mailto links untouched
return $link if $link =~ m{^https?://} || $link =~ m{^mailto:};
# sponsor links -> harmless placeholder
#return "#" if $link =~ m{^/sponsors/};
my $out = $link;
# 1. root-relative path -> relative path
$out =~ s{^/+(.*)$}{../$1};
# 2. strip anchors
$out =~ s{^(?!https?://)([^#]*)#.*$}{$1};
# 3. .html -> no extension
$out =~ s{^(?!https?://)(.+)\.html$}{$1};
# 4. default to .md if no known extension
$out =~ s{^(?!https?://)(.+)(?<!\.(?:md|png|jpg|jpeg|gif|svg|webp|pdf|mp4))$}{$1.md};
# 5. collapse stray leading double slashes
$out =~ s{^//+}{/};
# 6. legacy media dir -> media/
$out =~ s{_media/}{media/}g;
return $out;
}
}
s{\]\(([^)]+)\)}{"](" . rewrite_link($1) . ")"}ge;
s{src=(["\x27])([^"\x27]+)\1}{"src=" . $1 . rewrite_link($2) . $1}ge;
s{href=(["\x27])([^"\x27]+)\1}{"href=" . $1 . rewrite_link($2) . $1}ge;
' "${file}" > "${out}"
done
fi
# --- copy root media/ -> .docs-clean/media -----------------------
if [ -d "${MEDIA_DIR}" ]; then
mkdir -p "${MEDIA_OUT}"
cp -a "${MEDIA_DIR}/." "${MEDIA_OUT}/"
fi
echo "OK: docs + root media -> .docs-clean"
- name: Run lychee
id: lychee
uses: lycheeverse/lychee-action@v2
with:
args: >
.docs-clean
--exclude '^https?://(www\.)?(twitter\.com|x\.com|instagram\.com|linkedin\.com)'
--exclude '/sponsors/'
format: markdown
output: lychee-report.md
fail: true