Created
September 14, 2011 15:54
-
-
Save itspriddle/1216939 to your computer and use it in GitHub Desktop.
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
| <?php | |
| // Usage: Drop this script in _import and then run `php import.php` | |
| // It will import posts from WordPress as markdown | |
| // EDIT THESE | |
| ini_set('date.timezone', 'America/New_York'); | |
| $con = mysql_connect('localhost', 'root', ''); | |
| $db = mysql_select_db('blog_test'); | |
| $q = mysql_query("SELECT * FROM blog_posts"); | |
| while ($post = mysql_fetch_array($q)) { | |
| $post_time = strtotime($post['post_date']); | |
| $content = "---\n"; | |
| $content .= "layout: post\n"; | |
| $content .= "date: ".date('D M j H:i:s O Y', $post_time)."\n"; | |
| $content .= "title: {$post['post_title']}\n"; | |
| $content .= "---\n\n"; | |
| $content .= $post['post_content']; | |
| $filename = date('Y-m-d', $post_time)."-{$post['post_name']}.markdown"; | |
| if (file_exists(realpath(dirname(__FILE__)). "/../_posts/{$filename}")) { | |
| echo "Not writing {$filename}, already imported\n"; | |
| } else { | |
| file_put_contents($filename, $content); | |
| echo "Wrote {$filename}!\n"; | |
| } | |
| } | |
| echo "Done!\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment