blob: 4f03df369ea2bc7cbb054b1b056221867c077b19 (
plain) (
tree)
|
|
#!/usr/bin/env php
<?php
if (empty($argv[1])) {
exit;
}
// Gather arguments and join into title-cased string.
$title_words = array_map(
fn ($w): string => trim($w, ".:;()[]{}'\"<>,/?"),
array_slice($argv, 1)
);
// Generate HTML title.
$title = implode(' ', $title_words);
$title = "<h1>$title</h1>\n\n";
// Generate post filename/URL.
$filename = strtolower(implode('-', $title_words));
$date = date('Y-m-d');
$filename = "$date-$filename.php";
if (!$handle = fopen("./drafts/$filename", 'a')) {
fwrite(STDERR, "Cannot append to file: $filename\n");
exit;
}
if (fwrite($handle, $title) === false) {
fwrite(STDERR, "Cannot write contents to file: $filename\n");
exit;
}
printf("Created draft %s\n", $filename);
|