Last active
March 31, 2023 11:33
-
-
Save ThomasRettig/f22d6da858753e67ad39269ee9c81a99 to your computer and use it in GitHub Desktop.
A boilerplate HTML file generator written in Perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Term::ANSIColor; | |
my ($title, $num, $normalize) = @ARGV; | |
# Validate input | |
if (!$title || !$num || $normalize !~ /^(y|n)$/i) { | |
print color('bright_red'), "Usage: ", color('reset'), "$0 <filename> <number-of-files> <normalize[y/n]>\n"; | |
exit; | |
} | |
for (my $i = 1; $i <= $num; $i++) { | |
my $file_name = "${title}_${i}.html"; | |
open my $html_fh, '>', $file_name or die color('bright_red'), "Can't open file: $!", color('reset'); | |
print $html_fh <<~END_HTML; | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>$title</title> | |
<link rel="stylesheet" href="https://unpkg.com/normalize.css\@8.0.1/normalize.css"> | |
</head> | |
<body> | |
<h1>$title</h1> | |
</body> | |
</html> | |
END_HTML | |
close $html_fh; | |
print color('bright_green'), "Created file: ", color('reset'), "$file_name\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment