diff options
author | Matias Linares <matiaslina@gmail.com> | 2019-01-06 21:01:49 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@gmail.com> | 2019-01-06 21:01:49 -0300 |
commit | 7e48cfe9a4226599ea27da9adb85ab39618260b5 (patch) | |
tree | 7781d696a0072e096d70bbcc31cf8f0f8aa811d2 /bin/gen-doc.p6 | |
parent | 4f7a67d5fb82b4300e94c6df9933f07b9020ffeb (diff) | |
download | perl6-matrix-client-7e48cfe9a4226599ea27da9adb85ab39618260b5.tar.gz |
Add a little script to generate the doc page
Diffstat (limited to 'bin/gen-doc.p6')
-rw-r--r-- | bin/gen-doc.p6 | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/bin/gen-doc.p6 b/bin/gen-doc.p6 new file mode 100644 index 0000000..1e41aa8 --- /dev/null +++ b/bin/gen-doc.p6 @@ -0,0 +1,46 @@ +use v6; +use Pygments; + +my %*POD2HTML-CALLBACKS; +%*POD2HTML-CALLBACKS<code> = sub (:$node, :&default) { + Pygments.highlight($node.contents.join('\n'), "perl6", + :style(Pygments.style('emacs'))) +}; + +use Pod::To::HTML; +use Pod::Load; +use Template::Mustache; + +sub git-version { + run('git', 'tag', '-l', :out).out.lines.first +} +sub pods { dir('./docs', :test( *.IO.extension eq 'pod'|'pod6' )) } + +my $sidebar = pods.sort.map( + -> $p { + my $f = $p.IO.extension('html').basename; + "<li><a href='$f'>{$f.split('.').first.tc}</a></li>" + }); + +sub MAIN(:o(:$output-dir)?) { + $output-dir.IO.add('index.html').spurt( + Template::Mustache.render('./templates/index.mustache'.IO.slurp, + {version => git-version()})); + + pods.map( + -> $pod { + say "Generating html for $pod"; + next if $pod.IO.extension ne 'pod'|'pod6'; + my $html = pod2html( + load($pod.IO), + :templates<templates> + ); + + my $filename = $pod.IO.extension('html'); + my $output = $output-dir.defined ?? + $output-dir.IO.add($filename.basename) !! + $filename; + + spurt $output, $html; + }); +} |