jekyll-theme-open-project-helpers 1.0.5 → 1.0.6

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: 7f63b46564cc429a52480049af1d972a63a0ac845caebbeef39aff999f6fbd43
4
- data.tar.gz: 6ea1458978a4423864d31229ea8a6f38b4320005b280ae0791425ef63e23165d
3
+ metadata.gz: f5fd5decde1edbaf519bb5db108a98384d4c3638c1ecafd392ea0f684da92c71
4
+ data.tar.gz: 7cc6823120af4dd4147948d4410d0f282445c7ff61df0c84be53ad842f2b425b
5
5
  SHA512:
6
- metadata.gz: 057e49bf5d6cee6318e5240900f0a59e98f74654cdef1d7b643d5073f834d13759ab0e0b9fd4f718f19ca81fa5762f614bab1cf38e0ba0ef5f56cd5358114c48
7
- data.tar.gz: 2a7cbde88d5c9b607fc355397cf8f11a9d188ef5eb9cc9a4f0e6057d2b84f43727063f11aee7a3c4ff3a04dc605899bda6c8f28d94053a8a390066dab083fbec
6
+ metadata.gz: 3107adcca93d30676b5c72ec5925bb7de05b79cf431e388fd2052736d8dcdfe9b28c4a43cb8574d8707f60700880500c38bf43077083c333b8b685e73272a7c3
7
+ data.tar.gz: 582502b40a9d21e12af4def1e90a135c88bb0d62cc4a58deb0e0cccbca0d6e48367bf907ea8240a541c0d923f31a78c64f204b601c65e7648df37be75195deec
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'jekyll-theme-open-project-helpers'
5
- s.version = '1.0.5'
5
+ s.version = '1.0.6'
6
6
  s.authors = ['Ribose Inc.']
7
7
  s.email = ['open.source@ribose.com']
8
8
 
@@ -3,6 +3,8 @@ require 'fileutils'
3
3
  module Jekyll
4
4
  module OpenProjectHelpers
5
5
 
6
+ DEFAULT_DOCS_SUBTREE = 'docs'
7
+
6
8
  class CollectionDocReader < Jekyll::DataReader
7
9
 
8
10
  def read(dir, collection)
@@ -65,7 +67,7 @@ module Jekyll
65
67
 
66
68
  def fetch_hub_logo
67
69
  if @site.config.key? 'parent_hub' and @site.config['parent_hub'].key? 'git_repo_url'
68
- git_sparse_checkout(
70
+ git_shallow_checkout(
69
71
  File.join(@site.source, 'parent-hub'),
70
72
  @site.config['parent_hub']['git_repo_url'],
71
73
  ['assets/', 'title.html'])
@@ -80,7 +82,7 @@ module Jekyll
80
82
  project_indexes.each do |project|
81
83
  project_path = project.path.split('/')[0..-2].join('/')
82
84
 
83
- result = git_sparse_checkout(
85
+ result = git_shallow_checkout(
84
86
  project_path,
85
87
  project['site']['git_repo_url'],
86
88
  ['assets/', '_posts/', '_software/', '_specs/'])
@@ -96,46 +98,61 @@ module Jekyll
96
98
  end
97
99
  end
98
100
 
99
- def fetch_docs_for_item(item_doc)
100
- item_name = item_doc.id.split('/')[-1]
101
- docs_path = "#{item_doc.path.split('/')[0..-2].join('/')}/#{item_name}"
102
-
103
- return {
104
- :checkout_result => git_sparse_checkout(
105
- docs_path,
106
- item_doc['docs']['git_repo_url'],
107
- [item_doc['docs']['git_repo_subtree']]),
108
- :docs_path => docs_path,
109
- }
110
- end
111
-
112
101
  def fetch_and_read_docs_for_items(collection_name, index_collection_name=nil)
113
102
  # collection_name would be either software, specs, or (for hub site) projects
114
- # index_collection_name would be either software or specs
103
+ # index_collection_name would be either software, specs or (for project site) nil
115
104
 
116
105
  return unless @site.collections.key?(collection_name)
117
106
 
118
107
  index_collection_name = index_collection_name or collection_name
119
108
 
120
109
  entry_points = @site.collections[collection_name].docs.select do |doc|
121
- doc.data.key?('docs') and
122
- doc.data['docs']['git_repo_url']
110
+ doc.data['repo_url']
123
111
  end
112
+
124
113
  entry_points.each do |index_doc|
125
- result = fetch_docs_for_item(index_doc)
126
- index_doc.merge_data!({ 'last_update' => result[:checkout_result][:modified_at] })
114
+ item_name = index_doc.id.split('/')[-1]
115
+
116
+ if index_doc.data.key?('docs') and index_doc.data['docs']['git_repo_url']
117
+ docs_repo = index_doc.data['docs']['git_repo_url']
118
+ docs_subtree = index_doc.data['docs']['git_repo_subtree'] || DEFAULT_DOCS_SUBTREE
119
+ else
120
+ docs_repo = index_doc.data['repo_url']
121
+ docs_subtree = DEFAULT_DOCS_SUBTREE
122
+ end
127
123
 
128
- # Read all docs for hub site only when the repo is freshly initialized,
129
- # for project sites always. A workaround for #4 pending proper solution.
130
- if !@site.config['is_hub'] or result[:newly_initialized]
131
- CollectionDocReader.new(site).read(
132
- result[:docs_path],
133
- @site.collections[collection_name])
124
+ docs_path = "#{index_doc.path.split('/')[0..-2].join('/')}/#{item_name}"
125
+
126
+ begin
127
+ docs_checkout = git_shallow_checkout(docs_path, docs_repo, [docs_subtree])
128
+
129
+ # Read all docs for hub site only when the repo is freshly initialized,
130
+ # for project sites always. A workaround for #4 pending proper solution.
131
+ if !@site.config['is_hub'] or docs_checkout[:newly_initialized]
132
+ CollectionDocReader.new(site).read(
133
+ docs_checkout[:docs_path],
134
+ @site.collections[collection_name])
135
+ end
136
+
137
+ rescue
138
+ docs_checkout = nil
139
+
140
+ end
141
+
142
+ # Get last repository modification timestamp.
143
+ # Fetch the repository for that purpose,
144
+ # unless it’s the same as the repo where docs are.
145
+ if docs_checkout == nil or docs_repo != index_doc.data['repo_url']
146
+ repo_path = "#{index_doc.path.split('/')[0..-2].join('/')}/_#{item_name}_repo"
147
+ repo_checkout = git_shallow_checkout(repo_path, index_doc.data['repo_url'])
148
+ index_doc.merge_data!({ 'last_update' => repo_checkout[:modified_at] })
149
+ else
150
+ index_doc.merge_data!({ 'last_update' => docs_checkout[:modified_at] })
134
151
  end
135
152
  end
136
153
  end
137
154
 
138
- def git_sparse_checkout(repo_path, remote_url, subtrees)
155
+ def git_shallow_checkout(repo_path, remote_url, sparse_subtrees=[])
139
156
  # Returns hash with timestamp of latest repo commit
140
157
  # and boolean signifying whether new repo has been initialized
141
158
  # in the process of pulling the data.
@@ -155,19 +172,21 @@ module Jekyll
155
172
 
156
173
  repo.add_remote('origin', remote_url)
157
174
 
158
- repo.config('core.sparseCheckout', true)
175
+ if sparse_subtrees.size > 0
176
+ repo.config('core.sparseCheckout', true)
159
177
 
160
- FileUtils.mkdir_p File.join(git_dir, 'info')
161
- open(File.join(git_dir, 'info', 'sparse-checkout'), 'a') { |f|
162
- subtrees.each { |path| f << "#{path}\n" }
163
- }
178
+ FileUtils.mkdir_p File.join(git_dir, 'info')
179
+ open(File.join(git_dir, 'info', 'sparse-checkout'), 'a') { |f|
180
+ subtrees.each { |path| f << "#{path}\n" }
181
+ }
182
+ end
164
183
 
165
184
  else
166
185
  repo = Git.open(repo_path)
167
186
 
168
187
  end
169
188
 
170
- repo.fetch
189
+ repo.fetch('origin', { :depth => 1 })
171
190
  repo.reset_hard
172
191
  repo.checkout('origin/master', { :f => true })
173
192
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-theme-open-project-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-09 00:00:00.000000000 Z
11
+ date: 2018-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll