oliverdavies.uk/scripts/redirects.php

35 lines
658 B
PHP
Raw Normal View History

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