Skip to content

Commit 3aa0ecb

Browse files
committed
- rewrite output filenames
- warn on duplicate filenames - write list of links into html/links.txt
1 parent bb78130 commit 3aa0ecb

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

htmlify.p6

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,35 @@ use Perl6::Documentable::Registry;
2929
use Pod::Convenience;
3030
use Pod::Htmlify;
3131

32+
&spurt.wrap(sub (|c){
33+
state %seen-paths;
34+
die "{c[0]} got badchar" if c[0].contains(any(qw[\ % ? & = # + " ' : ~ < >]));
35+
note "duplicated path {c[0]}" if %seen-paths{c[0]}:exists;
36+
%seen-paths{c[0]}++;
37+
callsame
38+
});
39+
40+
my @__URLS;
41+
&url-munge.wrap(sub (|c){
42+
@__URLS.push: uri-unescape(c[0]);
43+
callsame
44+
});
45+
3246
use experimental :cached;
3347

48+
sub escape-filename($s is copy) {
49+
return $s if $s ~~ m{^ <[a..z]>+ '://'}; # bail on external links
50+
constant badchars = qw[$ / \ . % ? & = # + " ' : ~ < >];
51+
constant goodnames = badchars.map: '$' ~ *.uniname.subst(' ', '_', :g);
52+
constant length = badchars.elems;
53+
54+
loop (my int $i = 0;$i < length;$i++) {
55+
$s = $s.subst(badchars[$i], goodnames[$i], :g)
56+
}
57+
58+
$s
59+
}
60+
3461
my $type-graph;
3562
my %routines-by-type;
3663
my %*POD2HTML-CALLBACKS;
@@ -178,6 +205,8 @@ sub MAIN(
178205
if $sparse || !$search-file || !$disambiguation {
179206
say "This is a sparse or incomplete run. DO NOT SYNC WITH doc.perl6.org!";
180207
}
208+
209+
spurt('html/links.txt', @__URLS.sort.unique.join("\n"));
181210
}
182211

183212
my $precomp-store = CompUnit::PrecompilationStore::File.new(:prefix($?FILE.IO.parent.child("precompiled")));
@@ -221,14 +250,16 @@ sub process-pod-dir($dir, :&sorted-by = &[cmp], :$sparse, :$parallel) {
221250
for @pod-sources.kv -> $num, (:key($filename), :value($file)) {
222251
FIRST my @pod-files;
223252

224-
push @pod-files, start {
253+
# push @pod-files, start {
254+
push @pod-files, {
225255
printf "% 4d/%d: % -40s => %s\n", $num+1, $total, $file.path, "$kind/$filename";
226256
my $pod = extract-pod($file.path);
227257
process-pod-source :$kind, :$pod, :$filename, :pod-is-complete;
228258
}
229259

230260
if $num %% $parallel {
231-
await(@pod-files);
261+
# await(@pod-files);
262+
@pod-files>>.();
232263
@pod-files = ();
233264
}
234265

@@ -364,7 +395,9 @@ multi write-type-source($doc) {
364395
note "Type $podname not found in type-graph data";
365396
}
366397

367-
my $html-filename = "html" ~ $doc.url ~ ".html";
398+
my @parts = $doc.url.split('/', :v);
399+
@parts[*-1] = escape-filename @parts[*-1];
400+
my $html-filename = "html" ~ @parts.join('/') ~ ".html";
368401
my $pod-path = pod-path-from-url($doc.url);
369402
spurt $html-filename, p2h($pod, $what, pod-path => $pod-path);
370403
}
@@ -778,7 +811,8 @@ sub write-disambiguation-files() {
778811
});
779812
}
780813
my $html = p2h($pod, 'routine');
781-
spurt "html/$name.subst(/<[/\\]>/,'_',:g).html", $html;
814+
spurt "html/{escape-filename $name}.html", $html;
815+
# spurt "html/$name.subst(/<[/\\]>/,'_',:g).html", $html;
782816
}
783817
say '';
784818
}
@@ -896,7 +930,8 @@ sub write-kind($kind) {
896930
})
897931
);
898932
print '.';
899-
spurt "html/$kind/$name.subst(/<[/\\]>/,'_',:g).html", p2h($pod, $kind);
933+
# spurt "html/$kind/$name.subst(/<[/\\]>/,'_',:g).html", p2h($pod, $kind);
934+
spurt "html/$kind/{escape-filename $name}.html", p2h($pod, $kind);
900935
}
901936
say '';
902937
}
@@ -908,7 +943,7 @@ sub write-qualified-method-call(:$name!, :$pod!, :$type!) {
908943
@$pod,
909944
);
910945
return if $name ~~ / '/' /;
911-
spurt "html/routine/{$type}.{$name}.html", p2h($p, 'routine');
946+
spurt "html/routine/{escape-filename $type}.{escape-filename $name}.html", p2h($p, 'routine');
912947
}
913948

914949
sub highlight-code-blocks(:$use-inline-python = True) {

0 commit comments

Comments
 (0)