Skip to content

Instantly share code, notes, and snippets.

@molovo
Last active September 16, 2019 03:47
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save molovo/6907965 to your computer and use it in GitHub Desktop.
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
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);
}
});
@ham1
Copy link

ham1 commented Sep 27, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment