Extract common code from scripts, add script to process post links, put links in list in top of post to allow links in excerpts

This commit is contained in:
2016-01-30 16:02:49 +00:00
parent 098debb80d
commit f503e8be6c
3 changed files with 94 additions and 69 deletions

20
_scripts/utilities.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
require __DIR__ . '/../_php/autoload.php';
use Symfony\Component\Yaml\Yaml;
function parseFile($sFile, &$aYaml, &$sContents = null) {
$sContents = file_get_contents($sFile);
$aContents = explode("\n", $sContents);
$aParts = explode('---', implode("\n", array_slice($aContents, 1)));
$aYaml = Yaml::parse(trim(str_replace(" - \n", null, current($aParts))));
$sContents = trim(implode('---', array_slice($aParts, 1)));
}
function writeFile($sFile, $aYaml, $sContents = null) {
file_put_contents($sFile, '---' . "\n" . yamlDump($aYaml) . '---' . "\n" . trim($sContents));
}
function yamlDump($aData) {
return str_replace("'", null, Yaml::dump($aData, 4, 2));
}