jekyll-contentfyll 0.0.1 → 0.0.16

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
  SHA256:
3
- metadata.gz: d471451ee7a3599b365fff1038ad57d8ab61b901f3bd79c75f24f945ca66f56b
4
- data.tar.gz: 1d51a5db790bb412bf2eca46540a2153022f6c2ebc1570fb189321945ade624a
3
+ metadata.gz: e0bb26fc3a6acb4c2be62d5d93a949ee2619fb101ca7b4e83c399a2cc84db41d
4
+ data.tar.gz: 938bb7f8d0dc46613fe205fcae3daa735784c61fe6998c973643f40720733ac1
5
5
  SHA512:
6
- metadata.gz: ecae1f29cd289fbebadb80d02a0a406e1a491d04013b08c3f0afe488d0338d3d60b559a5c90c9a24728be6ffaccfe97a647ec8c5fb6f7ee48d24e27afaa41e0d
7
- data.tar.gz: 57b1d2838d6efbf6fee17fd17001391d815a6f72e0bb323af15335be11ccb04dd1260a1752ba063179dc8173a1a35a0ecd736f1869f48334ffba861976acc194
6
+ metadata.gz: 29391255ec6065df27564389a40087c9f3839a87b403e9e16dee644cab3e515f6773a8c0814c62958194cc04d929ca09131017a869520a99f09c83574022ab3e
7
+ data.tar.gz: c07d6d8b98f2ccb610fb362b1d19dedba289944dae65e6eea54ec0d5a29d3f0c12ba8df3bd7fb109e584f64097ae170258d7589c013a0690630dc82a5beed51e
data/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # Change Log
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Chance Griffin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # jekyll-contentfyll
@@ -1,5 +1,6 @@
1
- class JekyllContentfyll
2
- def self.hi
3
- puts "Hello world!"
4
- end
1
+ require 'jekyll-contentfyll/version'
2
+ require 'jekyll-contentfyll/helpers'
3
+
4
+ %w[fyll].each do |file|
5
+ require File.expand_path("jekyll/commands/#{file}.rb", File.dirname(__FILE__))
5
6
  end
@@ -0,0 +1,7 @@
1
+ module Jekyll
2
+ module Contentfyll
3
+ def self.time(&block)
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,101 @@
1
+ require 'contentful'
2
+
3
+ module Jekyll
4
+ module Contentfyll
5
+ # Importer class
6
+ #
7
+ # Entry fetching logic
8
+ class Importer
9
+ attr_reader :config
10
+
11
+ def initialize(jekyll_config)
12
+ @jekyll_config = jekyll_config
13
+ @config = jekyll_config.key?('contentful') ? jekyll_config['contentful'] : jekyll_config
14
+
15
+ end
16
+
17
+ def run
18
+ spaces.each do |name, options|
19
+ space_client = client(
20
+ value_for(options, 'space'),
21
+ value_for(options, 'access_token'),
22
+ value_for(options, 'environment'),
23
+ client_options(options.fetch('client_options', {}))
24
+ )
25
+
26
+ export_data(name, space_client, options)
27
+ end
28
+ end
29
+
30
+ def export_data(name, space_client, options)
31
+ entries = get_entries(space_client, options)
32
+
33
+ Jekyll.logger.info "Number of entries:"
34
+ Jekyll.logger.info entries.length
35
+ end
36
+
37
+ def value_for(options, key)
38
+ potential_value = options[key]
39
+ return ENV[potential_value.gsub('ENV_', '')] if !potential_value.nil? && potential_value.start_with?('ENV_')
40
+ potential_value
41
+ end
42
+
43
+ def spaces
44
+ config['spaces'].map(&:first)
45
+ end
46
+
47
+ def get_entries(space_client, options)
48
+ cda_query = options.fetch('cda_query', {})
49
+ Jekyll.logger.info options
50
+ return space_client.entries(cda_query) unless options.fetch('all_entries', false)
51
+
52
+ all = []
53
+ query = cda_query.clone
54
+ query[:order] = 'sys.createdAt' unless query.key?(:order)
55
+ num_entries = space_client.entries(limit: 1).total
56
+
57
+ page_size = options.fetch('all_entries_page_size', 1000)
58
+
59
+ Jekyll.logger.info num_entries
60
+ Jekyll.logger.info page_size
61
+ Jekyll.logger.info query
62
+
63
+ ((num_entries / page_size) + 1).times do |i|
64
+ query[:limit] = page_size
65
+ query[:skip] = i * page_size
66
+ page = space_client.entries(query)
67
+ page.each { |entry| all << entry }
68
+ end
69
+
70
+ all
71
+ end
72
+
73
+ def client(space, access_token, environment = nil, options = {})
74
+ options = {
75
+ space: space,
76
+ access_token: access_token,
77
+ environment: environment || 'master',
78
+ dynamic_entries: :auto,
79
+ raise_errors: true,
80
+ integration_name: 'jekyll',
81
+ integration_version: Jekyll::Contentfyll::VERSION
82
+ }.merge(options)
83
+
84
+ ::Contentful::Client.new(options)
85
+ end
86
+
87
+ private
88
+
89
+ def client_options(options)
90
+ options = options.each_with_object({}) do |(k, v), memo|
91
+ memo[k.to_sym] = v
92
+ memo
93
+ end
94
+
95
+ options.delete(:dynamic_entries)
96
+ options.delete(:raise_errors)
97
+ options
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module Contentfyll
3
+ VERSION = '0.0.5'.freeze
4
+ end
5
+ end
@@ -0,0 +1,55 @@
1
+ require 'jekyll-contentfyll/importer'
2
+
3
+ module Jekyll
4
+ # Module for Jekyll Commands
5
+ module Commands
6
+ # jekyll fyll Command
7
+ class Fyll < Command
8
+ def self.init_with_program(prog)
9
+ prog.command(:fyll) do |c|
10
+ c.syntax 'fyll [OPTIONS]'
11
+ c.description 'Imports data from Contentful'
12
+
13
+ options.each { |opt| c.option(*opt) }
14
+
15
+ add_build_options(c)
16
+
17
+ command_action(c)
18
+ end
19
+ end
20
+
21
+ def self.options
22
+ [
23
+ [
24
+ 'rebuild', '-r', '--rebuild',
25
+ 'Rebuild Jekyll Site after fetching data'
26
+ ]
27
+ ]
28
+ end
29
+
30
+ def self.command_action(command)
31
+ command.action do |args, options|
32
+ jekyll_options = configuration_from_options(options)
33
+ process args, options, jekyll_options
34
+ end
35
+ end
36
+
37
+ def self.process(_args = [], options = {}, config = {})
38
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
39
+ Jekyll.logger.info '... Fylling Content ...'
40
+
41
+ Jekyll::Contentfyll::Importer.new(config).run
42
+
43
+ ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
44
+ elapsed = ending - starting
45
+ Jekyll.logger.info '... Content Fylled ... '
46
+ Jekyll.logger.info elapsed
47
+
48
+ # return unless options['rebuild']
49
+
50
+ # Jekyll.logger.info 'Starting Jekyll Rebuild'
51
+ # Jekyll::Commands::Build.process(options)
52
+ end
53
+ end
54
+ end
55
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-contentfyll
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chance Griffin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-11 00:00:00.000000000 Z
11
+ date: 2021-05-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple hello world gem
14
14
  email: cbg@hey.com
@@ -16,7 +16,14 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - CHANGELOG.md
20
+ - LICENSE.txt
21
+ - README.md
19
22
  - lib/jekyll-contentfyll.rb
23
+ - lib/jekyll-contentfyll/helpers.rb
24
+ - lib/jekyll-contentfyll/importer.rb
25
+ - lib/jekyll-contentfyll/version.rb
26
+ - lib/jekyll/commands/fyll.rb
20
27
  homepage: https://rubygems.org/gems/jekyll-contentfyll
21
28
  licenses:
22
29
  - MIT