cyberia_uptime_party

Website of https://cyberia.uptime.party
git clone git://git.2f30.org/cyberia_uptime_party
Log | Files | Refs | README | LICENSE

write_servers.pl (883B)


      1 #!/usr/bin/env perl
      2 use strict;
      3 use warnings;
      4 use YAML::Tiny;
      5 use File::Slurp qw/read_file write_file/;
      6 
      7 my $ser = YAML::Tiny->read("servers.yml")->[0];
      8 my $html;
      9 
     10 for my $s (@{ $ser->{"servers"} }) {
     11 	$html .= "<tr><td>$s->{name}";
     12 
     13 	if (exists $s->{"note"}) {
     14 		$html .= note($s->{"note"});
     15 	}
     16 
     17 	$html .= "</td><td>";
     18 
     19 	if (exists $s->{"extra_addrs"}) {
     20 		my $first = 1;
     21 		for my $a (@{ $s->{"extra_addrs"} }) {
     22 			if (!$first) {
     23 				$html .= ", ";
     24 			} else {
     25 				$first = 0;
     26 			}
     27 
     28 			$html .= $a->{"addr"};
     29 
     30 			if (exists $a->{"note"}) {
     31 				$html .= note($a->{"note"});
     32 			}
     33 		}
     34 	} else {
     35 		$html .= "n/a";
     36 	}
     37 
     38 	$html .= "</td><td>$s->{admin_nick}</td><td>$s->{location}</td></tr>";
     39 }
     40 
     41 my $doc = read_file("servers_template.html");
     42 $doc =~ s/<!-- \{\{\{ SERVERS \}\}\} -->/$html/;
     43 write_file("htdocs/servers.html", $doc);
     44 
     45 sub note {
     46 	my $n = shift;
     47 	return " <em>($n)</em>";
     48 }