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

35 lines
658 B
PHP
Raw Normal View History

2015-08-07 00:47:27 +00:00
#!/usr/bin/env php
<?php
2015-08-07 21:22:56 +00:00
$csv = __DIR__ . '/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);
2015-08-07 06:01:37 +00:00
2015-08-09 19:47:06 +00:00
$filename = str_replace('/', '-', $data[0]);
2015-08-09 19:51:57 +00:00
file_put_contents("source/$filename.html", $output);
echo "Written to $filename.html\n";
2015-08-07 06:19:43 +00:00
}
2015-08-07 00:47:27 +00:00
}
}
fclose($handle);