oliverdavies.uk/scripts/redirects.php

38 lines
633 B
PHP
Raw Normal View History

2015-08-07 00:47:27 +00:00
#!/usr/bin/env php
<?php
$template = <<<EOS
---
layout: redirect
destination: %DESTINATION%
---
EOS;
$filename = dirname(__FILE__) . '/redirects.csv';
$row = 1;
if (($handle = fopen($filename, 'r')) !== FALSE) {
while (($data = fgetcsv($handle, filesize($filename))) !== FALSE) {
2015-08-07 06:01:37 +00:00
# if ($row == 1) {
# continue;
# }
2015-08-07 00:47:27 +00:00
$templateData = [
'%DESTINATION%' => $data[1],
2015-08-07 00:47:27 +00:00
];
$output = strtr($template, $templateData);
file_put_contents("source/{$data[0]}.html", $output);
echo "Written to {$data[0]}.html\n";
2015-08-07 06:01:37 +00:00
2015-08-07 00:47:27 +00:00
$row++;
}
}
fclose($handle);