From 65273a403e1f7c5684e8fdf183104b783a583413 Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Thu, 25 Jan 2018 16:23:02 -0800 Subject: [PATCH] Add script that generates moarvm.org/releases.html This reads docs/ChangeLog and requires the Text::Markdown Perl 5 module. --- docs/moarvm.org_releases.pl | 145 ++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 docs/moarvm.org_releases.pl diff --git a/docs/moarvm.org_releases.pl b/docs/moarvm.org_releases.pl new file mode 100644 index 0000000000..358d9fec5c --- /dev/null +++ b/docs/moarvm.org_releases.pl @@ -0,0 +1,145 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use utf8; +use feature qw(unicode_strings say); +use English '-no_match_vars'; +binmode STDOUT, ':encoding(UTF-8)'; +binmode STDERR, ':encoding(UTF-8)'; +use Text::Markdown 'markdown'; + +sub slurp { + my ($filename) = @_; + local $INPUT_RECORD_SEPARATOR = undef; + open my $fh, '<', $filename; + binmode $fh, ':encoding(UTF-8)'; + return <$fh>; +} +sub main { + my $ChangeLog = slurp 'docs/ChangeLog'; + $ChangeLog =~ s/(^\s*[^+].*?:\n[ ]*)([+])/$1\n$2/xmsg; + say beginning_text() . process_changelog(html_escape($ChangeLog)) . end_text(); +} +main(); +sub process_changelog { + my ($in) = @_; + my @release_html; + # Extracts the text from the 'New in XXXX.XX' to the next 'New in XXXX.XX' + # if there are no 'New in' left it extracts to the end of the document. + while ($in =~ s/(New in ([\d.]+)(.*?))(New in [\d.]+|$)/$4/s) { + my $sec = $3; + my $release = $2; + print STDERR "$release\n"; + my $md_obj = Text::Markdown->new; + my $mid = $md_obj->markdown($sec); +my $start = <<"END"; +
+
+

$release

+
+
+END + my $end = <<"END"; +

Download

+
+
+END + my $html = start_enclosing_text($release) . $mid . end_enclosing_text($release); + push @release_html, $html; + } + return join '', @release_html; +} +# Escapes &, < and > for html +sub html_escape { + my ($text) = @_; + $text =~ s/[&]/&/g; + $text =~ s/[<]/</g; + $text =~ s/[>]/>/g; + return $text; +} +# The text comes before every version +sub start_enclosing_text { + my ($release) = @_; + my $start = <<"END"; +
+
+

$release

+
+
+END + return $start; +} +# This text comes after every version +sub end_enclosing_text { + my ($release) = @_; + my $end = <<"END"; +

Download

+
+
+END + return $end; +} +# This text begins the html document (only used once). +sub beginning_text { + <<'END'; + + + + MoarVM - A VM for NQP and Rakudo Perl 6 + + + + + + + + + + +
+ + Fork me on GitHub + + + +END +} +# This text ends the html document (only used once). +sub end_text { +<<'END'; + + +
+ + + + + + + +END +}