mirror of
https://github.com/SharpeTronics/jekyll-spaceship.git
synced 2025-06-24 00:01:24 -04:00
Compare commits
No commits in common. "master" and "v0.9.1" have entirely different histories.
12
README.md
12
README.md
@ -146,7 +146,7 @@ plugins:
|
|||||||
|
|
||||||
**💡 Tip:** Note that GitHub Pages runs in `safe` mode and only allows [a set of whitelisted plugins](https://pages.github.com/versions/). To use the gem in GitHub Pages, you need to build locally or use CI (e.g. [travis](https://travis-ci.org/), [github workflow](https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow)) and deploy to your `gh-pages` branch.
|
**💡 Tip:** Note that GitHub Pages runs in `safe` mode and only allows [a set of whitelisted plugins](https://pages.github.com/versions/). To use the gem in GitHub Pages, you need to build locally or use CI (e.g. [travis](https://travis-ci.org/), [github workflow](https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow)) and deploy to your `gh-pages` branch.
|
||||||
|
|
||||||
### Additions for Unlimited GitHub Pages
|
### Additions
|
||||||
|
|
||||||
* Here is a GitHub Action named [jekyll-deploy-action](https://github.com/jeffreytse/jekyll-deploy-action) for Jekyll site deployment conveniently. 👍
|
* Here is a GitHub Action named [jekyll-deploy-action](https://github.com/jeffreytse/jekyll-deploy-action) for Jekyll site deployment conveniently. 👍
|
||||||
* Here is a [Jekyll site](https://github.com/jeffreytse/jekyll-jeffreytse-blog) using Travis to build and deploy to GitHub Pages for your references.
|
* Here is a [Jekyll site](https://github.com/jeffreytse/jekyll-jeffreytse-blog) using Travis to build and deploy to GitHub Pages for your references.
|
||||||
@ -186,7 +186,7 @@ jekyll-spaceship:
|
|||||||
syntax:
|
syntax:
|
||||||
code: 'plantuml!'
|
code: 'plantuml!'
|
||||||
custom: ['@startuml', '@enduml']
|
custom: ['@startuml', '@enduml']
|
||||||
src: http://www.plantuml.com/plantuml/svg/
|
src: http://www.plantuml.com/plantuml/png/
|
||||||
mermaid-processor:
|
mermaid-processor:
|
||||||
mode: default # mode value 'pre-fetch' for fetching image at building stage
|
mode: default # mode value 'pre-fetch' for fetching image at building stage
|
||||||
css:
|
css:
|
||||||
@ -637,7 +637,7 @@ Code above would be parsed as:
|
|||||||
|
|
||||||
### 3. PlantUML Usage
|
### 3. PlantUML Usage
|
||||||
|
|
||||||
[PlantUML](https://plantuml.com) is a component that allows to quickly write:
|
[PlantUML](http://plantuml.sourceforge.net/) is a component that allows to quickly write:
|
||||||
|
|
||||||
- sequence diagram,
|
- sequence diagram,
|
||||||
- use case diagram,
|
- use case diagram,
|
||||||
@ -966,7 +966,7 @@ Automatically adds a `target="_blank" rel="noopener noreferrer"` attribute to al
|
|||||||
jekyll-spaceship:
|
jekyll-spaceship:
|
||||||
element-processor:
|
element-processor:
|
||||||
css:
|
css:
|
||||||
- a: # Replace all `a` tags
|
- a: # Replce all `a` tags
|
||||||
props:
|
props:
|
||||||
class: ['(^.*$)', '\0 ext-link'] # Add `ext-link` to class by regex pattern
|
class: ['(^.*$)', '\0 ext-link'] # Add `ext-link` to class by regex pattern
|
||||||
target: _blank # Replace `target` value to `_blank`
|
target: _blank # Replace `target` value to `_blank`
|
||||||
@ -982,7 +982,7 @@ Automatically adds `loading="lazy"` to `img` and `iframe` tags to natively load
|
|||||||
jekyll-spaceship:
|
jekyll-spaceship:
|
||||||
element-processor:
|
element-processor:
|
||||||
css:
|
css:
|
||||||
- a: # Replace all `a` tags
|
- a: # Replce all `a` tags
|
||||||
props: #
|
props: #
|
||||||
loading: lazy # Replace `loading` value to `lazy`
|
loading: lazy # Replace `loading` value to `lazy`
|
||||||
```
|
```
|
||||||
@ -997,7 +997,7 @@ See the following examples to prevent lazy loading.
|
|||||||
jekyll-spaceship:
|
jekyll-spaceship:
|
||||||
element-processor:
|
element-processor:
|
||||||
css:
|
css:
|
||||||
- a: # Replace all `a` tags
|
- a: # Replce all `a` tags
|
||||||
props: #
|
props: #
|
||||||
loading: eager # Replace `loading` value to `eager`
|
loading: eager # Replace `loading` value to `eager`
|
||||||
```
|
```
|
||||||
|
@ -116,7 +116,7 @@ module Jekyll::Spaceship
|
|||||||
if self.respond_to? method
|
if self.respond_to? method
|
||||||
@page.content = self.pre_exclude @page.content
|
@page.content = self.pre_exclude @page.content
|
||||||
@page.content = self.send method, @page.content
|
@page.content = self.send method, @page.content
|
||||||
@page.content = self.post_exclude @page.content
|
@page.content = self.after_exclude @page.content
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if Type.html? output_ext
|
if Type.html? output_ext
|
||||||
@ -151,8 +151,8 @@ module Jekyll::Spaceship
|
|||||||
logger.log file
|
logger.log file
|
||||||
end
|
end
|
||||||
|
|
||||||
def exclusion_regexs()
|
def pre_exclude(content)
|
||||||
regexs = []
|
@exclusion_store = []
|
||||||
@exclusions.each do |type|
|
@exclusions.each do |type|
|
||||||
regex = nil
|
regex = nil
|
||||||
if type == :code
|
if type == :code
|
||||||
@ -162,14 +162,7 @@ module Jekyll::Spaceship
|
|||||||
elsif type == :liquid_filter
|
elsif type == :liquid_filter
|
||||||
regex = /((?<!\\)((\{\{[^\n]*?\}\})|(\{%[^\n]*?%\})))/
|
regex = /((?<!\\)((\{\{[^\n]*?\}\})|(\{%[^\n]*?%\})))/
|
||||||
end
|
end
|
||||||
regexs.push regex unless regex.nil?
|
next if regex.nil?
|
||||||
end
|
|
||||||
regexs
|
|
||||||
end
|
|
||||||
|
|
||||||
def pre_exclude(content, regexs = self.exclusion_regexs())
|
|
||||||
@exclusion_store = []
|
|
||||||
regexs.each do |regex|
|
|
||||||
content.scan(regex) do |match_data|
|
content.scan(regex) do |match_data|
|
||||||
match = match_data[0]
|
match = match_data[0]
|
||||||
id = @exclusion_store.size
|
id = @exclusion_store.size
|
||||||
@ -180,7 +173,7 @@ module Jekyll::Spaceship
|
|||||||
content
|
content
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_exclude(content)
|
def after_exclude(content)
|
||||||
while @exclusion_store.size > 0
|
while @exclusion_store.size > 0
|
||||||
match = @exclusion_store.pop
|
match = @exclusion_store.pop
|
||||||
id = @exclusion_store.size
|
id = @exclusion_store.size
|
||||||
@ -199,38 +192,5 @@ module Jekyll::Spaceship
|
|||||||
end
|
end
|
||||||
content
|
content
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.fetch_img_data(url)
|
|
||||||
begin
|
|
||||||
res = Net::HTTP.get_response URI(url)
|
|
||||||
raise res.body unless res.is_a?(Net::HTTPSuccess)
|
|
||||||
content_type = res.header['Content-Type']
|
|
||||||
raise 'Unknown content type!' if content_type.nil?
|
|
||||||
content_body = res.body.force_encoding('UTF-8')
|
|
||||||
return {
|
|
||||||
'type' => content_type,
|
|
||||||
'body' => content_body
|
|
||||||
}
|
|
||||||
rescue StandardError => msg
|
|
||||||
logger.log msg
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.make_img_tag(data)
|
|
||||||
css_class = data['class']
|
|
||||||
type = data['type']
|
|
||||||
body = data['body']
|
|
||||||
if type == 'url'
|
|
||||||
"<img class=\"#{css_class}\" src=\"#{body}\">"
|
|
||||||
elsif type.include?('svg')
|
|
||||||
body.gsub(/\<\?xml.*?\?>/, '')
|
|
||||||
.gsub(/<!--[^\0]*?-->/, '')
|
|
||||||
.sub(/<svg /, "<svg class=\"#{css_class}\" ")
|
|
||||||
else
|
|
||||||
body = Base64.encode64(body)
|
|
||||||
body = "data:#{type};base64, #{body}"
|
|
||||||
"<img class=\"#{css_class}\" src=\"#{body}\">"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -62,20 +62,18 @@ module Jekyll::Spaceship
|
|||||||
def handle_mermaid(code)
|
def handle_mermaid(code)
|
||||||
# encode to UTF-8
|
# encode to UTF-8
|
||||||
code = code.encode('UTF-8')
|
code = code.encode('UTF-8')
|
||||||
|
|
||||||
url = get_url(code)
|
url = get_url(code)
|
||||||
|
|
||||||
# render mode
|
# render mode
|
||||||
case self.config['mode']
|
case self.config['mode']
|
||||||
when 'pre-fetch'
|
when 'pre-fetch'
|
||||||
data = self.class.fetch_img_data(url)
|
url = self.get_mermaid_img_data(url)
|
||||||
end
|
|
||||||
if data.nil?
|
|
||||||
data = { 'type' => 'url', 'body' => url }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# return img tag
|
# return img tag
|
||||||
data['class'] = self.config['css']['class']
|
css_class = self.config['css']['class']
|
||||||
self.class.make_img_tag(data)
|
"<img class=\"#{css_class}\" src=\"#{url}\">"
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_url(code)
|
def get_url(code)
|
||||||
@ -98,5 +96,21 @@ module Jekyll::Spaceship
|
|||||||
raise "No supported src ! #{src}"
|
raise "No supported src ! #{src}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_mermaid_img_data(url)
|
||||||
|
data = ''
|
||||||
|
begin
|
||||||
|
res = Net::HTTP.get_response URI(url)
|
||||||
|
raise res.body unless res.is_a?(Net::HTTPSuccess)
|
||||||
|
data = Base64.encode64(res.body)
|
||||||
|
content_type = res.header['Content-Type']
|
||||||
|
raise 'Unknown content type!' if content_type.nil?
|
||||||
|
data = "data:#{content_type};base64, #{data}"
|
||||||
|
rescue StandardError => msg
|
||||||
|
data = url
|
||||||
|
logger.log msg
|
||||||
|
end
|
||||||
|
data
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ module Jekyll::Spaceship
|
|||||||
'css' => {
|
'css' => {
|
||||||
'class' => 'plantuml'
|
'class' => 'plantuml'
|
||||||
},
|
},
|
||||||
'src' => 'http://www.plantuml.com/plantuml/svg/'
|
'src' => 'http://www.plantuml.com/plantuml/png/'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -59,20 +59,18 @@ module Jekyll::Spaceship
|
|||||||
def handle_plantuml(code)
|
def handle_plantuml(code)
|
||||||
# wrap plantuml code
|
# wrap plantuml code
|
||||||
code = "@startuml#{code}@enduml".encode('UTF-8')
|
code = "@startuml#{code}@enduml".encode('UTF-8')
|
||||||
url = self.get_url(code)
|
|
||||||
|
url = get_url(code)
|
||||||
|
|
||||||
# render mode
|
# render mode
|
||||||
case self.config['mode']
|
case self.config['mode']
|
||||||
when 'pre-fetch'
|
when 'pre-fetch'
|
||||||
data = self.class.fetch_img_data(url)
|
url = self.get_plantuml_img_data(url)
|
||||||
end
|
|
||||||
if data.nil?
|
|
||||||
data = { 'type' => 'url', 'body' => url }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# return img tag
|
# return img tag
|
||||||
data['class'] = self.config['css']['class']
|
css_class = self.config['css']['class']
|
||||||
self.class.make_img_tag(data)
|
"<img class=\"#{css_class}\" src=\"#{url}\">"
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_url(code)
|
def get_url(code)
|
||||||
@ -89,5 +87,21 @@ module Jekyll::Spaceship
|
|||||||
raise "No supported src ! #{src}"
|
raise "No supported src ! #{src}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_plantuml_img_data(url)
|
||||||
|
data = ''
|
||||||
|
begin
|
||||||
|
res = Net::HTTP.get_response URI(url)
|
||||||
|
raise res.body unless res.is_a?(Net::HTTPSuccess)
|
||||||
|
data = Base64.encode64(res.body)
|
||||||
|
content_type = res.header['Content-Type']
|
||||||
|
raise 'Unknown content type!' if content_type.nil?
|
||||||
|
data = "data:#{content_type};base64, #{data}"
|
||||||
|
rescue StandardError => msg
|
||||||
|
data = url
|
||||||
|
logger.log msg
|
||||||
|
end
|
||||||
|
data
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -305,12 +305,10 @@ module Jekyll::Spaceship
|
|||||||
cvter = self.converter('markdown')
|
cvter = self.converter('markdown')
|
||||||
return if cvter.nil?
|
return if cvter.nil?
|
||||||
content = cell.inner_html
|
content = cell.inner_html
|
||||||
content = self.pre_exclude(content, [/(\<code.*\>.*\<\/code\>)/])
|
|
||||||
.gsub(/(?<!\\)\|/, '\\|')
|
.gsub(/(?<!\\)\|/, '\\|')
|
||||||
.gsub(/^\s+|\s+$/, '')
|
.gsub(/^\s+|\s+$/, '')
|
||||||
.gsub(/</, '<')
|
.gsub(/</, '<')
|
||||||
.gsub(/>/, '>')
|
.gsub(/>/, '>')
|
||||||
content = self.post_exclude(content)
|
|
||||||
content = cvter.convert(content)
|
content = cvter.convert(content)
|
||||||
content = Nokogiri::HTML.fragment(content)
|
content = Nokogiri::HTML.fragment(content)
|
||||||
if content.children.first&.name == 'p'
|
if content.children.first&.name == 'p'
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
module Jekyll
|
module Jekyll
|
||||||
module Spaceship
|
module Spaceship
|
||||||
VERSION = "0.9.3"
|
VERSION = "0.9.1"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,100 +0,0 @@
|
|||||||
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
||||||
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
||||||
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
|
||||||
# this file to always be loaded, without a need to explicitly require it in any
|
|
||||||
# files.
|
|
||||||
#
|
|
||||||
# Given that it is always loaded, you are encouraged to keep this file as
|
|
||||||
# light-weight as possible. Requiring heavyweight dependencies from this file
|
|
||||||
# will add to the boot time of your test suite on EVERY test run, even for an
|
|
||||||
# individual file that may not need all of that loaded. Instead, consider making
|
|
||||||
# a separate helper file that requires the additional dependencies and performs
|
|
||||||
# the additional setup, and require it from the spec files that actually need
|
|
||||||
# it.
|
|
||||||
#
|
|
||||||
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
||||||
RSpec.configure do |config|
|
|
||||||
# rspec-expectations config goes here. You can use an alternate
|
|
||||||
# assertion/expectation library such as wrong or the stdlib/minitest
|
|
||||||
# assertions if you prefer.
|
|
||||||
config.expect_with :rspec do |expectations|
|
|
||||||
# This option will default to `true` in RSpec 4. It makes the `description`
|
|
||||||
# and `failure_message` of custom matchers include text for helper methods
|
|
||||||
# defined using `chain`, e.g.:
|
|
||||||
# be_bigger_than(2).and_smaller_than(4).description
|
|
||||||
# # => "be bigger than 2 and smaller than 4"
|
|
||||||
# ...rather than:
|
|
||||||
# # => "be bigger than 2"
|
|
||||||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
||||||
end
|
|
||||||
|
|
||||||
# rspec-mocks config goes here. You can use an alternate test double
|
|
||||||
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
|
||||||
config.mock_with :rspec do |mocks|
|
|
||||||
# Prevents you from mocking or stubbing a method that does not exist on
|
|
||||||
# a real object. This is generally recommended, and will default to
|
|
||||||
# `true` in RSpec 4.
|
|
||||||
mocks.verify_partial_doubles = true
|
|
||||||
end
|
|
||||||
|
|
||||||
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
|
||||||
# have no way to turn it off -- the option exists only for backwards
|
|
||||||
# compatibility in RSpec 3). It causes shared context metadata to be
|
|
||||||
# inherited by the metadata hash of host groups and examples, rather than
|
|
||||||
# triggering implicit auto-inclusion in groups with matching metadata.
|
|
||||||
config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
||||||
|
|
||||||
# The settings below are suggested to provide a good initial experience
|
|
||||||
# with RSpec, but feel free to customize to your heart's content.
|
|
||||||
=begin
|
|
||||||
# This allows you to limit a spec run to individual examples or groups
|
|
||||||
# you care about by tagging them with `:focus` metadata. When nothing
|
|
||||||
# is tagged with `:focus`, all examples get run. RSpec also provides
|
|
||||||
# aliases for `it`, `describe`, and `context` that include `:focus`
|
|
||||||
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
|
||||||
config.filter_run_when_matching :focus
|
|
||||||
|
|
||||||
# Allows RSpec to persist some state between runs in order to support
|
|
||||||
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
|
||||||
# you configure your source control system to ignore this file.
|
|
||||||
config.example_status_persistence_file_path = "spec/examples.txt"
|
|
||||||
|
|
||||||
# Limits the available syntax to the non-monkey patched syntax that is
|
|
||||||
# recommended. For more details, see:
|
|
||||||
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
|
||||||
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
|
||||||
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
|
||||||
config.disable_monkey_patching!
|
|
||||||
|
|
||||||
# This setting enables warnings. It's recommended, but in some cases may
|
|
||||||
# be too noisy due to issues in dependencies.
|
|
||||||
config.warnings = true
|
|
||||||
|
|
||||||
# Many RSpec users commonly either run the entire suite or an individual
|
|
||||||
# file, and it's useful to allow more verbose output when running an
|
|
||||||
# individual spec file.
|
|
||||||
if config.files_to_run.one?
|
|
||||||
# Use the documentation formatter for detailed output,
|
|
||||||
# unless a formatter has already been configured
|
|
||||||
# (e.g. via a command-line flag).
|
|
||||||
config.default_formatter = "doc"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Print the 10 slowest examples and example groups at the
|
|
||||||
# end of the spec run, to help surface which specs are running
|
|
||||||
# particularly slow.
|
|
||||||
config.profile_examples = 10
|
|
||||||
|
|
||||||
# Run specs in random order to surface order dependencies. If you find an
|
|
||||||
# order dependency and want to debug it, you can fix the order by providing
|
|
||||||
# the seed, which is printed after each run.
|
|
||||||
# --seed 1234
|
|
||||||
config.order = :random
|
|
||||||
|
|
||||||
# Seed global randomization in this process using the `--seed` CLI option.
|
|
||||||
# Setting this allows you to use `--seed` to deterministically reproduce
|
|
||||||
# test failures related to randomization by passing the same `--seed` value
|
|
||||||
# as the one that triggered the failure.
|
|
||||||
Kernel.srand config.seed
|
|
||||||
=end
|
|
||||||
end
|
|
Loading…
x
Reference in New Issue
Block a user