jekyll-spaceship 0.9.8 → 0.10.2

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: feae82926b331a1fc32b0ed226447d3d58b6721c7187035ae3d82f297970e979
4
- data.tar.gz: c34eef77784ba8087689780e75548318a91e188073995bbe0922d27abee1d0bc
3
+ metadata.gz: a416b7cf9c8e911656cded0ab54e172ef344f3efd767647c11357c40cc95733e
4
+ data.tar.gz: d0b73825b4ad8ef33b5cd39f34902159aa29110d36cf4a33b0989ea4aeecb30a
5
5
  SHA512:
6
- metadata.gz: b5e6ed122db069ffdc833eec1a360ee90257b356632ba4732a0b47a49a2ef9a41934d7e7de7eb23a03f61cf49d9347183d9d3cad88f1d9b6b79735cf100651a2
7
- data.tar.gz: 8fca41fbf22600014b6c5b87f31b31b744447854effdf0099d446293e78d032bbdcc102a222c58a9fd05c7dd7f6088cea28575181e2e337488bd993c23504f93
6
+ metadata.gz: eb35ba184747e58e6a5ab3d30f3140f347ed27729050a281da36dd72990cf63a3eed0a9a8c3058b4bf14f529ebfc9c318c2c0495ccec78145d86a786343dda49
7
+ data.tar.gz: 8ba26f392d63e59cbc7bab80849608cc723ee05839e3f696757e0a23664b5ec491251ff39dfdd11bc530833e07028413a94b3bfa0a1ff98211c2255400b6ccd5
data/README.md CHANGED
@@ -112,6 +112,7 @@ Spaceship is a minimalistic, powerful and extremely customizable [Jekyll](https:
112
112
  - [5.2 Vimeo Usage](#vimeo-usage)
113
113
  - [5.3 DailyMotion Usage](#dailymotion-usage)
114
114
  - [5.4 Spotify Usage](#spotify-usage)
115
+ - [5.4 Spotify Podcast Usage](#spotify-podcast-usage)
115
116
  - [5.5 SoundCloud Usage](#soundcloud-usage)
116
117
  - [5.6 General Video Usage](#general-video-usage)
117
118
  - [5.7 General Audio Usage](#general-audio-usage)
@@ -441,7 +442,7 @@ Code above would be parsed as:
441
442
  #### Cell Alignment
442
443
 
443
444
  Markdown table syntax use colons ":" for forcing column alignment.
444
- Therefore, here we also use it for foring cell alignment.
445
+ Therefore, here we also use it for forcing cell alignment.
445
446
 
446
447
  Table cell can be set alignment separately.
447
448
 
@@ -791,6 +792,15 @@ the link as below:
791
792
 
792
793
  <image width="600" src="https://user-images.githubusercontent.com/9413601/89762618-5d11b000-db23-11ea-81db-35cc3682b234.png">
793
794
 
795
+ #### Spotify Podcast Usage
796
+
797
+ ```markdown
798
+ ![](https://open.spotify.com/episode/31AxcwYdjsFtStds5JVWbT)
799
+ ```
800
+
801
+ <image width="600" src="https://user-images.githubusercontent.com/9413601/133599796-1d213033-8184-4059-9ec2-5415e50c94dc.png">
802
+
803
+
794
804
  #### SoundCloud Usage
795
805
 
796
806
  ```markdown
@@ -64,7 +64,10 @@ module Jekyll::Spaceship
64
64
  def self.load_config
65
65
  # post load site config for `group :jekyll_plugin`
66
66
  Jekyll::Hooks.register :site, :after_init do |site|
67
+ # load config
67
68
  self.load(site.config)
69
+ # dispatch site after_init event
70
+ Manager.dispatch(site, :site, :after_init)
68
71
  end
69
72
  end
70
73
  end
@@ -14,6 +14,7 @@ module Jekyll::Spaceship
14
14
  container = _register.first
15
15
  events = _register.last.uniq
16
16
  events = events.select do |event|
17
+ next true if event.match(/^after/)
17
18
  next true if event.match(/^post/)
18
19
  next events.index(event.to_s.gsub(/^pre/, 'post').to_sym).nil?
19
20
  end
@@ -57,23 +58,35 @@ module Jekyll::Spaceship
57
58
  end
58
59
 
59
60
  def self.dispatch(page, container, event)
61
+ # dispatch to each processor
60
62
  @@_processors.each do |processor|
61
63
  processor.dispatch page, container, event
64
+ break unless processor.next?
62
65
  end
63
66
  if event.to_s.start_with?('post') and Type.html? output_ext(page)
64
67
  self.dispatch_html_block(page)
65
68
  end
69
+ # update page excerpt
70
+ @@_processors.each do |processor|
71
+ next unless processor.handled
72
+ next unless page.is_a? Jekyll::Document
73
+ break page.data['excerpt'] = Jekyll::Excerpt.new(page)
74
+ end
75
+ # call on_handled
66
76
  @@_processors.each do |processor|
67
77
  processor.on_handled if processor.handled
78
+ break unless processor.next?
68
79
  end
69
80
  end
70
81
 
71
82
  def self.ext(page)
83
+ return unless page.respond_to? :path
72
84
  ext = page.path.match(/\.[^.]+$/)
73
85
  ext.to_s.rstrip
74
86
  end
75
87
 
76
88
  def self.output_ext(page)
89
+ return unless page.respond_to? :url_placeholders
77
90
  page.url_placeholders[:output_ext]
78
91
  end
79
92
 
@@ -90,6 +90,10 @@ module Jekyll::Spaceship
90
90
  def self.config
91
91
  end
92
92
 
93
+ def next?
94
+ true
95
+ end
96
+
93
97
  def process?
94
98
  Type.html?(output_ext) or Type.markdown?(ext)
95
99
  end
@@ -188,12 +192,28 @@ module Jekyll::Spaceship
188
192
  while @exclusion_store.size > 0
189
193
  match = @exclusion_store.pop
190
194
  id = @exclusion_store.size
191
- content = content.sub("<!JEKYLL@#{object_id}@#{id}>", match)
195
+ content = content.sub(
196
+ "<!JEKYLL@#{object_id}@#{id}>"
197
+ ) { match }
192
198
  end
193
199
  @exclusion_store = []
194
200
  content
195
201
  end
196
202
 
203
+ def get_exclusion(id)
204
+ result = nil
205
+ match_data = id.match /<!JEKYLL@(.+)@(.+)>/
206
+ unless match_data.nil?
207
+ id = match_data[2].to_i
208
+ result = {
209
+ :id => id,
210
+ :marker => match_data[0],
211
+ :content => @exclusion_store[id]
212
+ }
213
+ end
214
+ result
215
+ end
216
+
197
217
  def self.escape_html(content)
198
218
  # escape link
199
219
  content.scan(/((https?:)?\/\/\S+\?[a-zA-Z0-9%\-_=\.&;]+)/) do |result|
@@ -237,5 +257,31 @@ module Jekyll::Spaceship
237
257
  "<img class=\"#{css_class}\" src=\"#{body}\">"
238
258
  end
239
259
  end
260
+
261
+ def self.handle_bang_link(
262
+ content,
263
+ url = '(https?:)?\\/\\/.*',
264
+ title = '("(.*)".*){0,1}',
265
+ &block
266
+ )
267
+ # pre-handle reference-style links
268
+ regex = /(\[(.*)\]:\s*(#{url}\s*#{title}))/
269
+ content.scan regex do |match_data|
270
+ match = match_data[0]
271
+ ref_name = match_data[1]
272
+ ref_value = match_data[2]
273
+ content = content.gsub(match, '')
274
+ .gsub(/\!\[(.*)\]\s*\[#{ref_name}\]/,
275
+ "![\1](#{ref_value})")
276
+ end
277
+
278
+ # handle inline-style links
279
+ regex = /(\!\[(.*)\]\(.*#{url}\s*#{title}\))/
280
+ content.scan regex do |match_data|
281
+ url = match_data[2]
282
+ title = match_data[6]
283
+ block.call(url, title)
284
+ end
285
+ end
240
286
  end
241
287
  end
@@ -37,15 +37,31 @@ module Jekyll::Spaceship
37
37
  def emoji_filter(content, selector)
38
38
  # use nokogiri to parse html
39
39
  doc = Nokogiri::HTML(content)
40
+
40
41
  body = doc.at('body')
41
42
 
43
+ # in case of a page has no the body node, especially when your
44
+ # page's layout field of front matter is nil or unavailable
45
+ return content if body.nil?
46
+
47
+ # Count for restoration
48
+ escaped_count = 0
49
+
42
50
  # filter nodes (pre, code)
43
- nodes = body.css(selector)
44
- nodes.each do |node|
51
+ body.css(selector).each do |node|
52
+ count = escaped_count
53
+
45
54
  # handle emoji markup
46
- node.inner_html = node.inner_html.gsub(
47
- /:([\w\d+-]+?):/, '\:\1\:'
48
- )
55
+ inner_html = node.inner_html.gsub(
56
+ /(?<!\\):([\w\d+-]+?)(?<!\\):/
57
+ ) do |match|
58
+ escaped_count += 1
59
+ "\\:#{match[1..-2]}\\:"
60
+ end
61
+
62
+ if escaped_count > count
63
+ node.inner_html = inner_html
64
+ end
49
65
  end
50
66
 
51
67
  # parse the emoji
@@ -68,8 +84,10 @@ module Jekyll::Spaceship
68
84
 
69
85
  body.inner_html = content
70
86
 
87
+ return doc.to_html if escaped_count.zero?
88
+
71
89
  # restore nodes (pre, code)
72
- nodes.each do |node|
90
+ body.css(selector).each do |node|
73
91
  # handle emoji markup
74
92
  node.inner_html = node.inner_html.gsub(
75
93
  /\\:([\w\d+-]+?)\\:/, ':\1:'
@@ -45,6 +45,7 @@ module Jekyll::Spaceship
45
45
  escaped_expr = expr
46
46
  .gsub(/(?<!^)\\(?!\S$)/, '\\\\\\\\')
47
47
  .gsub(/(?<!\\)\$\$/, '\\\$\\\$')
48
+ .gsub(/\\\\(?=\s)/, '\\\\\\\\\\')
48
49
  .gsub(/\\ /, '\\\\\\ ')
49
50
  content = content.gsub(expr, escaped_expr)
50
51
  end
@@ -92,7 +93,7 @@ module Jekyll::Spaceship
92
93
  r&.each do |i|
93
94
  btag = Regexp.escape(i[0])
94
95
  etag = Regexp.escape(i[1])
95
- patterns <<= /((?<!\\\\)#{btag}(.*?)(?<!\\\\)#{etag})/
96
+ patterns <<= /((?<!\\\\)#{btag}([\s\S]*?)(?<!\\\\)#{etag})/
96
97
  end
97
98
  end
98
99
  end
@@ -107,17 +108,35 @@ module Jekyll::Spaceship
107
108
 
108
109
  def scan_mathjax_expression(doc, &block)
109
110
  patterns = get_math_patterns()
110
- doc.css('*').each do |node|
111
- next if ['code', 'pre', 'figure'].include? node.name
112
- next if node.ancestors('code, pre, figure').size > 0
113
- next if node.children.size > 1
114
- patterns['include'].each do |pattern|
115
- # check scripting mathjax expression
116
- if node.name == 'script'
117
- type = node['type']
118
- next unless type
119
- next unless type.match(/math\/tex/)
111
+ doc = doc.clone
112
+
113
+ # remove code, pre, figure nodes
114
+ doc.css('body code, body pre, body figure').each do |node|
115
+ node.remove
116
+ end
117
+
118
+ # remove scripting mathjax expression
119
+ doc.css('body script').each do |node|
120
+ next if node['type']&.match(/math\/tex/)
121
+ node.remove
122
+ end
123
+
124
+ # scan mathjax expressions
125
+ doc.css('body *').each do |node|
126
+ # filter invalid nodes
127
+ next if node.children.size == 0
128
+ invalid = false
129
+ node.children.each do |child|
130
+ unless [
131
+ 'text', 'br', 'span',
132
+ 'img', 'svg', 'a'
133
+ ].include? child.name
134
+ break invalid = true
120
135
  end
136
+ end
137
+ next if invalid
138
+
139
+ patterns['include'].each do |pattern|
121
140
  # check normal mathjax expression
122
141
  node.content.scan(pattern) do |result|
123
142
  expr = result[0]
@@ -30,6 +30,7 @@ module Jekyll::Spaceship
30
30
  handle_vimeo(element)
31
31
  handle_dailymotion(element)
32
32
  handle_spotify(element)
33
+ handle_spotify_podcast(element)
33
34
  handle_soundcloud(element)
34
35
  end
35
36
  doc.to_html
@@ -42,7 +43,7 @@ module Jekyll::Spaceship
42
43
  handle_media(element, {
43
44
  media_type: 'audio',
44
45
  host: '(https?:\\/\\/)?.*\\/',
45
- id: '(.+?\\.(mp3|wav|ogg|mid|midi|aac|wma))',
46
+ id: '(.+?\\.(mp3|wav|ogg|mid|midi|aac|wma))'
46
47
  })
47
48
  end
48
49
 
@@ -53,7 +54,7 @@ module Jekyll::Spaceship
53
54
  # ![video](//techslides.com/demos/sample-videos/small.mp4?width=400)
54
55
  def handle_normal_video(element)
55
56
  handle_media(element, {
56
- media_type: 'iframe',
57
+ media_type: 'video',
57
58
  host: '(https?:\\/\\/)?.*\\/',
58
59
  id: '(.+?\\.(avi|mp4|webm|ogg|ogv|flv|mkv|mov|wmv|3gp|rmvb|asf))'
59
60
  })
@@ -90,8 +91,8 @@ module Jekyll::Spaceship
90
91
  def handle_dailymotion(element)
91
92
  handle_media(element, {
92
93
  media_type: 'iframe',
93
- host: '(https?:)?\\/\\/.*dai.?ly.*',
94
- id: '(?<=video\\/|\\/)([a-zA-Z0-9\\_\\-]+)',
94
+ host: '(https?:)?\\/\\/(?>www\\.)?dai\\.?ly(?>motion\\.com\\/video)?\\/',
95
+ id: '([a-zA-Z0-9\\_\\-]+)',
95
96
  base_url: "https://www.dailymotion.com/embed/video/"
96
97
  })
97
98
  end
@@ -109,6 +110,19 @@ module Jekyll::Spaceship
109
110
  })
110
111
  end
111
112
 
113
+ # Examples:
114
+ # ![spotify podcast](//open.spotify.com/episode/31AxcwYdjsFtStds5JVWbT)
115
+ # ![spotify podcast](//open.spotify.com/episode/44gfWHnwbmSY7Euw6Nb39k?width=400)
116
+ def handle_spotify_podcast(element)
117
+ handle_media(element, {
118
+ media_type: 'iframe',
119
+ host: '(https?:)?\\/\\/open\\.spotify\\.com\\/episode\\/',
120
+ id: '(?<=episode\\/)([a-zA-Z0-9\\_\\-]+)',
121
+ base_url: "https://open.spotify.com/embed/episode/",
122
+ height: 152
123
+ })
124
+ end
125
+
112
126
  # Examples:
113
127
  # ![soundcloud](//soundcloud.com/aviciiofficial/preview-avicii-vs-lenny)
114
128
  def handle_soundcloud(element)
@@ -128,7 +142,7 @@ module Jekyll::Spaceship
128
142
  src = element.get_attribute('src')
129
143
  title = element.get_attribute('title')
130
144
  id = data[:id_from] === 'html' ? '()' : data[:id]
131
- match_data = src.match(/#{host}#{id}\S*/)
145
+ match_data = src&.match(/#{host}#{id}\S*/)
132
146
  return if match_data.nil?
133
147
 
134
148
  media_type = data[:media_type]
@@ -158,6 +172,10 @@ module Jekyll::Spaceship
158
172
  cfg['loop'] = qs['loop'] || data[:loop] || cfg['loop']
159
173
  cfg['style'] += ';display: none;' if qs['hidden']
160
174
  handle_audio(element, { cfg: cfg })
175
+ when 'video'
176
+ cfg['autoplay'] = qs['autoplay'] || data[:autoplay] || cfg['autoplay']
177
+ cfg['loop'] = qs['loop'] || data[:loop] || cfg['loop']
178
+ handle_video(element, { cfg: cfg })
161
179
  when 'iframe'
162
180
  cfg['title'] = title
163
181
  cfg['width'] = qs['width'] || data[:width] || cfg['width']
@@ -179,12 +197,32 @@ module Jekyll::Spaceship
179
197
  " src=\"#{cfg['src']}\""\
180
198
  " style=\"#{cfg['style']}\""\
181
199
  " controls>" \
182
- "<p> Your browser doesn't support HTML5 audio."\
200
+ " Your browser doesn't support HTML5 audio."\
183
201
  " Here is a <a href=\"#{cfg['src']}\">link to download the audio</a>"\
184
- "instead. </p>"\
202
+ " instead."\
185
203
  "</audio>"
186
- doc = Nokogiri::XML(html)
187
- element.replace(doc.children.first)
204
+ doc = Nokogiri::HTML(html)
205
+ return if element.parent.nil?
206
+ element.replace(doc.at('body').children.first)
207
+ end
208
+
209
+ def handle_video(element, data)
210
+ cfg = data[:cfg]
211
+ html = "<video"\
212
+ " id=\"#{cfg['id']}\""\
213
+ " class=\"#{cfg['class']}\""\
214
+ " style=\"#{cfg['style']}\""\
215
+ " #{cfg['autoplay'] ? 'autoplay' : ''}"\
216
+ " #{cfg['loop'] ? 'loop' : ''}"\
217
+ " controls>" \
218
+ " <source src=\"#{cfg['src']}\">" \
219
+ " Your browser doesn't support HTML5 video."\
220
+ " Here is a <a href=\"#{cfg['src']}\">link to download the video</a>"\
221
+ " instead."\
222
+ "</video>"
223
+ doc = Nokogiri::HTML(html)
224
+ return if element.parent.nil?
225
+ element.replace(doc.at('body').children.first)
188
226
  end
189
227
 
190
228
  def handle_iframe(element, data)
@@ -201,8 +239,9 @@ module Jekyll::Spaceship
201
239
  " frameborder=\"#{cfg['frameborder']}\""\
202
240
  " allowfullscreen>"\
203
241
  "</iframe>"
204
- doc = Nokogiri::XML(html)
205
- element.replace(doc.children.first)
242
+ doc = Nokogiri::HTML(html)
243
+ return if element.parent.nil?
244
+ element.replace(doc.at('body').children.first)
206
245
  end
207
246
 
208
247
  def get_id_from_html(url, pattern)
@@ -18,13 +18,21 @@ module Jekyll::Spaceship
18
18
  end
19
19
  if references.size > 0
20
20
  content.scan(/[^\n]*(?<!\\)\|[^\n]*/) do |result|
21
+ replace = result
21
22
  references.each do |key, val|
22
- replace = result.gsub(
23
- /\[([^\n\]]*?)\]\s*\[#{key}\]/,
24
- "[\1](#{val})")
25
- next if result == replace
26
- content = content.gsub(result, replace)
23
+ replace = replace.gsub(
24
+ /\[([^\n\]]*?)\]\s*\[#{Regexp.escape(key)}\]/,
25
+ "[\\1](#{val})"
26
+ )
27
27
  end
28
+ references.each do |key, val|
29
+ replace = replace.gsub(
30
+ /\[#{Regexp.escape(key)}\](?!\s*\(.*?\))/,
31
+ "[#{key}](#{val})"
32
+ )
33
+ end
34
+ next if result == replace
35
+ content = content.gsub(result, replace)
28
36
  end
29
37
  end
30
38
 
@@ -87,7 +95,6 @@ module Jekyll::Spaceship
87
95
  handle_multi_rows(data)
88
96
  handle_text_align(data)
89
97
  handle_rowspan(data)
90
- handle_attr_list(data)
91
98
  end
92
99
  end
93
100
  rows.each do |row|
@@ -95,6 +102,7 @@ module Jekyll::Spaceship
95
102
  cells.each do |cell|
96
103
  data.cell = cell
97
104
  handle_format(data)
105
+ handle_attr_list(data)
98
106
  end
99
107
  end
100
108
  self.handled = true
@@ -143,10 +151,10 @@ module Jekyll::Spaceship
143
151
  end
144
152
  end
145
153
 
146
- result = cell.content.match(/(\|)+$/)
154
+ result = cell.inner_html.match(/(\|)+$/)
147
155
  return if result.nil?
148
156
 
149
- cell.content = cell.content.gsub(/(\|)+$/, '')
157
+ cell.inner_html = cell.inner_html.gsub(/(\|)+$/, '')
150
158
  result = result[0]
151
159
  colspan = result.scan(/\|/).count
152
160
  scope.row.colspan += colspan
@@ -203,8 +211,8 @@ module Jekyll::Spaceship
203
211
 
204
212
  # handle rowspan
205
213
  span_cell = scope.table.span_row_cells[scope.row.col_index]
206
- if span_cell and cell.content.match(/^\s*\^{2}/)
207
- cell.content = cell.content.gsub(/^\s*\^{2}/, '')
214
+ if span_cell and cell.inner_html.match(/^\s*\^{2}/)
215
+ cell.inner_html = cell.inner_html.gsub(/^\s*\^{2}/, '')
208
216
  span_cell.inner_html += "\n<br>\n#{cell.inner_html}"
209
217
  rowspan = span_cell.get_attribute('rowspan') || 1
210
218
  rowspan = rowspan.to_i + 1
@@ -264,7 +272,7 @@ module Jekyll::Spaceship
264
272
  content = cell.inner_html
265
273
  # inline attribute list(IAL) handler
266
274
  ial_handler = ->(list) do
267
- list.scan(/(\S+)=("|')(.*?)\2|(\S+)/) do |attr|
275
+ list.scan(/(\S+)=(”|"|')(.*?)\2|(\S+)/) do |attr|
268
276
  key = attr[0]
269
277
  val = attr[2]
270
278
  single = attr[3]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Spaceship
5
- VERSION = "0.9.8"
5
+ VERSION = "0.10.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-spaceship
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jeffreytse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-10 00:00:00.000000000 Z
11
+ date: 2021-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll