Skip to content

Instantly share code, notes, and snippets.

@opdavies
Created December 29, 2016 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opdavies/385f7254c3c2a49ef5118ca35f332709 to your computer and use it in GitHub Desktop.
Save opdavies/385f7254c3c2a49ef5118ca35f332709 to your computer and use it in GitHub Desktop.
<?php
require 'vendor/autoload.php';
use Symfony\Component\Finder\Finder;
// Find all posts.
$files = Finder::create()->files()->in('../source/_posts')->name('*.md');
foreach ($files as $file) {
$contents = file_get_contents($file->getPathname());
// Find the opening front matter tag.
$position = strpos($contents, '---', 3);
// Prepend the extra front matter to the second tag.
$contents = substr_replace($contents, "use: [posts]\n---", $position, 3);
file_put_contents($file->getPathname(), $contents);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment