mirror of https://github.com/captn3m0/outliner.git
[docker] Adds export and general re-org
- Move import script to exe/ - Fix httparty dependency being included in gemspec - Add license in Gemspec - Add .dockerignore
This commit is contained in:
parent
179e4aff01
commit
4bbc3d373a
|
@ -0,0 +1,10 @@
|
||||||
|
Dockerfile
|
||||||
|
CHANGELOG.md
|
||||||
|
CODE_OF_CONDUCT.md
|
||||||
|
Rakefile
|
||||||
|
test/
|
||||||
|
vendor/
|
||||||
|
vendor
|
||||||
|
test
|
||||||
|
*.gem
|
||||||
|
.git
|
|
@ -8,3 +8,4 @@
|
||||||
/tmp/
|
/tmp/
|
||||||
/vendor/
|
/vendor/
|
||||||
Gemfile.lock
|
Gemfile.lock
|
||||||
|
*.gem
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
FROM ruby:2.6-alpine
|
||||||
|
|
||||||
|
WORKDIR /outliner
|
||||||
|
COPY . /outliner/
|
||||||
|
|
||||||
|
RUN gem install bundler && \
|
||||||
|
bundle install
|
||||||
|
|
||||||
|
ENTRYPOINT ["/outliner/entrypoint.sh"]
|
46
README.md
46
README.md
|
@ -1,6 +1,6 @@
|
||||||
# Outliner [![Gem Version](https://badge.fury.io/rb/outliner.svg)](https://badge.fury.io/rb/outliner)
|
# Outliner [![Gem Version](https://badge.fury.io/rb/outliner.svg)](https://badge.fury.io/rb/outliner)
|
||||||
|
|
||||||
A simple HTTParty based wrapper for the [Outline API](https://www.getoutline.com/developers). It also offers a one-line import option to let you migrate an existing set of Markdown files to Outline.
|
A simple HTTParty based wrapper for the [Outline API](https://www.getoutline.com/developers). It also offers a one-line import option to let you migrate an existing set of Markdown files to Outline. For quickly running export/import commands, you can use the Docker Image as well.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ pp client.collections_list(offset: 0, limit: 10)
|
||||||
|
|
||||||
### Import
|
### Import
|
||||||
|
|
||||||
`outliner` can be used to import an existing collection of documents into Outline. To do this run:
|
`outliner` can be used to import an existing collection of documents into Outline. To do this, run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
export OUTLINE_BASE_URI="https://kb.example.com"
|
export OUTLINE_BASE_URI="https://kb.example.com"
|
||||||
|
@ -40,12 +40,50 @@ export OUTLINE_TOKEN="PUT YOUR TOKEN HERE"
|
||||||
export SOURCE_DIRECTORY="/home/user/wiki"
|
export SOURCE_DIRECTORY="/home/user/wiki"
|
||||||
export DESTINATION_COLLECTION_NAME="Archive"
|
export DESTINATION_COLLECTION_NAME="Archive"
|
||||||
bundle install outliner
|
bundle install outliner
|
||||||
bundle exec bin/import "$SOURCE_DIRECTORY" "$DESTINATION_COLLECTION_NAME"
|
outliner-import "$SOURCE_DIRECTORY" "$DESTINATION_COLLECTION_NAME"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Export
|
||||||
|
|
||||||
|
`outliner` can be used to run a one-time export of all documents in Outline to a local directory. To do this, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export OUTLINE_BASE_URI="https://kb.example.com"
|
||||||
|
export OUTLINE_TOKEN="PUT YOUR TOKEN HERE"
|
||||||
|
# Ensure that this exists and is writable
|
||||||
|
export DESTINATION_DIRECTORY="/data"
|
||||||
|
bundle install outliner
|
||||||
|
outliner-export "$DESTINATION_DIRECTORY"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker
|
||||||
|
|
||||||
|
You can use the pre-built docker image to run the above commands as well. See the following commands for examples:
|
||||||
|
|
||||||
|
### Export
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --env OUTLINE_BASE_URI="https://kb.example.com" \
|
||||||
|
--env OUTLINE_TOKEN="PUT YOUR TOKEN HERE" \
|
||||||
|
--volume /tmp:/data \
|
||||||
|
captn3m0/outliner \
|
||||||
|
export \
|
||||||
|
/data
|
||||||
|
```
|
||||||
|
|
||||||
|
### Import
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --env OUTLINE_BASE_URI="https://kb.example.com" \
|
||||||
|
--env OUTLINE_TOKEN="PUT YOUR TOKEN HERE" \
|
||||||
|
--volume /path/to/wiki:/data \
|
||||||
|
captn3m0/outliner \
|
||||||
|
import "/data" "Archive"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Limitations
|
#### Limitations
|
||||||
|
|
||||||
- Images are currently not imported
|
- Images are currently not imported. Host them externally for this to work.
|
||||||
- Only `.md` files are currently supported
|
- Only `.md` files are currently supported
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
echo "Please run with outliner [export|import] arguments"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
export)
|
||||||
|
shift
|
||||||
|
bundle exec outliner-export $@
|
||||||
|
;;
|
||||||
|
import)
|
||||||
|
shift
|
||||||
|
bundle exec outliner-import $@
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid command, please check README"
|
||||||
|
;;
|
||||||
|
esac
|
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require "bundler/setup"
|
||||||
|
require "outliner"
|
||||||
|
require 'tempfile'
|
||||||
|
|
||||||
|
def validate
|
||||||
|
unless (ARGV.size == 1) and Dir.exists?(ARGV[0]) and ENV.key?('OUTLINE_BASE_URI') and ENV.key?('OUTLINE_TOKEN')
|
||||||
|
puts "[E] Please call as `outliner-export directory`"
|
||||||
|
puts "[E] Please export OUTLINE_BASE_URI and OUTLINE_TOKEN environment variables"
|
||||||
|
puts "[E] OUTLINE_BASE_URI should not include /api"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Run validations
|
||||||
|
validate
|
||||||
|
|
||||||
|
# Setup variables
|
||||||
|
local_directory = ARGV[0]
|
||||||
|
CLIENT = Outliner::Client.new ENV['OUTLINE_BASE_URI']
|
||||||
|
|
||||||
|
# Download the complete zip
|
||||||
|
response = CLIENT.collections_exportAll(download: true)
|
||||||
|
|
||||||
|
# Extract it to a tempfle
|
||||||
|
file = Tempfile.new('download.zip')
|
||||||
|
File.open(file.path, 'w') { |file| file.write(response.body) }
|
||||||
|
|
||||||
|
`unzip -o "#{file.path}" -d "#{local_directory}"`
|
||||||
|
|
||||||
|
# Delete tempfile
|
||||||
|
file.unlink
|
|
@ -4,20 +4,11 @@ require "bundler/setup"
|
||||||
require "outliner"
|
require "outliner"
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
unless (ARGV.size == 2) and Dir.exists?(ARGV[0]) and ARGV[1].match(/\w+/) and ENV.key?('OUTLINE_BASE_URI')
|
unless (ARGV.size == 2) and Dir.exists?(ARGV[0]) and ARGV[1].match(/\w+/) and ENV.key?('OUTLINE_BASE_URI') and ENV.key?('OUTLINE_TOKEN')
|
||||||
puts "[E] Please call as import local_directory remote_collection_name"
|
puts "[E] Please call as `outliner-import local_directory remote_collection_name`"
|
||||||
puts "[E] Please export OUTLINE_BASE_URI and OUTLINE_TOKEN environment variables"
|
puts "[E] Please export OUTLINE_BASE_URI and OUTLINE_TOKEN environment variables"
|
||||||
puts "[E] OUTLINE_BASE_URI should not include /api"
|
puts "[E] OUTLINE_BASE_URI should not include /api"
|
||||||
end
|
exit 1
|
||||||
end
|
|
||||||
|
|
||||||
def find_or_create_collection(name)
|
|
||||||
collections = CLIENT.collections_list(limit: 100)['data']
|
|
||||||
collections.filter!{|c|c['name'] == name}
|
|
||||||
if collections.size >= 1
|
|
||||||
collections[0]['id']
|
|
||||||
else
|
|
||||||
CLIENT.collections_create(name: name, description: 'Imported Collection')['data']['id']
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,7 +54,7 @@ remote_collection_name = ARGV[1]
|
||||||
|
|
||||||
# Create a root collection
|
# Create a root collection
|
||||||
CLIENT = Outliner::Client.new ENV['OUTLINE_BASE_URI']
|
CLIENT = Outliner::Client.new ENV['OUTLINE_BASE_URI']
|
||||||
root_collection_id = find_or_create_collection(remote_collection_name)
|
root_collection_id = find_or_create_collection(CLIENT, remote_collection_name)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
create_documents_recursively(local_directory, root_collection_id)
|
create_documents_recursively(local_directory, root_collection_id)
|
|
@ -1,4 +1,5 @@
|
||||||
require "outliner/version"
|
require "outliner/version"
|
||||||
|
require "outliner/client"
|
||||||
|
|
||||||
module Outliner
|
module Outliner
|
||||||
class Error < StandardError; end
|
class Error < StandardError; end
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
module Outliner
|
||||||
|
class Helper
|
||||||
|
def find_or_create_collection(client, name)
|
||||||
|
collections = client.collections_list(limit: 100)['data']
|
||||||
|
collections.filter!{|c|c['name'] == name}
|
||||||
|
if collections.size >= 1
|
||||||
|
collections[0]['id']
|
||||||
|
else
|
||||||
|
client.collections_create(name: name, description: 'Imported Collection')['data']['id']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,3 +1,3 @@
|
||||||
module Outliner
|
module Outliner
|
||||||
VERSION = "0.1.1"
|
VERSION = "0.2.0"
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,13 +2,13 @@ lib = File.expand_path("lib", __dir__)
|
||||||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
||||||
|
|
||||||
require "outliner/version"
|
require "outliner/version"
|
||||||
require "outliner/client"
|
|
||||||
|
|
||||||
Gem::Specification.new do |spec|
|
Gem::Specification.new do |spec|
|
||||||
spec.name = "outliner"
|
spec.name = "outliner"
|
||||||
spec.version = Outliner::VERSION
|
spec.version = Outliner::VERSION
|
||||||
spec.authors = ["Nemo"]
|
spec.authors = ["Nemo"]
|
||||||
spec.email = ["rubygem.outliner@captnemo.in"]
|
spec.email = ["rubygem.outliner@captnemo.in"]
|
||||||
|
spec.licenses = ["MIT"]
|
||||||
|
|
||||||
spec.summary = "A simple HTTParty based client for outline knowledge base."
|
spec.summary = "A simple HTTParty based client for outline knowledge base."
|
||||||
spec.homepage = "https://github.com/captn3m0/outliner"
|
spec.homepage = "https://github.com/captn3m0/outliner"
|
||||||
|
@ -17,11 +17,8 @@ Gem::Specification.new do |spec|
|
||||||
spec.metadata["source_code_uri"] = "https://github.com/captn3m0/outliner"
|
spec.metadata["source_code_uri"] = "https://github.com/captn3m0/outliner"
|
||||||
spec.metadata["changelog_uri"] = "https://github.com/captn3m0/outliner/blob/master/CHANGELOG.md"
|
spec.metadata["changelog_uri"] = "https://github.com/captn3m0/outliner/blob/master/CHANGELOG.md"
|
||||||
|
|
||||||
# Specify which files should be added to the gem when it is released.
|
spec.files = Dir['**/*'].reject { |f| f.match(%r{^(vendor|test|spec|features)/}) }
|
||||||
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
||||||
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
||||||
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
||||||
end
|
|
||||||
spec.bindir = "exe"
|
spec.bindir = "exe"
|
||||||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
||||||
spec.require_paths = ["lib"]
|
spec.require_paths = ["lib"]
|
||||||
|
|
Loading…
Reference in New Issue