Created
August 16, 2017 22:03
-
-
Save danmayer/9629fa62e8e855472f5dc7dda1ac29bc to your computer and use it in GitHub Desktop.
convert a folder of markdown files to confluence wiki docs
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'confluence/api/client' | |
require 'kramdown' | |
username = '[email protected]' | |
password = 'your_pass' | |
url = 'https://your_co.atlassian.net/wiki' | |
space = 'DP' | |
# if you don't want your files at the root give a parent page to nest them under | |
parent_page_id = 5564541 | |
path = '/Users/danmayer/projects/DevDocuments' | |
original_root_path = 'https://github.com/OffgridElectric/DevDocuments/blob/master' | |
### | |
# see https://github.com/amishyn/confluence-api-client for usage | |
### | |
client = Confluence::Api::Client.new(username, password, url) | |
errors = [] | |
files = Dir.glob("#{path}/**/*") | |
converted = 0 | |
files.each do |file| | |
if file.to_s.match('.md') | |
converted += 1 | |
next if converted <= 3 | |
relative_path = file.to_s.gsub("#{path}/",'') | |
title = file.to_s.gsub("#{path}/",'').gsub('/','_').gsub('.md','') | |
content = File.read(file) | |
content += "\n\n\n [original document](#{original_root_path}/#{relative_path})" | |
html_content = Kramdown::Document.new(content).to_html | |
puts "creating #{title}" | |
page = client.create({type:"page", | |
title: title, | |
space: {key: space}, | |
ancestors:[{id: parent_page_id}], | |
body: {storage:{value: html_content, | |
representation: "storage"}}}) | |
errors << page if page['statusCode'].to_i > 200 | |
end | |
end | |
puts "converted #{converted}" | |
puts "errors:" | |
puts errors.inspect | |
puts 'done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment