File: check-links

package info (click to toggle)
nqp 2024.09%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,972 kB
  • sloc: java: 28,087; perl: 3,479; ansic: 451; makefile: 202; javascript: 68; sh: 1
file content (32 lines) | stat: -rwxr-xr-x 682 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env raku

# check the header links in docs/ops.markdown

# could be converted to a doc test, but needs some work

my %heads;
my %links;

for "docs/ops.markdown".IO.slurp.lines -> $line {

    if $line ~~ /^ '  * [' (.+) '](#' (.+) ')'/ { 
        %heads{~$/[0]} = ~$/[1];
    } elsif $line ~~ /^ '## ' (.*) / {
        my $a = ~$/[0].trim;
        next unless $a;
        $a = $a.subst(/ (' '|'`')+ /, '-', :global);
        $a ~~ s/ '-' $//;
        %links{$a}=1;
    }
}

for %heads.kv -> $k, $v {
    next if %links{$v};
    say "HEADER NO LINK: $k, $v"
}
my %tags = %heads.invert;

for %links.kv -> $k, $v {
    next if %tags{$k};
    say "LINK NO HEADER: $k, $v";
}