diff --git a/scripts/add-matrix-org-stylings.pl b/scripts/add-matrix-org-stylings.pl new file mode 100755 index 000000000..af6ac8ded --- /dev/null +++ b/scripts/add-matrix-org-stylings.pl @@ -0,0 +1,71 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use File::Slurp qw/read_file/; + +if (scalar(@ARGV) < 1) { + die "Usage: $0 include_dir file_to_replace..."; +} + +my $include_dir = $ARGV[0]; +if (! -d $include_dir) { + die "'$include_dir' is not a directory"; +} + +my $header = read_file("${include_dir}/head.html"); +my $nav = read_file("${include_dir}/nav.html"); +my $footer = read_file("${include_dir}/footer.html"); + +$header .= "\n"; + +$nav = < +
+ $nav +
+
+
+EOT + +$footer = < +
+
+
+
+
+ $footer +
+ +EOT + +my $oldargv; +while(<>) { + if (!$oldargv || $ARGV ne $oldargv) { + # new file: open output file + unlink($ARGV); + open(ARGVOUT, ">", $ARGV); + select(ARGVOUT); + $oldargv = $ARGV; + } + + s//$&$header/; + + if (//) { + my $match = $&; + my $classes = "blog et_fixed_nav et_cover_background et_right_sidebar"; + if ($match =~ / class=/) { + $match =~ s/ class="([^"]*)"/ class="$1 $classes"/; + } else { + $match =~ s/>/ class=\"$classes\">/; + } + + s//$match$nav/; + } + + s##$footer$&#; + + print; +} diff --git a/scripts/add-matrix-org-stylings.sh b/scripts/add-matrix-org-stylings.sh deleted file mode 100755 index bc46637a5..000000000 --- a/scripts/add-matrix-org-stylings.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -eu - -if [[ $# == 0 || ! -d $1 ]]; then - echo >&2 "Usage: $0 include_dir file_to_replace..." - exit 1 -fi - -include_dir="$1" -shift - -HEADER="${include_dir}/head.html" -NAV_BAR="${include_dir}/nav.html" -FOOTER="${include_dir}/footer.html" - -for f in "${include_dir}"/{head,nav,footer}.html; do - if [[ ! -e "${f}" ]]; then - echo >&2 "Need ${f} to exist" - exit 1 - fi -done - -perl -MFile::Slurp -pi -e 'BEGIN { $header = read_file("'$HEADER'") } s##$header - -#' "$@" - -perl -MFile::Slurp -pi -e 'BEGIN { $nav = read_file("'$NAV_BAR'") } s## -
-
- $nav -
-
-
-#' "$@" - -perl -MFile::Slurp -pi -e 'BEGIN { $footer = read_file("'$FOOTER'") } s## -
-
-
-
-
-
- $footer -
- - #' "$@"