This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
oliverdavies.uk-old-sculpin/scripts/redirects.php

34 lines
604 B
PHP
Raw Normal View History

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