distributed-press-api-client 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae448e05caf1d538ac277c028958db6d002f18d623940b34f107f9fffb9ceb69
4
- data.tar.gz: 52a18426f835670fd078cd73fd9aa65b0b3f18ec83d58f76dcf3dee0a79e7007
3
+ metadata.gz: c37544ed2afa25eb25880482b5882f197dd2eb7debf9db754cf7759e3d99fe26
4
+ data.tar.gz: f34ebb76bb1ce46164812ae1527202d888cb01a8bba51859f8100eebc71ba117
5
5
  SHA512:
6
- metadata.gz: 4bd3a517a48151f9e50ad237f694c936e8942177ef886aa244534e45212532655d09858f5912d51a8f9f841dfa6bbf074af84c34e3f1e70a9ab781b8a001f22f
7
- data.tar.gz: 3d012f7c84984cbb94f291aab7ea10ca0ce717ad9328042de8e07a84a9b8873bbe3ab38009e2fbb42f65714305ad5008997f01df776ad22056cacd09d3fc9b66
6
+ metadata.gz: 4576d6dfb4095303612df97b3a7a737f973ea0fa8f8c2d33c881eb642ecaae6dd477661173fd52cc1467cf786c82a45fc0cb1ca0b4b349e2d4cf3f9b42a5fd4c
7
+ data.tar.gz: 21afc0dd53b4e48246e75bf53499638821aad983c2120f63f5919e5ce2be3e200d877999f0dbd02ea833d8eaaa66edf363c77f1c00dcb56fadbff7286c5e71cf
data/README.md CHANGED
@@ -62,6 +62,13 @@ Build and publish site:
62
62
  JEKYLL_ENV=production DISTRIBUTED_PRESS_API_KEY=the_api_key bundle exec jekyll build
63
63
  ```
64
64
 
65
+ Other env vars:
66
+
67
+ ```bash
68
+ DISTRIBUTED_PRESS_PROJECT_DOMAIN=your.domain.at.distributed.press
69
+ DISTRIBUTED_PRESS_API_URL=https://api.distributed.press
70
+ ```
71
+
65
72
  ## Contributing
66
73
 
67
74
  Bug reports and pull requests are welcome on 0xacab.org at
@@ -10,7 +10,7 @@ class DistributedPress
10
10
  NEWLINE = "\r\n"
11
11
  BOUNDARY = '--'
12
12
 
13
- attr_reader :api_key, :project_domain
13
+ attr_reader :api_key, :project_domain, :configure_result, :publish_result
14
14
 
15
15
  # @param options [Hash]
16
16
  # @option options [String] :url API URL
@@ -40,9 +40,9 @@ class DistributedPress
40
40
  config.close
41
41
  end
42
42
 
43
- result = upload_io('/v0/publication/configure', stream)
43
+ @configure_result = upload_io('/v0/publication/configure', stream)
44
44
 
45
- result['errorCode'].zero?
45
+ configure_result['errorCode'].zero?
46
46
  end
47
47
 
48
48
  # Publishes a directory by tarballing it on the fly.
@@ -66,11 +66,11 @@ class DistributedPress
66
66
  body.close
67
67
  end
68
68
 
69
- result = upload_io '/v0/publication/publish', stream
69
+ @publish_result = upload_io '/v0/publication/publish', stream
70
70
 
71
71
  # wait
72
72
  thread.value
73
- result['errorCode'].zero?
73
+ publish_result['errorCode'].zero?
74
74
  end
75
75
  end
76
76
 
@@ -3,9 +3,40 @@
3
3
  require 'distributed_press'
4
4
 
5
5
  Jekyll::Hooks.register :site, :post_write, priority: :low do |site|
6
- next unless ENV['JEKYLL_ENV'] == 'production'
7
- if site.config['locales']
8
- next unless site.config['locale'] == site.config['locales'].last
6
+ def logger(message:, level: :info)
7
+ Jekyll.logger.public_send(level, 'Distributed Press:', message)
8
+ end
9
+
10
+ def warn(message)
11
+ logger level: :warn, message: message
12
+ end
13
+
14
+ def debug(message)
15
+ logger level: :debug, message: message
16
+ end
17
+
18
+ def info(message)
19
+ logger message: message
20
+ end
21
+
22
+ unless ENV['JEKYLL_ENV'] == 'production'
23
+ debug "Ignoring publication in #{ENV['JEKYLL_ENV']} mode"
24
+ next
25
+ end
26
+
27
+ # Compatibility with jekyll-locales, only publish on the last locale
28
+ dest = site.dest
29
+ locales_enabled = site.config['plugins'].include?('jekyll-locales')
30
+
31
+ if locales_enabled
32
+ if site.locales?
33
+ if site.locale != site.locales.last
34
+ info "Ignoring #{site.locale}"
35
+ next
36
+ else
37
+ dest = File.realpath(File.join(site.dest, '..'))
38
+ end
39
+ end
9
40
  end
10
41
 
11
42
  hostname = ENV['DISTRIBUTED_PRESS_PROJECT_DOMAIN']
@@ -14,12 +45,19 @@ Jekyll::Hooks.register :site, :post_write, priority: :low do |site|
14
45
 
15
46
  raise URI::Error unless hostname
16
47
 
17
- Jekyll.logger.info 'Distributed Press:', 'Publishing website'
48
+ info 'Publishing website'
18
49
 
19
- distributed_press = DistributedPress.new project_domain: hostname
20
- distributed_press.configure && distributed_press.publish(site.dest)
50
+ distributed_press = DistributedPress.new(url: ENV['DISTRIBUTED_PRESS_API_URL'], project_domain: hostname)
21
51
 
22
- Jekyll.logger.info 'Distributed Press:', 'Published!'
52
+ if distributed_press.configure
53
+ if distributed_press.publish(dest)
54
+ info 'Published!'
55
+ else
56
+ warn distributed_press.publish_result['error']
57
+ end
58
+ else
59
+ warn distributed_press.configure_result['error']
60
+ end
23
61
  rescue URI::Error
24
- Jekyll.logger.warn 'Distributed Press:', '`hostname` or `url` keys missing on _config.yml, skipping publication.'
62
+ warn '`hostname` or `url` keys missing on _config.yml, skipping publication.'
25
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: distributed-press-api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-06 00:00:00.000000000 Z
11
+ date: 2022-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -59,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 2.6.0
62
+ version: '2.7'
63
63
  required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ">="