no-style-please2-plugins 0.11.2 → 0.11.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: b4019f862d9afa74d95a4bcacd0f2c401eaf5e6317f62104582838f65c9b39b7
4
- data.tar.gz: e0fd447728fc26818fc8a78a12a99c4566ffb332cd05aa392aa5f61e75958854
3
+ metadata.gz: a6a7bd011e093cf19ae22dc2851898347f1afd2f247eb8c81274e2fd03e5f474
4
+ data.tar.gz: 693b524f338b58300871fa5db936802e527205d80aa7e04f59bd068de67128e6
5
5
  SHA512:
6
- metadata.gz: b61c348fa5d6269cf1a2563846a381dd7aebc1b0b73577a7f6b5f9779e7c1fb209ebec001c22f28a84a84f06ff554c0ac80828708266db59706def47c990db5a
7
- data.tar.gz: 0edd0b4a9dbb59130998f7061de8f834645b0609dd4795e79609c9a311acc28533a2295c1522beafd95f996491195df7a33d8a18acace67df32245d89473559e
6
+ metadata.gz: 9aa78868e4f312f3006b7a7664485279ebe4b3e4eea7e7ca05a75d5f03e5041458db7a3a5c5f8f0f5178addeab690390b51e55be8c352c144973289abddaf0ce
7
+ data.tar.gz: 76e836b48a804ef7acf37a95614f363b8ab91eb334848f5eecb52223750fba431c64b484cc1d74ab03cad1b0521ca40ab1a897796ee7fe19492035600603268e
data/lib/enc.rb CHANGED
@@ -222,6 +222,11 @@ class Test
222
222
  extend EncFilter
223
223
  end
224
224
 
225
+ class EncFilterClass
226
+ include EncFilter
227
+ end
228
+
229
+
225
230
 
226
231
 
227
232
  end
data/lib/ext.rb CHANGED
@@ -2,6 +2,7 @@ require "jekyll"
2
2
  require "liquid"
3
3
  require "fileutils"
4
4
  require 'base64'
5
+ require 'enc'
5
6
  module Jekyll
6
7
  class RenderTimeTag < Liquid::Tag
7
8
 
@@ -35,6 +36,24 @@ module Jekyll
35
36
  @img_width = arr[1]
36
37
  end
37
38
  end
39
+
40
+ def guess_image_mime_by_base64(base64_str)
41
+ prefix = base64_str[0, 15] # 取前 15 个字符足够判断
42
+
43
+ case
44
+ when prefix.start_with?('/9j/')
45
+ 'image/jpeg'
46
+ when prefix.start_with?('iVBOR')
47
+ 'image/png'
48
+ when prefix.start_with?('R0lGODdh', 'R0lGODlh')
49
+ 'image/gif'
50
+ when prefix.start_with?('UklGR')
51
+ 'image/webp'
52
+ else
53
+ 'image/png'
54
+ end
55
+ end
56
+
38
57
 
39
58
  def render(context)
40
59
  path = context['page']['path']
@@ -50,6 +69,32 @@ module Jekyll
50
69
  link = "#{base}/pics/#{dirPath}/#{@img_name}"
51
70
  end
52
71
 
72
+ enc = EncFilterClass.new
73
+ encid = enc.get_encrypt_id('',context['page'])
74
+ if !encid.nil? && encid.length > 0
75
+ begin
76
+ file = File.open(File.expand_path("pics/#{dirPath}/#{@img_name}"))
77
+ b64 = Base64.strict_encode64 file.read()
78
+ link = "data:image/#{guess_image_mime_by_base64(b64)};base64," + b64
79
+ puts "Encrypt img #{"pics/#{dirPath}/#{@img_name}"}"
80
+ rescue => exception
81
+ puts "\n----------------------------"
82
+ puts exception
83
+
84
+ puts "\nEncrypt img #{"pics/#{dirPath}/#{@img_name}"} Fail"
85
+ puts "----------------------------"
86
+
87
+ link = 'ERROR '
88
+ end
89
+
90
+
91
+
92
+
93
+
94
+ else
95
+ end
96
+
97
+
53
98
  if @img_width != nil
54
99
  return "<img src='#{link}' style='width:#{@img_width}px'>"
55
100
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NoStylePlease2
4
- VERSION = "0.11.2"
4
+ VERSION = "0.11.3"
5
5
  end
data/test.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'openssl'
4
4
  require 'base64'
5
+
5
6
  require_relative "lib/enc"
6
7
  $Key = {}
7
8
  def genKey(password)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: no-style-please2-plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - vitock