Merge branch 'feature/redirects'

This commit is contained in:
Oliver Davies 2015-08-07 07:32:32 +01:00
commit 7817c3d274
3 changed files with 39 additions and 4 deletions

5
scripts/redirects.csv Normal file
View file

@ -0,0 +1,5 @@
old,new
about,/
cv,https://gist.github.com/opdavies/d096d553b80140a342d4
portfolio,/
work,/
1 old new
2 about /
3 cv https://gist.github.com/opdavies/d096d553b80140a342d4
4 portfolio /
5 work /

34
scripts/redirects.php Normal file
View file

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

View file

@ -1,4 +0,0 @@
---
layout: redirect
destination: https://gist.github.com/opdavies/d096d553b80140a342d4
---