3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Confluenceの記事をesa.ioに移行する方法

Posted at

概要

Confluenceからesaに移行したい!
でもConfluenceはjson exportなんて高度なことはできない!

ならparseすればいいじゃない。

ruby触ったことがほとんどないので好きなようにリファクタしてください。

手順

  1. Confluence記事をhtml exportする。
  2. esaのaccess_tokenを取得する
  3. 以下のgemを入れる。
gem "esa"
gem "nokogiri"
gem 'reverse_markdown'
  1. 以下のscriptを走らせる

コード

# ! /usr/bin/env ruby

require "nokogiri"
require "esa"
require "reverse_markdown"

client = Esa::Client.new(access_token: 'ここに発行したトークン', current_team: 'チーム名')

input = "/Users/hoge/落としてきた記事ディレクトリ/"
title_text = ""
body_text = ""
body_text_md = ""

Dir.glob("#{input}*.{html}"){ | file |
  doc = Nokogiri::HTML(open(file))

  doc.xpath('//head//title').each do |node|
    title_text = node.inner_text #記事タイトル
  end

  doc.search("//div[@id='main-content']").each do |node|
    body_text = node.inner_html #記事本文
    body_text_md = ReverseMarkdown.convert body_text #htmlをマークダウンに変換する
    body_text_md.lstrip #先頭の空文字を消す
  end

  #esaの/tempディレクトリに記事を作成
  client.create_post(
    name: title_text,
    category: "/temp",
    tag: "confluence",
    wip: false,
    body_md: body_text_md,
  )
}

問題点

  • Confluenceはテーブル内改行をしまくるのでテーブルが壊れる。
改行を`<br>`に置換して不要なスペースなどは削除するようにする。
  • 画像が見れない
記事データと一緒に落としてきてそれをみているがそのままだと画像が取れない。
一旦esaにあげる必要がある
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?