qiita-export 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/qiita-export/config.rb +12 -4
- data/lib/qiita-export/image.rb +20 -11
- data/lib/qiita-export/version.rb +1 -1
- data/spec/qiita-export/image_spec.rb +12 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2643db2f14d425da768e96d073f13f14455f19c
|
4
|
+
data.tar.gz: ceb813fc819fffe7a647ebab3b964e2930739b55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 357f1ede7cb38d312b07302de64b15744b0562e8b874688ac276ef2af361b512d7ad3d3f6fe5eb14caeb920763bb171af684fe8f150822eff114499a3fb0a39e
|
7
|
+
data.tar.gz: 6a96c26613fb1a7c197012beb9f7abfb2d8b3c87b8148e21620547dc95bca6b64a9c0c694fe04c844ae2aab5b24db68ab6e2a1fcf72bc257e3f11696f81cb82f
|
data/README.md
CHANGED
@@ -41,6 +41,8 @@ Usage: qiita-export [options]
|
|
41
41
|
-o, --output-dir=dirpath specify the full path of destination directory.
|
42
42
|
-a, --api-token=token specify API token for Qiita.
|
43
43
|
-e, --exclude-pattern=regexp specify the regexp pattern to exclude article title.
|
44
|
+
-g, --original-image-filename export by original image file name
|
45
|
+
--no-rc ignore .qiita-exportrc files.
|
44
46
|
```
|
45
47
|
|
46
48
|
## Contributing
|
data/lib/qiita-export/config.rb
CHANGED
@@ -32,13 +32,17 @@ module QiitaExport
|
|
32
32
|
opt.on('-o', '--output-dir=dirpath', 'specify the full path of destination directory.') { |v| @option[:'output-dir'] = v }
|
33
33
|
opt.on('-a', '--api-token=token', 'specify API token for Qiita.') { |v| @option[:'api-token'] = v }
|
34
34
|
opt.on('-e', '--exclude-pattern=regexp', 'specify the regexp pattern to exclude article title.') { |v| @option[:'exclude-pattern'] = v }
|
35
|
+
opt.on('-g', '--original-image-filename','export by original image file name') { |v| @option[:'original-image-filename'] = v }
|
36
|
+
opt.on('--no-rc', 'ignore .qiita-exportrc files.') { |v| @option[:'no-rc'] = v }
|
35
37
|
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
+
unless argv.include?("--no-rc")
|
40
|
+
# load home config
|
41
|
+
@parser.load(File.expand_path(HOME_CONFIG_FILE))
|
39
42
|
|
40
|
-
|
41
|
-
|
43
|
+
# load local config
|
44
|
+
@parser.load(File.expand_path(LOCAL_CONFIG_FILE))
|
45
|
+
end
|
42
46
|
|
43
47
|
# parse argv
|
44
48
|
@parser.parse!(argv)
|
@@ -116,6 +120,10 @@ module QiitaExport
|
|
116
120
|
@option[:comment]
|
117
121
|
end
|
118
122
|
|
123
|
+
def original_image_filename?
|
124
|
+
@option[:'original-image-filename']
|
125
|
+
end
|
126
|
+
|
119
127
|
def team_url?(url)
|
120
128
|
url !~ /^https?:\/\/qiita\.com/
|
121
129
|
end
|
data/lib/qiita-export/image.rb
CHANGED
@@ -4,22 +4,35 @@ require 'uri'
|
|
4
4
|
|
5
5
|
module QiitaExport
|
6
6
|
class Image
|
7
|
-
attr_reader :key, :url
|
7
|
+
attr_reader :key, :url, :filename, :org_filename
|
8
8
|
|
9
9
|
IMAGE_DIR = "images"
|
10
10
|
|
11
|
-
def initialize(key, url)
|
12
|
-
@key
|
13
|
-
@url
|
11
|
+
def initialize(key, url, filename, org_filename)
|
12
|
+
@key = key
|
13
|
+
@url = url
|
14
|
+
@filename = filename
|
15
|
+
@org_filename = org_filename
|
14
16
|
end
|
15
17
|
|
16
18
|
def self.extract_urls(key, markdown)
|
17
|
-
image_urls = markdown.scan(/!\[
|
19
|
+
image_urls = markdown.scan(/!\[(.*?)\]\((.+?)(?: \".*?\")?\)/)
|
18
20
|
image_urls.map do |image_url|
|
19
|
-
|
21
|
+
url = image_url[1]
|
22
|
+
filename = File.basename(url)
|
23
|
+
org_filename = if image_url[0].nil? || image_url[0].empty?
|
24
|
+
filename
|
25
|
+
else
|
26
|
+
image_url[0]
|
27
|
+
end
|
28
|
+
new(key, url, filename, org_filename)
|
20
29
|
end
|
21
30
|
end
|
22
31
|
|
32
|
+
def output_filename
|
33
|
+
Config.original_image_filename? ? @org_filename : @filename
|
34
|
+
end
|
35
|
+
|
23
36
|
def require_auth?
|
24
37
|
@url !~ /qiita-image-store.s3.amazonaws.com/
|
25
38
|
end
|
@@ -28,16 +41,12 @@ module QiitaExport
|
|
28
41
|
require_auth? ? Config.auth_header : Config.default_header
|
29
42
|
end
|
30
43
|
|
31
|
-
def filename
|
32
|
-
"#{File.basename(url)}"
|
33
|
-
end
|
34
|
-
|
35
44
|
def save(path)
|
36
45
|
image_dir = File.join(File.expand_path(path), IMAGE_DIR)
|
37
46
|
|
38
47
|
FileUtils.makedirs(image_dir) unless Dir.exists?(image_dir)
|
39
48
|
|
40
|
-
file_path = File.join(image_dir,
|
49
|
+
file_path = File.join(image_dir, output_filename)
|
41
50
|
|
42
51
|
open(file_path, 'wb') do |out|
|
43
52
|
open(@url, request_header) do |image|
|
data/lib/qiita-export/version.rb
CHANGED
@@ -5,13 +5,15 @@ require 'qiita-export'
|
|
5
5
|
|
6
6
|
describe QiitaExport::Image do
|
7
7
|
let(:valid_key) { '99999999999999999999' }
|
8
|
-
let(:valid_url) { 'http://qiita-image-store.s3.amazonaws.com/
|
8
|
+
let(:valid_url) { 'http://qiita-image-store.s3.amazonaws.com/2c8ab5c7-8903-b9c6-e08f-82c745a594e5.jpeg' }
|
9
|
+
let(:valid_filename) { '2c8ab5c7-8903-b9c6-e08f-82c745a594e5.jpeg' }
|
10
|
+
let(:valid_org_filename) { 'example.jpg' }
|
9
11
|
|
10
12
|
describe ".new" do
|
11
13
|
|
12
14
|
context "with arguments" do
|
13
15
|
let(:arguments) do
|
14
|
-
[valid_key, valid_url]
|
16
|
+
[valid_key, valid_url, valid_filename, valid_org_filename]
|
15
17
|
end
|
16
18
|
|
17
19
|
subject do
|
@@ -41,8 +43,8 @@ describe QiitaExport::Image do
|
|
41
43
|
let(:include_images) {
|
42
44
|
<<-"EOS"
|
43
45
|
## Example Markdown
|
44
|
-

|
47
|
+

|
46
48
|
EOS
|
47
49
|
}
|
48
50
|
|
@@ -63,9 +65,13 @@ describe QiitaExport::Image do
|
|
63
65
|
it { expect(subject).not_to be_empty }
|
64
66
|
it { expect(subject.length).to eq(2) }
|
65
67
|
it { expect(subject.first).to be_an_instance_of(QiitaExport::Image) }
|
66
|
-
it { expect(subject.first.url).to eq('https://example.com/
|
68
|
+
it { expect(subject.first.url).to eq('https://example.com/foo1234567.png') }
|
69
|
+
it { expect(subject.first.filename).to eq('foo1234567.png') }
|
70
|
+
it { expect(subject.first.org_filename).to eq('foo.png') }
|
67
71
|
it { expect(subject.last).to be_an_instance_of(QiitaExport::Image) }
|
68
|
-
it { expect(subject.last.url).to eq('https://example.com/
|
72
|
+
it { expect(subject.last.url).to eq('https://example.com/bar8901234.png') }
|
73
|
+
it { expect(subject.last.filename).to eq('bar8901234.png') }
|
74
|
+
it { expect(subject.last.org_filename).to eq('bar.png') }
|
69
75
|
end
|
70
76
|
|
71
77
|
context "when there is no image urls" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qiita-export
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shin Akiyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04
|
11
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|