ブログをGhostに移行した

2014-08-31

Ghostを使いはじめた。

Ghostで記事書いてるとこ

Rubyでこんなスクリプト書いて、OctopressのMarkdownファイルからSQLiteにデータ移行した。

#!/bin/env ruby

require 'time'
require 'sqlite3'
require 'securerandom'

db = SQLite3::Database.new('/path/to/ghost/content/data/ghost.db')

Dir.glob('/path/to/octopress/source/_posts/*.markdown').each {|f|
  filename = File.basename(f)

  title = File.readlines(f).grep(/^title:/)[0].split('title:')[1].delete('"')
  slug = filename.slice(/\d{4}-\d{2}-\d{2}-(.*).markdown/, 1)
  date_string = filename.slice(/(\d{4}-\d{2}-\d{2})/)
  markdown = File.open(f).read
  uuid = SecureRandom.uuid

  stmt = db.prepare("INSERT INTO POSTS ( uuid, title, slug, status, markdown, author_id, created_at, created_by, published_at)
  VALUES ( ?, ?, ?, 'published', ?, 1, datetime(?), 1, datetime(?));")

  stmt.execute(uuid, title, slug, markdown, date_string, date_string)
}

そしてその後 https://github.com/jbrooksuk/OctoGhost というリポジトリを見つけた。もっと先に気づいてれば…

記事が増えないまま、こういう暇潰しばかりが増えていく。

Shinya Tsunematsu

a Software Engineer loves tech, curry, music, fitness.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.