jekyll-spaceship 0.6.1 → 0.7.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: ca3414a157fe1966031e109e08be4805790638d24fa4f7197bf74fc231b69778
4
- data.tar.gz: 95b7d289cd489e28c09902ff5b7f6e35229847cab376df5be9bbab3434f4e41f
3
+ metadata.gz: 106c9567e6da2b0de0e2bdfee8cc88bfbb1cb5269456cca7b233e7ef7ff48d7a
4
+ data.tar.gz: 52287264fd7f7875a6f00e4997e49658461f25698958abd90fed7b8139ac48e3
5
5
  SHA512:
6
- metadata.gz: 27e7c3291a2994b03b8670a920ff8cb9d8727a1986debc19d1cf1a92989fc651790353cf29811d2cead664bf999fb0cb77ebb676b5af5773192b8d934e3ce90d
7
- data.tar.gz: fde58815d50920a1c1c9b4c6694b0600e7a02102bd2d86edad24db469487942e9fdad477a70c567afbcd8e527275bc093328b7b0e75627ed0c194247155361d4
6
+ metadata.gz: 8245dfe8f753198e5a1f9839a804734c6ce4ee77c224055b30c0df90be790f586d68721cf3593e001db916fa6679bf775b511549a9c524eb1ef85ceebc7ec71f
7
+ data.tar.gz: 7e4a12588c99731ac3f490e0673e7987ba8c2ba816974b5ef2cafc622081e7bc338c76010e00ba32204ab7d1ee6054f156edc79da01ba43d3dd9c04c60267cd4
data/README.md CHANGED
@@ -80,10 +80,10 @@
80
80
  <br>
81
81
 
82
82
 
83
- A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, emoji, youtube, vimeo, dailymotion, etc.
83
+ Spaceship is a minimalistic, powerful and extremely customizable [Jekyll](https://jekyllrb.com/) plugin. It combines everything you may need for convenient work, without unnecessary complications, like a real spaceship.
84
84
 
85
85
  <p align="center">
86
- <img alt="Jekyll Spaceship Demo" src="https://user-images.githubusercontent.com/9413601/82250463-15451780-997e-11ea-8809-f411586d9508.gif" alt="Donate (Ko-fi)" />
86
+ <img alt="Jekyll Spaceship Demo" src="https://user-images.githubusercontent.com/9413601/82250463-15451780-997e-11ea-8809-f411586d9508.gif" />
87
87
  </p>
88
88
 
89
89
  **💡 Tip:** I hope you enjoy using this plugin. If you like this project, **a little star** for it is your way make a clear statement: **My work is valued**. I would appreciate your support! _Thank you!_
@@ -109,10 +109,13 @@ A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, emoji
109
109
  - [4.1 Youtube Usage](#youtube-usage)
110
110
  - [4.2 Vimeo Usage](#vimeo-usage)
111
111
  - [4.3 DailyMotion Usage](#dailymotion-usage)
112
+ - [4.4 General Video Usage](#general-video-usage)
112
113
  - [5. Hybrid HTML with Markdown](#5-hybrid-html-with-markdown)
113
114
  - [6. Markdown Polyfill](#6-markdown-polyfill)
114
115
  - [6.1 Escape Ordered List](#escape-ordered-list)
115
116
  - [7. Emoji Usage](#7-emoji-usage)
117
+ - [7.1 Emoji Customizing](#71-emoji-customizing)
118
+ - [8. Modifying Element Usage](#8-modifying-element-usage)
116
119
  - [Credits](#credits)
117
120
  - [Contributing](#contributing)
118
121
  - [License](#license)
@@ -152,6 +155,7 @@ jekyll-spaceship:
152
155
  - polyfill-processor
153
156
  - video-processor
154
157
  - emoji-processor
158
+ - element-processor
155
159
  mathjax-processor:
156
160
  src: //cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
157
161
  config:
@@ -576,6 +580,7 @@ While its not possible to embed a video in markdown, the best and easiest way is
576
580
  - Youtube
577
581
  - Vimeo
578
582
  - DailyMotion
583
+ - General Video ( mp4 | avi | webm | ogg | ogv | 3gp | flv | mov ... )
579
584
 
580
585
  There are two ways to embed a video in your Jekyll blog page:
581
586
 
@@ -634,6 +639,21 @@ the link as below:
634
639
  ![](https://dai.ly/x7tgcev?width=100%&height=400)
635
640
  ```
636
641
 
642
+ #### General Video Usage
643
+
644
+ ```markdown
645
+ ![](//www.html5rocks.com/en/tutorials/video/basics/devstories.webm)
646
+ ```
647
+
648
+ ```markdown
649
+ ![](//techslides.com/demos/sample-videos/small.ogv?allow=autoplay)
650
+ ```
651
+
652
+ ```markdown
653
+ ![](//techslides.com/demos/sample-videos/small.mp4?width=400)
654
+ ```
655
+
656
+
637
657
  ### 5. Hybrid HTML with Markdown
638
658
 
639
659
  As markdown is not only a lightweight markup language with plain-text-formatting syntax, but also an easy-to-read and easy-to-write plain text format, so writing a hybrid HTML with markdown is an awesome choice.
@@ -725,12 +745,114 @@ I give this plugin two :+1:!
725
745
 
726
746
  I give this plugin two :+1:!
727
747
 
748
+ #### 7.1 Emoji Customizing
749
+
750
+ If you'd like to serve emoji images locally, or use a custom emoji source, you can specify so in your `_config.yml` file:
751
+
752
+ ```yml
753
+ jekyll-spaceship:
754
+ emoji-processor:
755
+ src: "/assets/images/emoji"
756
+ ```
757
+
758
+ See the [Gemoji](https://github.com/github/gemoji) documentation for generating image files.
759
+
760
+ ### 8. Modifying Element Usage
761
+
762
+ It allows us to modify elements via `CSS3 selectors`. Through it you can easily
763
+ modify the attributes of an element tag, replace the children nodes and so on,
764
+ it's very flexible, but here is example usage for modifying a document:
765
+
766
+ ```yml
767
+ # Here is a comprehensive example
768
+ jekyll-spaceship:
769
+ element-processor:
770
+ css:
771
+ - a: '<h1>Test</h1>' # Replace all `a` tags (String Style)
772
+ - ['a.link1', 'a.link2']: # Replace all `a.link1`, `a.link2` tags (Hash Style)
773
+ name: img # Replace element tag name
774
+ props: # Replace element properties
775
+ title: Good image # Add a title attribute
776
+ src: ['(^.*$)', '\0?a=123'] # Add query string to src attribute by regex pattern
777
+ style: # Add style attribute (Hash Style)
778
+ color: red
779
+ font-size: '1.2em'
780
+ children: # Add children to the element
781
+ - # First empty for adding after the last child node
782
+ - "<span>Google</span>" # First child node (String Style)
783
+ - # Middle empty for wrapping the children nodes
784
+ - name: span # Second child node (Hash Style)
785
+ props:
786
+ prop1: "1" # Custom property1
787
+ prop2: "2" # Custom property2
788
+ prop3: "3" # Custom property3
789
+ children: # Add nested chidren nodes
790
+ - "<span>Jekyll</span>" # First child node (String Style)
791
+ - name: span # Second child node (Hash Style)
792
+ props: # Add attributes to child node (Hash Style)
793
+ prop1: "a"
794
+ prop2: "b"
795
+ prop3: "c"
796
+ children: "<b>Yap!</b>" # Add children nodes (String Style)
797
+ - # Last empty for adding before the first child node
798
+ - a.link: '<a href="//t.com">Link</a>' # Replace all `a.link` tags (String Style)
799
+ - 'h1#title': # Replace `h1#title` tags (Hash Style)
800
+ children: I'm a title! # Replace inner html to new text
801
+ ```
802
+
803
+ #### Example 1
804
+
805
+ Automatically adds a `target="_blank" rel="noopener noreferrer"` attribute to all external links in Jekyll's content.
806
+
807
+ ```yml
808
+ jekyll-spaceship:
809
+ element-processor:
810
+ css:
811
+ - a: # Replce all `a` tags
812
+ props:
813
+ class: ['(^.*$)', '\0 ext-link'] # Add `ext-link` to class by regex pattern
814
+ target: _blank # Replace `target` value to `_blank`
815
+ rel: noopener noreferrer # Replace `rel` value to `noopener noreferrer`
816
+ ```
817
+
818
+ #### Example 2
819
+
820
+ Automatically adds `loading="lazy"` to `img` and `iframe` tags to natively load lazily.
821
+ [Browser support](https://caniuse.com/#feat=loading-lazy-attr) is growing. If a browser does not support the `loading` attribute, it will load the resource just like it would normally.
822
+
823
+ ```yml
824
+ jekyll-spaceship:
825
+ element-processor:
826
+ css:
827
+ - a: # Replce all `a` tags
828
+ props: #
829
+ loading: lazy # Replace `lading` value to `lazy`
830
+ ```
831
+
832
+ In case you want to prevent loading some images/iframes lazily, add
833
+ `loading="eager"` to their tags. This might be useful to prevent flickering of
834
+ images during navigation (e.g. the site's logo).
835
+
836
+ See the following examples to prevent lazy loading.
837
+
838
+ ```yml
839
+ jekyll-spaceship:
840
+ element-processor:
841
+ css:
842
+ - a: # Replce all `a` tags
843
+ props: #
844
+ loading: eager # Replace `loading` value to `eager`
845
+ ```
846
+
847
+
728
848
  ## Credits
729
849
 
730
850
  - [Jekyll](https://github.com/jekyll/jekyll) - A blog-aware static site generator in Ruby.
731
851
  - [MultiMarkdown](https://fletcher.github.io/MultiMarkdown-6) - Lightweight markup processor to produce HTML, LaTeX, and more.
732
852
  - [markdown-it-multimd-table](https://github.com/RedBug312/markdown-it-multimd-table) - Multimarkdown table syntax plugin for markdown-it markdown parser.
733
853
  - [jmoji](https://github.com/jekyll/jemoji) - GitHub-flavored emoji plugin for Jekyll.
854
+ - [jekyll-target-blank](https://github.com/keithmifsud/jekyll-target-blank) - Automatically opens external links in a new browser for Jekyll Pages, Posts and Docs.
855
+ - [jekyll-loading-lazy](https://github.com/gildesmarais/jekyll-loading-lazy) - Automatically adds loading="lazy" to img and iframe tags to natively load lazily.
734
856
 
735
857
  ## Contributing
736
858
 
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.version = Jekyll::Spaceship::VERSION
10
10
  spec.authors = ["jeffreytse"]
11
11
  spec.email = ["jeffreytse.mail@gmail.com"]
12
- spec.summary = "A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, emoji, youtube, vimeo, dailymotion, etc."
12
+ spec.summary = "A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, emoji, video, youtube, vimeo, dailymotion, etc."
13
13
  spec.homepage = "https://github.com/jeffreytse/jekyll-spaceship"
14
14
  spec.license = "MIT"
15
15
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'yaml'
4
-
5
3
  module Jekyll::Spaceship
6
4
  class Config
7
5
  CONFIG_NAME = 'jekyll-spaceship'
@@ -12,20 +10,9 @@ module Jekyll::Spaceship
12
10
  'plantuml-processor',
13
11
  'polyfill-processor',
14
12
  'video-processor',
15
- 'emoji-processor'
16
- ],
17
- 'mathjax-processor' => {
18
- 'src' => '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML',
19
- 'config' => {
20
- 'tex2jax' => { 'inlineMath' => [['$','$'], ['\\(','\\)']] }
21
- }
22
- },
23
- 'plantuml-processor' => {
24
- 'src' => 'http://www.plantuml.com/plantuml/png/'
25
- },
26
- 'emoji-processor' => {
27
- 'src' => 'https://github.githubassets.com/images/icons/emoji/'
28
- }
13
+ 'emoji-processor',
14
+ 'element-processor'
15
+ ]
29
16
  }
30
17
 
31
18
  @@store = {}
@@ -43,14 +30,15 @@ module Jekyll::Spaceship
43
30
  first.merge(second.to_h, &merger)
44
31
  end
45
32
 
46
- def self.store(section)
47
- @@store[section]
33
+ def self.store(section, default)
34
+ return @@store[section] if default.nil?
35
+ @@store[section] = deep_merge(default, @@store[section])
48
36
  end
49
37
 
50
- def self.load(filename = '_config.yml')
38
+ def self.load(config = self.site_config)
51
39
  config = deep_merge(
52
40
  { CONFIG_NAME => DEFAULT_CONFIG },
53
- YAML.load_file(File.expand_path(filename))
41
+ config
54
42
  )[CONFIG_NAME]
55
43
  @@store = config
56
44
  self.use_processors(config)
@@ -61,5 +49,9 @@ module Jekyll::Spaceship
61
49
  Register.use processor
62
50
  end
63
51
  end
52
+
53
+ def self.site_config
54
+ Jekyll.sites.first.config
55
+ end
64
56
  end
65
57
  end
@@ -41,7 +41,8 @@ module Jekyll::Spaceship
41
41
  self.initialize_register
42
42
  self.initialize_exclusions
43
43
  @logger = Logger.new(self.name)
44
- @config = Config.store(self.filename)
44
+ @config = Config.store(self.filename, self.class.config)
45
+ @handled_files = {}
45
46
  end
46
47
 
47
48
  def initialize_priority
@@ -56,7 +57,7 @@ module Jekyll::Spaceship
56
57
  def initialize_register
57
58
  if @@_registers.size.zero?
58
59
  self.class.register :pages, :pre_render, :post_render
59
- self.class.register :posts, :pre_render, :post_render
60
+ self.class.register :documents, :pre_render, :post_render
60
61
  end
61
62
  @registers = Array.new @@_registers
62
63
  @@_registers.clear
@@ -82,6 +83,9 @@ module Jekyll::Spaceship
82
83
  @@_exclusions = types
83
84
  end
84
85
 
86
+ def self.config
87
+ end
88
+
85
89
  def process?
86
90
  Type.html?(output_ext) or Type.markdown?(ext)
87
91
  end
@@ -140,7 +144,10 @@ module Jekyll::Spaceship
140
144
  end
141
145
 
142
146
  def on_handled
143
- file = page.path.gsub(/.*_posts\//, '')
147
+ source = page.site.source
148
+ file = page.path.sub(/^#{source}\//, '')
149
+ return if @handled_files.has_key? file
150
+ @handled_files[file] = true
144
151
  logger.log file
145
152
  end
146
153
 
@@ -149,13 +156,13 @@ module Jekyll::Spaceship
149
156
  @exclusions.each do |type|
150
157
  regex = nil
151
158
  if type == :code
152
- regex = /(`{3}\s*(\w*)((?:.|\n)*?)`{3})/
159
+ regex = /((`+)\s*(\w*)((?:.|\n)*?)\2)/
153
160
  end
154
161
  next if regex.nil?
155
162
  content.scan(regex) do |match_data|
156
163
  match = match_data[0]
157
164
  id = @exclusion_store.size
158
- content = content.gsub(match, "[//]: JEKYLL_EXCLUDE_##{id}")
165
+ content = content.sub(match, "[JEKYLL@#{object_id}@#{id}]")
159
166
  @exclusion_store.push match
160
167
  end
161
168
  end
@@ -166,7 +173,7 @@ module Jekyll::Spaceship
166
173
  while @exclusion_store.size > 0
167
174
  match = @exclusion_store.pop
168
175
  id = @exclusion_store.size
169
- content = content.gsub("[//]: JEKYLL_EXCLUDE_##{id}", match)
176
+ content = content.sub("[JEKYLL@#{object_id}@#{id}]", match)
170
177
  end
171
178
  @exclusion_store = []
172
179
  content
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nokogiri'
4
+
5
+ module Jekyll::Spaceship
6
+ class ElementProcessor < Processor
7
+ priority :lowest
8
+
9
+ def self.config
10
+ { 'css' => [] }
11
+ end
12
+
13
+ def on_handle_html(content)
14
+ return content if config['css'].size.zero?
15
+
16
+ # use nokogiri to parse html content
17
+ doc = Nokogiri::HTML(content)
18
+
19
+ # handle each css pattern
20
+ config['css'].each do |data|
21
+ data.each do |key, val|
22
+ key = [key] if key.kind_of? String
23
+ key.each do |pattern|
24
+ nodes = doc.css(pattern)
25
+ nodes.each do |element|
26
+ handle_css_pattern({
27
+ :doc => doc,
28
+ :element => element,
29
+ :data => val
30
+ })
31
+ end
32
+ self.handled = true
33
+ end
34
+ end
35
+ end
36
+
37
+ doc.to_html
38
+ end
39
+
40
+ def handle_css_pattern(data)
41
+ doc = data[:doc]
42
+ element = data[:element]
43
+ data = data[:data]
44
+
45
+ if data.kind_of? String
46
+ element.replace Nokogiri::HTML.fragment(data)
47
+ elsif data.kind_of? Hash
48
+ # set name
49
+ element.name = data['name'] unless data['name'].nil?
50
+
51
+ # set props
52
+ data['props']&.each do |prop, val|
53
+ next element.remove_attribute if val.nil?
54
+ if val.kind_of? Array
55
+ next if val.size != 2
56
+ v = element[prop]
57
+ v = '' if v.nil?
58
+ val = v.sub(/#{val[0]}/, val[1])
59
+ elsif val.kind_of? Hash
60
+ result = []
61
+ val.each { |k, v| result.push "#{k}: #{v}" }
62
+ val = result.join(";")
63
+ end
64
+ element.set_attribute(prop, val)
65
+ end
66
+
67
+ # processing children
68
+ return unless data.has_key?('children')
69
+ return element.inner_html = "" if data['children'].nil?
70
+ children = self.create_children({
71
+ :doc => doc,
72
+ :data => data['children']
73
+ })
74
+
75
+ # replace whole inner html
76
+ unless data['children'].kind_of? Array
77
+ return element.inner_html = children
78
+ end
79
+
80
+ if element.children.size.zero?
81
+ return element.inner_html = children
82
+ end
83
+
84
+ index = data['children'].index(nil)
85
+ if index.nil?
86
+ return element.inner_html = children
87
+ end
88
+
89
+ # insert to the end of children
90
+ if index == 0
91
+ return element.children.last.after(children)
92
+ end
93
+
94
+ # insert to the begin of children
95
+ rindex = data['children'].rindex { |item| !item.nil? }
96
+ if index == rindex + 1
97
+ return element.children.first.before children
98
+ end
99
+
100
+ # wrap the children
101
+ element.children.first.before children[0..index]
102
+ element.children.last.after children[index..children.size]
103
+ end
104
+ end
105
+
106
+ def create_children(data)
107
+ doc = data[:doc]
108
+ data = data[:data]
109
+ root = Nokogiri::HTML.fragment("")
110
+
111
+ data = [data] unless data.kind_of? Array
112
+ data.each do |child_data|
113
+ node = self.create_element({
114
+ :doc => doc,
115
+ :data => child_data
116
+ })
117
+ next if node.nil?
118
+ unless child_data['children'].nil?
119
+ node.children = self.create_children({
120
+ :doc => doc,
121
+ :data => child_data['children']
122
+ })
123
+ end
124
+ root.add_child node
125
+ end
126
+ root.children
127
+ end
128
+
129
+ def create_element(data)
130
+ doc = data[:doc]
131
+ data = data[:data]
132
+
133
+ return if data.nil?
134
+ return Nokogiri::HTML.fragment(data) if data.kind_of? String
135
+ return if data['name'].nil?
136
+
137
+ # create node
138
+ node = doc.create_element(data['name'])
139
+
140
+ # set props
141
+ data['props']&.each do |prop, val|
142
+ if val.kind_of? Hash
143
+ result = []
144
+ val.each { |k, v| result.push "#{k}: #{v}" }
145
+ val = result.join(";")
146
+ end
147
+ node.set_attribute(prop, val)
148
+ end
149
+ node
150
+ end
151
+ end
152
+ end
@@ -6,6 +6,10 @@ require 'gemoji'
6
6
 
7
7
  module Jekyll::Spaceship
8
8
  class EmojiProcessor < Processor
9
+ def self.config
10
+ { 'src' => 'https://github.githubassets.com/images/icons/emoji/' }
11
+ end
12
+
9
13
  def on_handle_html(content)
10
14
  # handle emoji markup
11
15
  content.scan(/:([\w\d+-]+):/) do |match|
@@ -18,16 +22,16 @@ module Jekyll::Spaceship
18
22
 
19
23
  content = content.gsub(
20
24
  /(?<!\=")\s*:#{emoji_name}:\s*(?!"\s)/,
21
- "<img class=\"emoji\" \
22
- title=\":#{emoji.name}:\" \
23
- alt=\":#{emoji.name}:\" \
24
- raw=\"#{emoji.raw}\" \
25
- src=\"#{config['src']}#{emoji.image_filename}\" \
26
- style=\"vertical-align: middle; \
27
- max-width: 1em; visibility: hidden;\" \
28
- onload=\"this.style.visibility='visible'\" \
29
- onerror=\"this.replaceWith(this.getAttribute('raw'))\"> \
30
- </img>"
25
+ "<img class=\"emoji\""\
26
+ " title=\":#{emoji.name}:\""\
27
+ " alt=\":#{emoji.name}:\""\
28
+ " raw=\"#{emoji.raw}\""\
29
+ " src=\"#{config['src']}#{emoji.image_filename}\""\
30
+ " style=\"vertical-align: middle;"\
31
+ " max-width: 1em; visibility: hidden;\""\
32
+ " onload=\"this.style.visibility='visible'\""\
33
+ " onerror=\"this.replaceWith(this.getAttribute('raw'))\">"\
34
+ "</img>"
31
35
  )
32
36
  end
33
37
  content
@@ -4,6 +4,15 @@ require "nokogiri"
4
4
 
5
5
  module Jekyll::Spaceship
6
6
  class MathjaxProcessor < Processor
7
+ def self.config
8
+ {
9
+ 'src' => '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML',
10
+ 'config' => {
11
+ 'tex2jax' => { 'inlineMath' => [['$','$'], ['\\(','\\)']] }
12
+ }
13
+ }
14
+ end
15
+
7
16
  def process?
8
17
  return true if Type.html?(output_ext)
9
18
  end
@@ -7,17 +7,30 @@ module Jekyll::Spaceship
7
7
  class PlantumlProcessor < Processor
8
8
  exclude :none
9
9
 
10
+ PLANTUML_PATTERNS = [
11
+ /(\\?(@startuml)((?:.|\n)*?)@enduml)/,
12
+ /((`{3,})\s*plantuml((?:.|\n)*?)\2)/
13
+ ]
14
+
15
+ def self.config
16
+ { 'src' => 'http://www.plantuml.com/plantuml/png/' }
17
+ end
18
+
10
19
  def on_handle_markdown(content)
11
20
  # match default plantuml block and code block
12
- pattern = Regexp.union(
13
- /(\\?@startuml((?:.|\n)*?)@enduml)/,
14
- /(`{3}\s*plantuml((?:.|\n)*?)`{3})/
15
- )
21
+ PLANTUML_PATTERNS.each do |pattern|
22
+ content = handle_plantuml_block(pattern, content)
23
+ end
16
24
 
25
+ # handle escape default plantuml block
26
+ content.gsub(/\\(@startuml|@enduml)/, '\1')
27
+ end
28
+
29
+ def handle_plantuml_block(pattern, content)
17
30
  content.scan pattern do |match|
18
31
  match = match.select { |m| not m.nil? }
19
32
  block = match[0]
20
- code = match[1]
33
+ code = match[2]
21
34
 
22
35
  # skip escape default plantuml block
23
36
  if block.match(/(^\\@startuml|\\@enduml$)/)
@@ -31,9 +44,7 @@ module Jekyll::Spaceship
31
44
  handle_plantuml(code)
32
45
  )
33
46
  end
34
-
35
- # handle escape default plantuml block
36
- content.gsub(/\\(@startuml|@enduml)/, '\1')
47
+ content
37
48
  end
38
49
 
39
50
  def handle_plantuml(code)
@@ -5,11 +5,23 @@ require 'uri'
5
5
  module Jekyll::Spaceship
6
6
  class VideoProcessor < Processor
7
7
  def on_handle_markdown(content)
8
+ content = handle_normal_video(content)
8
9
  content = handle_youtube(content)
9
10
  content = handle_vimeo(content)
10
11
  content = handle_dailymotion(content)
11
12
  end
12
13
 
14
+ # Examples:
15
+ # ![video](//www.html5rocks.com/en/tutorials/video/basics/devstories.webm)
16
+ # ![video](//techslides.com/demos/sample-videos/small.ogv?allow=autoplay)
17
+ # ![video](//techslides.com/demos/sample-videos/small.mp4?width=400)
18
+ def handle_normal_video(content)
19
+ handle_video(content, {
20
+ host: '(https?:)?\\/\\/.*\\/',
21
+ id: '(.+?\\.(avi|mp4|webm|ogg|ogv|flv|mkv|mov|wmv|3gp|rmvb|asf))',
22
+ })
23
+ end
24
+
13
25
  # Examples:
14
26
  # ![youtube](https://www.youtube.com/watch?v=XA2WjJbmmoM "title")
15
27
  # ![youtube](http://www.youtube.com/embed/w-m_yZCLF5Q)
@@ -29,9 +41,7 @@ module Jekyll::Spaceship
29
41
  handle_video(content, {
30
42
  host: '(https?:)?\\/\\/vimeo\\.com\\/',
31
43
  id: '([0-9]+)',
32
- iframe_url: "https://player.vimeo.com/video/",
33
- width: 600,
34
- height: 350
44
+ iframe_url: "https://player.vimeo.com/video/"
35
45
  })
36
46
  end
37
47
 
@@ -77,25 +87,30 @@ module Jekyll::Spaceship
77
87
  next true if v == id or v == ''
78
88
  end
79
89
 
80
- width = qs['width'] || data[:width] || 600
81
- height = qs['height'] || data[:height] || 400
82
- style = "max-width: 100%" if width.nil?
90
+ css_id = qs['id'] || "video-#{id}"
91
+ css_class = qs['class'] || 'video'
92
+ width = qs['width'] || data[:width] || "100%"
93
+ height = qs['height'] || data[:height] || 350
94
+ frameborder = qs['frameborder'] || 0
95
+ style = qs['style'] || 'max-width: 600px'
96
+ allow = qs['allow'] || "encrypted-media; picture-in-picture"
83
97
 
84
- url = URI("#{iframe_url}#{id}").tap do |v|
98
+ url = URI(iframe_url ? "#{iframe_url}#{id}" : url).tap do |v|
85
99
  v.query = URI.encode_www_form(qs) if qs.size > 0
86
100
  end
87
101
 
88
- html = "<iframe \
89
- class=\"video\" \
90
- src=\"#{url}\" \
91
- title=\"#{title}\" \
92
- width=\"#{width}\" \
93
- height=\"#{height}\" \
94
- style=\"#{style}\" \
95
- allow=\"autoplay; encrypted-media\" \
96
- frameborder=\"0\" \
97
- allowfullscreen=\"\">\
98
- </iframe>"
102
+ html = "<iframe"\
103
+ " id=\"#{css_id}\""\
104
+ " class=\"#{css_class}\""\
105
+ " src=\"#{url}\""\
106
+ " title=\"#{title}\""\
107
+ " width=\"#{width}\""\
108
+ " height=\"#{height}\""\
109
+ " style=\"#{style}\""\
110
+ " allow=\"#{allow}\""\
111
+ " frameborder=\"#{frameborder}\""\
112
+ " allowfullscreen>" \
113
+ "</iframe>"
99
114
 
100
115
  content = content.gsub(match_data[0], html)
101
116
  self.handled = true
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Spaceship
5
- VERSION = "0.6.1"
5
+ VERSION = "0.7.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.6.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jeffreytse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-10 00:00:00.000000000 Z
11
+ date: 2020-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -137,6 +137,7 @@ files:
137
137
  - lib/jekyll-spaceship/cores/processor.rb
138
138
  - lib/jekyll-spaceship/cores/register.rb
139
139
  - lib/jekyll-spaceship/cores/type.rb
140
+ - lib/jekyll-spaceship/processors/element-processor.rb
140
141
  - lib/jekyll-spaceship/processors/emoji-processor.rb
141
142
  - lib/jekyll-spaceship/processors/mathjax-processor.rb
142
143
  - lib/jekyll-spaceship/processors/plantuml-processor.rb
@@ -172,5 +173,5 @@ rubygems_version: 2.7.7
172
173
  signing_key:
173
174
  specification_version: 4
174
175
  summary: A Jekyll plugin to provide powerful supports for table, mathjax, plantuml,
175
- emoji, youtube, vimeo, dailymotion, etc.
176
+ emoji, video, youtube, vimeo, dailymotion, etc.
176
177
  test_files: []