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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07a761de535b3fac30e81ce02879ccecad548aaa
4
- data.tar.gz: f7e388a44e4e543b30beca43b30b2d73d125999f
3
+ metadata.gz: f2643db2f14d425da768e96d073f13f14455f19c
4
+ data.tar.gz: ceb813fc819fffe7a647ebab3b964e2930739b55
5
5
  SHA512:
6
- metadata.gz: 55c498a11247a4179ecf9987af52a046327931449471a160bedeab72deff77c43d5ea0d93159e1ab6ed9e08989f9fdbb0283561520a08a1c05090a14e8c85076
7
- data.tar.gz: 09558c17f085b0d3ea750728bd6ca1f807dc6adc01fe594681cbc89cdb76c2d6a6d28e54bf048867bc2298493f205a26f68761ed46fe3a7e4ee34e58951f9445
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
@@ -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
- # load home config
38
- @parser.load(File.expand_path(HOME_CONFIG_FILE))
39
+ unless argv.include?("--no-rc")
40
+ # load home config
41
+ @parser.load(File.expand_path(HOME_CONFIG_FILE))
39
42
 
40
- # load local config
41
- @parser.load(File.expand_path(LOCAL_CONFIG_FILE))
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
@@ -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 = key
13
- @url = 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(/!\[.*?\]\((.+?)(?: \".*?\")?\)/).flatten
19
+ image_urls = markdown.scan(/!\[(.*?)\]\((.+?)(?: \".*?\")?\)/)
18
20
  image_urls.map do |image_url|
19
- new(key, image_url)
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, filename)
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|
@@ -1,4 +1,4 @@
1
1
  module QiitaExport
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
4
4
 
@@ -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/example.jpg' }
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
- ![foo.png](https://example.com/foo.png "foo.png")
45
- ![bar.png](https://example.com/bar.png)
46
+ ![foo.png](https://example.com/foo1234567.png "foo.png")
47
+ ![bar.png](https://example.com/bar8901234.png)
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/foo.png') }
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/bar.png') }
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.3
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-26 00:00:00.000000000 Z
11
+ date: 2016-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3