Optionally remove prefix from front of titles
This commit is contained in:
parent
b1f1a80500
commit
12a604d1b2
22
run.php
22
run.php
@ -4,11 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
$opts = getopt('o:', rest_index: $rest_index);
|
||||
$opts = getopt('o:t:', rest_index: $rest_index);
|
||||
$rest = array_slice($argv, $rest_index);
|
||||
|
||||
$gemlog_input_path = $rest[0] ?? null;
|
||||
$gemlog_output_path = $opts['o'] ?? null;
|
||||
$trim_prefix = $opts['t'] ?? null;
|
||||
|
||||
if (is_null($gemlog_input_path) || !file_exists($gemlog_input_path)) {
|
||||
throw new \Exception('Please provide an input gemlog file listing some articles. Got: ' . $gemlog_input_path);
|
||||
@ -27,7 +28,8 @@ $gemlog->load($gemlog_input_path);
|
||||
$titles = $gemlog->getTitles();
|
||||
|
||||
foreach ($titles as $title) {
|
||||
$article_path = $dir . '/' . $title . '.md';
|
||||
$encoded_title = str_replace('/', '%2F', $title);
|
||||
$article_path = $dir . '/' . $encoded_title . '.md';
|
||||
$article->load($article_path);
|
||||
$gemtext = $article->convert();
|
||||
|
||||
@ -35,13 +37,19 @@ foreach ($titles as $title) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sanitize_title = strtolower($title);
|
||||
$sanitize_title = str_replace([' ', ','], ['-'], $sanitize_title);
|
||||
$sanitize_title .= '.gmi';
|
||||
$sanitized_title = $title;
|
||||
|
||||
$output_path = $gemlog_output_path . '/' . $sanitize_title;
|
||||
if ($trim_prefix && strpos($sanitized_title, $trim_prefix) === 0) {
|
||||
$sanitized_title = substr($sanitized_title, strlen($trim_prefix));
|
||||
}
|
||||
|
||||
echo "Writing to ", $sanitize_title, "...\n";
|
||||
$sanitized_title = strtolower($sanitized_title);
|
||||
$sanitized_title = str_replace([' ', ','], ['-'], $sanitized_title);
|
||||
$sanitized_title .= '.gmi';
|
||||
|
||||
$output_path = $gemlog_output_path . '/' . $sanitized_title;
|
||||
|
||||
echo "Writing to ", $sanitized_title, "...\n";
|
||||
|
||||
$date = strtotime($article->getProperties()['date'] ?? null);
|
||||
if (empty($date)) {
|
||||
|
Loading…
Reference in New Issue
Block a user