summaryrefslogtreecommitdiff
path: root/mediawiki-matter
blob: 402e4309654b109b5b801c0d57b00abefe0850bd (plain)
  1. #!/usr/bin/perl
  2. # reorganize frontmatter
  3. use warnings;
  4. use strict;
  5. use Path::Tiny;
  6. use HTML::HTML5::Entities;
  7. my $infile = shift;
  8. my $outfile = shift || $infile;
  9. $_ = path($infile)->slurp_utf8;
  10. # swap sections → Copyright, TOC, Foreword, Preface
  11. s|^((?:.*?\n)?)(= Preface(?:(?!\n=).)*\n)(= Copyright(?:(?!\n=).)*\n)(= Table(?:(?!\n=).)*\n)(= Foreword(?:(?!\n=).)*\n)(=.*)$|$1$3$4$5$2$6|s;
  12. # drop section Copyright
  13. s|^((?:.*?\n)?)(= Copyright(?:(?!\n=).)*\n)(=.*)$|$1$3|s;
  14. path($outfile)->spew_utf8($_);
  15. 1;