jekyll-spaceship 0.6.2 → 0.7.3

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: df761631c9d2636245947978d30acc90b604f9ebd7dbfb047350cff020f80709
4
- data.tar.gz: 6eb135842d1d1e2f6eb87817a8bbdf7d2c1126a3c0e935e6275ee8ef5dd36a26
3
+ metadata.gz: d5aea23b39241812e97de9e3f6dc6f47db7a4fa743d6510de8cbc6fc8e1c90fb
4
+ data.tar.gz: 324717f9b72366dd9f2d7e51c378937222c5884380c903897781b4875d33e067
5
5
  SHA512:
6
- metadata.gz: 9675c39c1174d6420d08081d52a802865ef0a3773df936ad01cc29323a7d4287af07176328237de283a087154d86e8a3e92cd19e67a4b9ac1dae38e418a21c47
7
- data.tar.gz: b3c0d6b610fed90ca7017b25f5e08c880188f5ea9c68f7645e1027f9e8a8fb32b80b0dbc97e446d00a24346f86fbbeb394fea925a2d018af6d68c9e71368f570
6
+ metadata.gz: d0bcaeb2c487b51961678cd2ea6e665466d75dc2c6c8b51b2e723121a7c2f0889a536836f11c48dc33b8784f871976fb43607824dfede322fb3e3f859007226d
7
+ data.tar.gz: a222d1377e23672f35815a8f8d870f247688663897d728e2b5d108b57573dc0a0f24735608a189c31ea20957d26c0cd3af3f1f8e30bbc3d80ebf70d47cb09531
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
 
@@ -8,5 +8,5 @@ require 'jekyll-spaceship/cores/register'
8
8
 
9
9
  module Jekyll::Spaceship
10
10
  Logger.display_info
11
- Config.load
11
+ Config.load_config
12
12
  end
@@ -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,7 +10,8 @@ module Jekyll::Spaceship
12
10
  'plantuml-processor',
13
11
  'polyfill-processor',
14
12
  'video-processor',
15
- 'emoji-processor'
13
+ 'emoji-processor',
14
+ 'element-processor'
16
15
  ]
17
16
  }
18
17
 
@@ -32,15 +31,14 @@ module Jekyll::Spaceship
32
31
  end
33
32
 
34
33
  def self.store(section, default)
35
- return if @@store[section].nil?
36
34
  return @@store[section] if default.nil?
37
- @@store[section] = deep_merge(@@store[section], default)
35
+ @@store[section] = deep_merge(default, @@store[section])
38
36
  end
39
37
 
40
- def self.load(filename = '_config.yml')
38
+ def self.load(config = {})
41
39
  config = deep_merge(
42
40
  { CONFIG_NAME => DEFAULT_CONFIG },
43
- YAML.load_file(File.expand_path(filename))
41
+ config
44
42
  )[CONFIG_NAME]
45
43
  @@store = config
46
44
  self.use_processors(config)
@@ -51,5 +49,12 @@ module Jekyll::Spaceship
51
49
  Register.use processor
52
50
  end
53
51
  end
52
+
53
+ def self.load_config
54
+ # post load site config for `group :jekyll_plugin`
55
+ Jekyll::Hooks.register :site, :after_init do |site|
56
+ self.load(site.config)
57
+ end
58
+ end
54
59
  end
55
60
  end
@@ -156,13 +156,13 @@ module Jekyll::Spaceship
156
156
  @exclusions.each do |type|
157
157
  regex = nil
158
158
  if type == :code
159
- regex = /(`{3}\s*(\w*)((?:.|\n)*?)`{3})/
159
+ regex = /((`+)\s*(\w*)((?:.|\n)*?)\2)/
160
160
  end
161
161
  next if regex.nil?
162
162
  content.scan(regex) do |match_data|
163
163
  match = match_data[0]
164
164
  id = @exclusion_store.size
165
- content = content.gsub(match, "[//]: JEKYLL_EXCLUDE_##{id}")
165
+ content = content.sub(match, "[JEKYLL@#{object_id}@#{id}]")
166
166
  @exclusion_store.push match
167
167
  end
168
168
  end
@@ -173,7 +173,7 @@ module Jekyll::Spaceship
173
173
  while @exclusion_store.size > 0
174
174
  match = @exclusion_store.pop
175
175
  id = @exclusion_store.size
176
- content = content.gsub("[//]: JEKYLL_EXCLUDE_##{id}", match)
176
+ content = content.sub("[JEKYLL@#{object_id}@#{id}]", match)
177
177
  end
178
178
  @exclusion_store = []
179
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
@@ -7,21 +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
+
10
15
  def self.config
11
16
  { 'src' => 'http://www.plantuml.com/plantuml/png/' }
12
17
  end
13
18
 
14
19
  def on_handle_markdown(content)
15
20
  # match default plantuml block and code block
16
- pattern = Regexp.union(
17
- /(\\?@startuml((?:.|\n)*?)@enduml)/,
18
- /(`{3}\s*plantuml((?:.|\n)*?)`{3})/
19
- )
21
+ PLANTUML_PATTERNS.each do |pattern|
22
+ content = handle_plantuml_block(pattern, content)
23
+ end
20
24
 
25
+ # handle escape default plantuml block
26
+ content.gsub(/\\(@startuml|@enduml)/, '\1')
27
+ end
28
+
29
+ def handle_plantuml_block(pattern, content)
21
30
  content.scan pattern do |match|
22
31
  match = match.select { |m| not m.nil? }
23
32
  block = match[0]
24
- code = match[1]
33
+ code = match[2]
25
34
 
26
35
  # skip escape default plantuml block
27
36
  if block.match(/(^\\@startuml|\\@enduml$)/)
@@ -35,9 +44,7 @@ module Jekyll::Spaceship
35
44
  handle_plantuml(code)
36
45
  )
37
46
  end
38
-
39
- # handle escape default plantuml block
40
- content.gsub(/\\(@startuml|@enduml)/, '\1')
47
+ content
41
48
  end
42
49
 
43
50
  def handle_plantuml(code)
@@ -92,7 +92,7 @@ module Jekyll::Spaceship
92
92
  width = qs['width'] || data[:width] || "100%"
93
93
  height = qs['height'] || data[:height] || 350
94
94
  frameborder = qs['frameborder'] || 0
95
- style = qs['style'] || ''
95
+ style = qs['style'] || 'max-width: 600px'
96
96
  allow = qs['allow'] || "encrypted-media; picture-in-picture"
97
97
 
98
98
  url = URI(iframe_url ? "#{iframe_url}#{id}" : url).tap do |v|
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Spaceship
5
- VERSION = "0.6.2"
5
+ VERSION = "0.7.3"
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.2
4
+ version: 0.7.3
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-13 00:00:00.000000000 Z
11
+ date: 2020-06-22 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