summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2023-05-09 21:50:57 -0400
committerAdam T. Carpenter <atc@53hor.net>2023-05-09 21:50:57 -0400
commit1cad49701f761143a623df207b1141e520250158 (patch)
tree85bdf5135917f1c624ac275d79b4f1289703b148
parent3c05423d34be7d85459c7491e613dbd2755fc645 (diff)
download53hor-1cad49701f761143a623df207b1141e520250158.tar.xz
53hor-1cad49701f761143a623df207b1141e520250158.zip
fix: simplify and fix up draft generator
-rwxr-xr-xscripts/new.php19
1 files changed, 3 insertions, 16 deletions
diff --git a/scripts/new.php b/scripts/new.php
index b746888..4f03df3 100755
--- a/scripts/new.php
+++ b/scripts/new.php
@@ -4,24 +4,11 @@ if (empty($argv[1])) {
exit;
}
-const exceptions = [
- "vs", "above", "across", "against", "at", "between", "by", "along", "among", "down", "in",
- "once", "around", "of", "off", "on", "to", "with", "before", "behind", "below", "beneath",
- "down", "from", "near", "toward", "upon", "within", "a", "an", "the", "and", "but", "for",
- "or", "nor", "so", "till", "when", "yet", "that", "than", "in", "into", "like", "onto", "over",
- "past", "as", "if"
-];
-
// Gather arguments and join into title-cased string.
-$title_words = array_slice($argv, 1);
$title_words = array_map(
- fn (string $word) => in_array($word, exceptions) ? lcfirst($word) : ucfirst($word),
- $title_words
+ fn ($w): string => trim($w, ".:;()[]{}'\"<>,/?"),
+ array_slice($argv, 1)
);
-$title_words[0] = ucfirst($title_words[0]);
-end($title_words);
-$key = key($title_words);
-$title_words[$key] = ucfirst($title_words[$key]);
// Generate HTML title.
$title = implode(' ', $title_words);
@@ -30,7 +17,7 @@ $title = "<h1>$title</h1>\n\n";
// Generate post filename/URL.
$filename = strtolower(implode('-', $title_words));
$date = date('Y-m-d');
-$filename = "$date-$filename.md";
+$filename = "$date-$filename.php";
if (!$handle = fopen("./drafts/$filename", 'a')) {
fwrite(STDERR, "Cannot append to file: $filename\n");