jekyll-uj-powertools 1.7.7 → 1.7.8
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 +4 -4
- data/jekyll-uj-powertools.gemspec +1 -1
- data/lib/hooks/markdown-images.rb +20 -9
- data/lib/tags/iffile.rb +24 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6487d4258e4c8f8afe9d43a78898cdf73339924756f0d69f7ac19edb0f42a943
|
|
4
|
+
data.tar.gz: b0d0635fcd32cb3b9b78ffa4f0f1df976e573046d1b4fb19491d53d80ad83f1e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1030ea52ac7c9e11241602dc4b80a0c71e266ee1596735cf895e317e8566fc56adc29eeb6c94a28d398ca1fb372259aef8b81789442765079a50f09e7e5b9ff3
|
|
7
|
+
data.tar.gz: 186250ac81fdcc8756dc4b2ed6c9d7c62832ed384b70471efbacaab505c2905ec094b47bdb15b43cc1eadac503fb9d7a46fc0d318295ae1d772d7d3289f781a6
|
|
@@ -18,11 +18,8 @@ module Jekyll
|
|
|
18
18
|
# Get post ID for @post/ prefix resolution
|
|
19
19
|
post_id = doc.data['post'] && doc.data['post']['id'] ? doc.data['post']['id'] : nil
|
|
20
20
|
|
|
21
|
-
#
|
|
22
|
-
|
|
23
|
-
alt_text = $1
|
|
24
|
-
image_path = $2
|
|
25
|
-
|
|
21
|
+
# Shared transformer: convert  → rendered <img> HTML
|
|
22
|
+
render_image = lambda do |alt_text, image_path|
|
|
26
23
|
# Resolve @post/ prefix to full blog image path
|
|
27
24
|
if image_path.start_with?('@post/')
|
|
28
25
|
if post_id
|
|
@@ -33,19 +30,33 @@ module Jekyll
|
|
|
33
30
|
end
|
|
34
31
|
end
|
|
35
32
|
|
|
36
|
-
# Build the Liquid tag string
|
|
37
33
|
if image_class
|
|
38
34
|
liquid_tag = "{% uj_image \"#{image_path}\", alt=\"#{alt_text}\", class=\"#{image_class}\" %}"
|
|
39
35
|
else
|
|
40
36
|
liquid_tag = "{% uj_image \"#{image_path}\", alt=\"#{alt_text}\" %}"
|
|
41
37
|
end
|
|
42
38
|
|
|
43
|
-
# Parse and render the Liquid template immediately
|
|
44
39
|
template = Liquid::Template.parse(liquid_tag)
|
|
45
40
|
context = doc.site.site_payload.merge({'page' => doc.to_liquid})
|
|
46
|
-
|
|
41
|
+
template.render(Liquid::Context.new(context))
|
|
42
|
+
end
|
|
47
43
|
|
|
48
|
-
|
|
44
|
+
# First pass: linked images [](href) → <a href><img></a>
|
|
45
|
+
# Must run BEFORE the bare-image pass so the outer [](href) wrapper is preserved.
|
|
46
|
+
# Kramdown otherwise promotes the inner  to a block and discards the wrapping link.
|
|
47
|
+
# display:block on the anchor — otherwise an inline <a> has a 20px-tall hit
|
|
48
|
+
# box, and clicks on the (taller) image overflow miss the link entirely.
|
|
49
|
+
doc.content = doc.content.gsub(/\[!\[([^\]]*)\]\(([^)]+)\)\]\(([^)]+)\)/) do
|
|
50
|
+
alt_text = $1
|
|
51
|
+
image_path = $2
|
|
52
|
+
href = $3
|
|
53
|
+
img_html = render_image.call(alt_text, image_path)
|
|
54
|
+
"\n\n<a href=\"#{href}\" style=\"display:block\">#{img_html}</a>\n\n"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Second pass: bare markdown images 
|
|
58
|
+
doc.content = doc.content.gsub(/!\[([^\]]*)\]\(([^)]+)\)/) do
|
|
59
|
+
result = render_image.call($1, $2)
|
|
49
60
|
"\n\n#{result}\n\n"
|
|
50
61
|
end
|
|
51
62
|
end
|
data/lib/tags/iffile.rb
CHANGED
|
@@ -16,11 +16,10 @@ module Jekyll
|
|
|
16
16
|
# Get the site object
|
|
17
17
|
site = context.registers[:site]
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
path = resolve_path(context)
|
|
20
|
+
|
|
22
21
|
# Return empty if path couldn't be resolved
|
|
23
|
-
return ""
|
|
22
|
+
return "" if path.nil? || path.to_s.empty?
|
|
24
23
|
|
|
25
24
|
# Ensure path starts with /
|
|
26
25
|
path = "/#{path}" unless path.to_s.start_with?('/')
|
|
@@ -39,6 +38,27 @@ module Jekyll
|
|
|
39
38
|
""
|
|
40
39
|
end
|
|
41
40
|
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
# Resolve the path argument from context.
|
|
45
|
+
# Quoted strings are literals. Bare tokens are looked up as variables;
|
|
46
|
+
# if the root segment isn't defined in context, fall back to the literal markup.
|
|
47
|
+
def resolve_path(context)
|
|
48
|
+
return nil if @path.nil? || @path.empty?
|
|
49
|
+
|
|
50
|
+
# Quoted string literal
|
|
51
|
+
if @path.match(/^["'](.*)["']$/)
|
|
52
|
+
return $1
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
root = @path.split('.').first
|
|
56
|
+
resolved = resolve_variable(context, @path)
|
|
57
|
+
return resolved unless resolved.nil?
|
|
58
|
+
|
|
59
|
+
# Variable resolved to nil — fall back to literal only if root is also nil/undefined
|
|
60
|
+
context[root].nil? ? @path : nil
|
|
61
|
+
end
|
|
42
62
|
end
|
|
43
63
|
end
|
|
44
64
|
end
|