Skip to content

Instantly share code, notes, and snippets.

@AntJanus
Forked from molovo/gist:6907965
Last active September 17, 2019 03:54
Show Gist options
  • Save AntJanus/390d56a28c2e7617c766c726478692e6 to your computer and use it in GitHub Desktop.
Save AntJanus/390d56a28c2e7617c766c726478692e6 to your computer and use it in GitHub Desktop.
A short snippet for exporting posts from Anchor CMS into separate .markdown files for use with Jekyll. Just add the created files straight into your _posts folder in jekyll. The following code goes into /anchor/routes/site.php, then just visit <site URL>/export to create the files
Route::get('export', function() {
$posts = Post::where('status', '=', 'published')->get();
foreach ($posts as $post) {
$category = Category::where('id', '=', $post->category)->get()[0]->title;
$content = <<<EOD
---
layout: post
title: "$post->title"
date: $post->created
categories: "$category"
---
EOD;
$content .= $post->markdown;
$title = substr($post->created, 0, 10) . '-' . $post->slug . '.markdown';
file_put_contents($title, $content);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment