no-style-please2-plugins 0.11.1 → 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: afe6e6995a5c47069cd2b21d4e48a1cf29afab98905f355f227e1241cb30ee4b
4
- data.tar.gz: 2c09e5836ff991484ad4ed9bd62e3c3b48e1be398bd77c66f17687bcdc854f13
3
+ metadata.gz: a6a7bd011e093cf19ae22dc2851898347f1afd2f247eb8c81274e2fd03e5f474
4
+ data.tar.gz: 693b524f338b58300871fa5db936802e527205d80aa7e04f59bd068de67128e6
5
5
  SHA512:
6
- metadata.gz: faa96fe0004c5b9a525f5feb106aaf68ad788e2659a0aaea1d3662ac3b0b177a957215e6e37adab275f2e532f9f7b53eef05be249d92ef83a2c9cefd8ae1ee44
7
- data.tar.gz: 29a9c97558cce0c387fda8a94163ffe5cb75e9d171e65424e7dcf74c25d6df2d90593e09613ab24a5d0749187141cd0a764609990b51ca12a3cddac9801d699a
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
@@ -1,7 +1,8 @@
1
1
  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
@@ -255,6 +300,78 @@ EOF
255
300
  end
256
301
  end
257
302
 
303
+
304
+ class FileBase64 < Liquid::Tag
305
+ Syntax = /\s*file\s*=\s*(\S+)/
306
+
307
+
308
+ def getPath(text,context)
309
+ rootPath = $g_config['code_root_path'] || 'static'
310
+ if text.start_with?("/")
311
+ filePath = "#{text}"[1..-1].strip()
312
+ filePath = File.expand_path(filePath)
313
+ elsif text.start_with?("@")
314
+ # _include/
315
+ filePath = "#{text}"[1..-1].strip()
316
+
317
+
318
+ site = context.registers[:site]
319
+ user_include_path = File.join(site.source, "_includes", filePath)
320
+
321
+ site = Jekyll.sites.first # 或你自己已有的 site
322
+ theme = site.theme
323
+
324
+ themeroot = theme.root # 就是当前主题的根目录
325
+ plugin_include_file = File.join(themeroot, "_includes/" + filePath)
326
+
327
+ if File.exist?(user_include_path)
328
+ filePath = user_include_path
329
+ elsif File.exist?(plugin_include_file)
330
+ filePath = plugin_include_file
331
+ else
332
+ filePath = user_include_path
333
+ end
334
+
335
+
336
+ else
337
+ filePath = "#{rootPath}/#{text}".strip()
338
+ filePath = File.expand_path(filePath)
339
+ end
340
+ return filePath
341
+ end
342
+ def initialize(tag_name, text, tokens)
343
+
344
+ @file = ""
345
+ @dynamicFile = ""
346
+
347
+ if text =~ Syntax
348
+ dynfile = Regexp.last_match(1)
349
+ @dynamicFile = dynfile.gsub(/^['"]|['"]$/, '')
350
+ else
351
+ @filename = text.gsub(/^['"]|['"]$/, '')
352
+ end
353
+
354
+
355
+
356
+ end
357
+
358
+ def render(context)
359
+ filePath = @filename
360
+ if @dynamicFile.length > 1
361
+ filePath = context[@dynamicFile]
362
+ end
363
+ filePath = getPath(filePath,context)
364
+
365
+ begin
366
+ file = File.open(filePath)
367
+ return Base64.strict_encode64 file.read()
368
+ rescue => exception
369
+ puts exception
370
+ return "Base64 file:#{filePath} failed #{@dynamicFile}"
371
+
372
+ end
373
+ end
374
+ end
258
375
 
259
376
 
260
377
 
@@ -263,6 +380,8 @@ EOF
263
380
  Liquid::Template.register_tag('asset_img', Jekyll::AssetImg)
264
381
  Liquid::Template.register_tag('include_code', Jekyll::IncludeCode)
265
382
  Liquid::Template.register_tag('include_raw', Jekyll::IncludeRaw)
383
+ Liquid::Template.register_tag('file_base64', Jekyll::FileBase64)
384
+
266
385
 
267
386
 
268
387
  Liquid::Template.register_tag('post_link', Jekyll::PostLink)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NoStylePlease2
4
- VERSION = "0.11.1"
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: no-style-please2-plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - vitock
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-26 00:00:00.000000000 Z
11
+ date: 2025-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll