Last active
September 16, 2019 03:47
-
-
Save molovo/6907965 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 hidden or 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) { | |
$content = <<<EOD | |
--- | |
layout: post | |
title: "$post->title" | |
date: $post->created | |
categories: blog | |
--- | |
EOD; | |
$content .= $post->html; | |
$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
This is great, thank you.
I changed it slightly:
from
$content .= $post->html;
to
$content .= $post->markdown;
if you actually want the markdown and not the html inside the
.markdown
files.