-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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