jekyll-uj-powertools 1.6.0 → 1.6.1
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/README.md +94 -0
- data/jekyll-uj-powertools.gemspec +2 -1
- data/lib/filters/main.rb +36 -18
- data/lib/generators/inject-properties.rb +23 -1
- data/lib/hooks/inject-properties.rb +10 -0
- data/lib/hooks/markdown-images.rb +40 -0
- data/lib/jekyll-uj-powertools.rb +10 -0
- data/lib/tags/fake_comments.rb +72 -0
- data/lib/tags/icon.rb +262 -0
- data/lib/tags/image.rb +208 -0
- data/lib/tags/language.rb +301 -0
- data/lib/tags/member.rb +204 -0
- data/lib/tags/post.rb +258 -0
- data/lib/tags/readtime.rb +73 -0
- data/lib/tags/social.rb +84 -0
- data/lib/tags/translation_url.rb +154 -0
- metadata +26 -2
@@ -0,0 +1,154 @@
|
|
1
|
+
# Libraries
|
2
|
+
require "jekyll"
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
class UJTranslationUrlTag < Liquid::Tag
|
6
|
+
def initialize(tag_name, markup, tokens)
|
7
|
+
super
|
8
|
+
@markup = markup.strip
|
9
|
+
end
|
10
|
+
|
11
|
+
def render(context)
|
12
|
+
# Parse arguments that can be quoted or unquoted
|
13
|
+
parts = parse_arguments(@markup)
|
14
|
+
|
15
|
+
# Return root if no arguments
|
16
|
+
return '/' if parts.empty? || parts[0].nil?
|
17
|
+
|
18
|
+
language_code_input = parts[0]
|
19
|
+
url_path_input = parts[1] || '/'
|
20
|
+
|
21
|
+
# Resolve language code (literal or variable)
|
22
|
+
language_code = resolve_argument_value(context, language_code_input)
|
23
|
+
# Resolve URL path (literal or variable)
|
24
|
+
url_path = resolve_argument_value(context, url_path_input)
|
25
|
+
|
26
|
+
# Get site and translation config from context
|
27
|
+
site = context.registers[:site]
|
28
|
+
return '/' unless site
|
29
|
+
|
30
|
+
translation_config = site.config['translation'] || {}
|
31
|
+
default_language = translation_config['default'] || 'en'
|
32
|
+
available_languages = translation_config['languages'] || [default_language]
|
33
|
+
|
34
|
+
# Validate that the requested language is available
|
35
|
+
unless available_languages.include?(language_code)
|
36
|
+
# Fall back to default language if requested language is not available
|
37
|
+
language_code = default_language
|
38
|
+
end
|
39
|
+
|
40
|
+
# Normalize the URL path
|
41
|
+
normalized_path = normalize_path(url_path)
|
42
|
+
|
43
|
+
# Generate the language-specific URL
|
44
|
+
generate_language_url(language_code, normalized_path, default_language)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def parse_arguments(markup)
|
50
|
+
# Parse arguments that can be quoted or unquoted
|
51
|
+
# Examples: 'es', '/pricing' OR language, page.canonical.path OR 'es', page.url
|
52
|
+
args = []
|
53
|
+
current_arg = ''
|
54
|
+
in_quotes = false
|
55
|
+
quote_char = nil
|
56
|
+
|
57
|
+
markup.each_char.with_index do |char, i|
|
58
|
+
if !in_quotes && (char == '"' || char == "'")
|
59
|
+
# Start of quoted string - include the quote in the arg
|
60
|
+
in_quotes = true
|
61
|
+
quote_char = char
|
62
|
+
current_arg += char
|
63
|
+
elsif in_quotes && char == quote_char
|
64
|
+
# End of quoted string - include the quote in the arg
|
65
|
+
current_arg += char
|
66
|
+
in_quotes = false
|
67
|
+
quote_char = nil
|
68
|
+
elsif !in_quotes && char == ','
|
69
|
+
# Argument separator
|
70
|
+
args << current_arg.strip
|
71
|
+
current_arg = ''
|
72
|
+
else
|
73
|
+
# Regular character
|
74
|
+
current_arg += char
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Add the last argument
|
79
|
+
args << current_arg.strip if current_arg.strip.length > 0
|
80
|
+
|
81
|
+
args
|
82
|
+
end
|
83
|
+
|
84
|
+
def resolve_argument_value(context, argument_input)
|
85
|
+
return '' if argument_input.nil? || argument_input.empty?
|
86
|
+
|
87
|
+
# Check if the argument was originally quoted (literal string)
|
88
|
+
is_quoted = argument_input.match(/^['"].*['"]$/)
|
89
|
+
|
90
|
+
# If quoted, remove quotes and use as literal. Otherwise, try to resolve as variable
|
91
|
+
if is_quoted
|
92
|
+
# Remove quotes from literal string
|
93
|
+
resolved_value = argument_input[1..-2]
|
94
|
+
else
|
95
|
+
# Try to resolve as a variable
|
96
|
+
resolved_value = resolve_variable(context, argument_input)
|
97
|
+
# If variable resolved to nil, return empty string
|
98
|
+
return '' if resolved_value.nil?
|
99
|
+
# If it didn't resolve to a string, use the resolved value
|
100
|
+
resolved_value = resolved_value.to_s if resolved_value
|
101
|
+
end
|
102
|
+
|
103
|
+
resolved_value.to_s
|
104
|
+
end
|
105
|
+
|
106
|
+
def resolve_variable(context, variable_name)
|
107
|
+
parts = variable_name.split('.')
|
108
|
+
current = context
|
109
|
+
|
110
|
+
parts.each do |part|
|
111
|
+
if current.respond_to?(:[])
|
112
|
+
current = current[part]
|
113
|
+
elsif current.respond_to?(:key?) && current.key?(part)
|
114
|
+
current = current[part]
|
115
|
+
else
|
116
|
+
return nil
|
117
|
+
end
|
118
|
+
return nil if current.nil?
|
119
|
+
end
|
120
|
+
|
121
|
+
current
|
122
|
+
end
|
123
|
+
|
124
|
+
def normalize_path(path)
|
125
|
+
return '' if path.nil? || path.empty?
|
126
|
+
|
127
|
+
# Remove leading slash for processing
|
128
|
+
clean_path = path.start_with?('/') ? path[1..-1] : path
|
129
|
+
|
130
|
+
# Handle empty path (home page)
|
131
|
+
return '' if clean_path.empty?
|
132
|
+
|
133
|
+
clean_path
|
134
|
+
end
|
135
|
+
|
136
|
+
def generate_language_url(language_code, normalized_path, default_language)
|
137
|
+
# If it's the default language, return the original path
|
138
|
+
if language_code == default_language
|
139
|
+
return normalized_path.empty? ? '/' : "/#{normalized_path}"
|
140
|
+
end
|
141
|
+
|
142
|
+
# For non-default languages, prefix with language code
|
143
|
+
if normalized_path.empty?
|
144
|
+
# Home page: /es
|
145
|
+
"/#{language_code}"
|
146
|
+
else
|
147
|
+
# Other pages: /es/pricing
|
148
|
+
"/#{language_code}/#{normalized_path}"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
Liquid::Template.register_tag('uj_translation_url', Jekyll::UJTranslationUrlTag)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-uj-powertools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ITW Creative Works
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: simplecov
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: nokogiri
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,9 +116,19 @@ files:
|
|
102
116
|
- lib/filters/main.rb
|
103
117
|
- lib/generators/inject-properties.rb
|
104
118
|
- lib/hooks/inject-properties.rb
|
119
|
+
- lib/hooks/markdown-images.rb
|
105
120
|
- lib/jekyll-uj-powertools.rb
|
121
|
+
- lib/tags/fake_comments.rb
|
122
|
+
- lib/tags/icon.rb
|
106
123
|
- lib/tags/iffalsy.rb
|
107
124
|
- lib/tags/iftruthy.rb
|
125
|
+
- lib/tags/image.rb
|
126
|
+
- lib/tags/language.rb
|
127
|
+
- lib/tags/member.rb
|
128
|
+
- lib/tags/post.rb
|
129
|
+
- lib/tags/readtime.rb
|
130
|
+
- lib/tags/social.rb
|
131
|
+
- lib/tags/translation_url.rb
|
108
132
|
homepage: https://github.com/itw-creative-works/jekyll-uj-powertools
|
109
133
|
licenses:
|
110
134
|
- MIT
|