Permalink
Browse files

blacksmith-apprentice 0.0.1

  • Loading branch information...
1 parent 6bd1046 commit 9e1a643dfa6ea37258cd710efbdb613af5e48efd @luk- committed Feb 2, 2012
Showing with 36 additions and 55 deletions.
  1. +22 −0 README.md
  2. +7 −4 lib.js → apprentice.js
  3. +2 −1 blogs.json
  4. +3 −2 config.json
  5. +0 −46 habari.js
  6. +2 −2 package.json
View
@@ -0,0 +1,22 @@
+#blacksmith-apprentice
+
+Migrate your posts from your current blog and into a [blacksmith](https://github.com/flatiron/blacksmith)-compatible format.
+
+Apprentice currently supports the following blogs:
+
+- wordpress
+- habari
+
+But adding support for [your current blog software] is as trivial as writing a MySQL query. Check out blogs.json for an idea of how to structure an apprentice-compatible query.
+
+##Usage
+
+1. Run `npm install blacksmith-apprentice`.
+2. Edit `config.json` to include your database details and its current blog engine.
+3. run `node apprentice.js`. Apprentice will create an output directory containing the blacksmith-formatted posts. These can be put in your blacksmith site's pages directory.
+4. These pages will be converted to HTML with your other posts next time you run `blacksmith generate`.
+
+**Notes**
+
+- Wordpress uses a `<!--more-->` tag to represent where the preview and rest of content are separated. Apprentice will change this to the blacksmith/wheat version, which is `##` in Markdown.
+- Apprentice does not transcode from HTML to Markdown, so if you use any HTML markup in your posts in [your current blog software], it will be unchanged. This shouldn't cause an issue for the Markdown -> HTML conversion that happens during `blacksmith generate`.
View
@@ -41,7 +41,7 @@ migration.create_query = function () {
console.error("error parsing blogs.json \n\n" + e);
}
- migration.query = blogs.habari.replace(/\[PREFIX\]/g, migration.db_config.table_prefix);
+ migration.query = blogs[migration.db_config.engine].replace(/\[PREFIX\]/g, migration.db_config.table_prefix);
migrate_steps.emit('query_ready', migration.query);
});
@@ -65,7 +65,7 @@ migration.migrate = function () {
res.forEach (function (val, key) {
- var dir_title = val.title.replace(/\'|\,|\./g, '');
+ var dir_title = val.title.toLowerCase().replace(/[^a-zA-Z0-9]+/g, '-');
mkdirp('./output/' + dir_title, function (err) {
if (err) throw err;
@@ -76,9 +76,12 @@ migration.migrate = function () {
"date": new Date(val.date * 1000).toISOString()
};
+
page = JSON.stringify(page);
- fs.writeFile('./output/' + dir_title + '/content.md', val.body, function (err) {
+ var content = val.body.replace("<!--more-->", "##");
+
+ fs.writeFile('./output/' + dir_title + '/content.md', content, function (err) {
if (err) throw err;
fs.writeFile('./output/' + dir_title + '/page.json', page, function (err) {
if (err) throw err;
@@ -90,4 +93,4 @@ migration.migrate = function () {
});
});
-}
+}
View
@@ -1,3 +1,4 @@
{
- "habari": "select posts.title, posts.pubdate as date, posts.content as body, users.username as author from [PREFIX]posts as posts left join [PREFIX]users as users on posts.user_id where posts.user_id = users.id"
+ "habari": "select posts.title, posts.pubdate as date, posts.content as body, users.username as author from [PREFIX]posts as posts, [PREFIX]users as users where posts.user_id = users.id",
+ "wordpress": "select posts.post_title as title, users.display_name as author, unix_timestamp(posts.post_date) as date, posts.post_content as body from [PREFIX]posts as posts, [PREFIX]users as users where posts.post_type='post' and posts.post_author = users.id"
}
View
@@ -1,7 +1,8 @@
{
+ "engine": "wordpress",
"db_host": "localhost",
"db_user": "root",
"db_pass": "",
- "db_name": "mtambo_habari",
- "table_prefix": "habari__"
+ "db_name": "database_name",
+ "table_prefix": "wp_"
}
View
@@ -1,46 +0,0 @@
-var mysql = require('mysql')
- , mkdirp = require('mkdirp')
- , fs = require('fs')
- , database = 'mtambo_habari';
-
-var client = mysql.createClient({
- user: 'root',
- password: '',
-});
-
-
-client.query('use mtambo_habari');
-
-
-var q = client.query('select title, pubdate, content from habari__posts order by pubdate', function(err, res, fields) {
-
- res.forEach (function (val, key, arr) {
-
- var dir_title = val.title.replace(/\s/g, '-').replace(/\'|\,|\./g, '');
-
- mkdirp('./output/' + dir_title, function (err) {
- if (err) {
- console.error(err);
- }
- else {
- var page = {
- "title": val.title,
- "author": "luke",
- "date": new Date (val.pubdate * 1000).toISOString()
- }
-
- page = JSON.stringify (page);
-
- fs.writeFile('./output/' + dir_title + '/content.md', val.content, function () {});
- fs.writeFile('./output/' + dir_title + '/page.json', page, function () {});
- }
- });
-
- });
-
- //fs.writeFile('posts.json', JSON.stringify(res), function() {
- // console.log('done');
- // client.end();
- //});
-});
-
View
@@ -1,5 +1,5 @@
{
- "name": "blacksmith-migrate",
+ "name": "blacksmith-apprentice",
"version": "0.0.1",
"author": "Luke Arduini <luke.arduini@me.com>",
"description": "blacksmith migration tool for blogs",
@@ -9,6 +9,6 @@
},
"license": "MIT",
"engines": {
- "node": ">=0.6.0"
+ "node": ">=0.6.x"
}
}

0 comments on commit 9e1a643

Please sign in to comment.