Skip to content

Commit a4811a7

Browse files
committed
Create an index page
1 parent 65f731c commit a4811a7

File tree

1 file changed

+58
-7
lines changed

1 file changed

+58
-7
lines changed

htmlify.pl

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#!/usr/bin/env perl6
22
use v6;
3+
use Pod::To::HTML;
34

45
# this script isn't in bin/ because it's not meant
56
# to be installed.
67

8+
my %names;
9+
my %types;
710
my %routines;
811

912
sub MAIN($out_dir = 'html') {
1013
mkdir $out_dir unless $out_dir.IO ~~ :e;
14+
mkdir "$out_dir/type" unless "$out_dir/type".IO ~~ :e;
1115

1216
# TODO: be recursive instead
1317
my @source = dir('lib').grep(*.f).grep(rx{\.pod$});
@@ -16,12 +20,11 @@ ($out_dir = 'html')
1620

1721
for (@source) {
1822
my $podname = .basename.subst(rx{\.pod$}, '').subst(:g, '/', '::');
23+
# XXX just to speed stuff up for index creation debugging
1924
say "$_.path() => $podname";
20-
shell("perl6 --doc=HTML $_.path() > $out_dir/$podname.html");
21-
22-
# disable the rest of the processing for now, doesn't
23-
# really do anthing except burning CPU cycles
24-
next;
25+
%names{$podname}<type>.push: "/type/$podname";
26+
%types{$podname} = "/type/$podname";
27+
shell("perl6 --doc=HTML $_.path() > $out_dir/type/$podname.html");
2528

2629
shell("perl6 -Ilib --doc=Serialization $_.path() > $tempfile");
2730
# assume just one pod block for now
@@ -30,11 +33,17 @@ ($out_dir = 'html')
3033
:from({ $_ ~~ Pod::Heading and .level == 2}),
3134
:to({ $^b ~~ Pod::Heading and $^b.level <= $^a.level}),
3235
);
33-
for @chunks {
34-
say .perl;
36+
for @chunks -> $chunk {
37+
my $name = $chunk[0].content[0].content[0];
38+
next if $name ~~ /\s/;
39+
%names{$name}<routine>.push: "/type/$podname.html#$name";
40+
%routines{$name}.push: $chunk;
3541
}
3642
unlink $tempfile;
3743
}
44+
write-index-file($out_dir);
45+
# TODO: write per-routine docs
46+
# TODO: write top-level disambiguation files
3847
}
3948

4049
sub chunks-grep(:$from!, :&to!, *@elems) {
@@ -53,3 +62,45 @@ ($out_dir = 'html')
5362
take [@current] if @current;
5463
}
5564
}
65+
66+
sub write-index-file($out_dir) {
67+
my $pod = Pod::Block::Named.new(
68+
name => "pod",
69+
content => Array.new(
70+
Pod::Block::Named.new(
71+
name => "TITLE",
72+
content => Array.new(
73+
Pod::Block::Para.new(
74+
content => ["Perl 6 Documentation"],
75+
)
76+
)
77+
),
78+
Pod::Block::Para.new(
79+
content => ['Official Perl 6 documentation'],
80+
),
81+
# TODO: add more
82+
Pod::Heading.new(
83+
level => 1,
84+
content => Array.new(
85+
Pod::Block::Para.new(content => ["Types"])
86+
)
87+
),
88+
%types.sort.map: {
89+
Pod::Item.new(
90+
level => 1,
91+
content => [
92+
Pod::FormattingCode.new(
93+
type => 'L',
94+
content => [
95+
.key ~ '|' ~ .value;
96+
],
97+
),
98+
],
99+
),
100+
}
101+
)
102+
);
103+
my $file = open :w, "$out_dir/index.html";
104+
$file.print: pod2html($pod);
105+
$file.close;
106+
}

0 commit comments

Comments
 (0)