jekyll-imgflow 0.1.7 → 0.1.9

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: 07f3c2dfe3416810827699ab3b82a29012283ad308ad215f034f1bb86d8d8a79
4
- data.tar.gz: 6ee5f237e22490069f7b3dc6ef0d8ba63a2ad8ecd1fe8a90754034a03192b11f
3
+ metadata.gz: 031d0986b4c5e0b451cc3d404eb7bc251e5ee61791fa19a9ae71ad5dc2a2e46b
4
+ data.tar.gz: 658faf7858443964c239ebbab8a343e51430c1c5043cf6e413c3c2463d4b68a8
5
5
  SHA512:
6
- metadata.gz: e8da1e7ca9f599f6e1dcfbe5b2a44277ec53edd42b57e34159af1090e0fafcf068b361ac0713ba8932e4acb213f3569a268ffc1471c43c21ffd5845734769315
7
- data.tar.gz: 4c7014c3888b5d4a2c94022f89eab3a383edf315fe34b556f3b727d7483f883b0b40ac772ab05fd51d37ab5d900122385d0887052bc6508085a2513dce339d0d
6
+ metadata.gz: 349afebeceaea49781508b0156177cc07eb1cf0d440ef3fe9754cfec279428b76d9ca2716b991744d66523c16a42102c8a31055864612bcb921b313a69d0c900
7
+ data.tar.gz: aef1c22691523d287e2aebb7c4e12f8247f7e2cb9b9999ee0368373141c3eddb88c02c96198bf97364a8e04565d09063f447c33d2cdc89af3b5826f40bedcc15
data/README.md CHANGED
@@ -5,6 +5,7 @@ A [Jekyll](https://jekyllrb.com/) plugin for automatic image optimization with m
5
5
  [![DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/gundestrup/jekyll-imgflow)
6
6
  [![Status](https://img.shields.io/badge/status-active-success)](https://github.com/gundestrup/jekyll-imgflow)
7
7
  [![codecov](https://codecov.io/gh/gundestrup/jekyll-imgflow/branch/main/graph/badge.svg)](https://codecov.io/gh/gundestrup/jekyll-imgflow)
8
+ [![VS Code Extension](https://img.shields.io/badge/VS%20Code%20Companion-jekyll--imgflow-blue?logo=visual-studio-code)](https://github.com/gundestrup/jekyll-imgflow-vscode)
8
9
  [![License](https://img.shields.io/github/license/gundestrup/jekyll-imgflow)](LICENSE)
9
10
 
10
11
  ## 🚀 Quick Start
@@ -32,9 +33,11 @@ imgflow:
32
33
  > and [Configuration Reference](docs/ARCHITECTURE.md).
33
34
 
34
35
  > **Note:** Image references require exact filenames (or paths relative to
35
- > `originals`). There is no fuzzy matching or autocomplete yet — if you type
36
+ > `originals`). There is no fuzzy matching during the build yet — if you type
36
37
  > `photo.jpg` but the file is `photo.jpeg`, the build will fail with an error.
37
- > Future versions may add "did you mean" suggestions.
38
+ >
39
+ > For editor autocomplete while writing `{% imgflow %}` tags, install the
40
+ > [VS Code companion extension](https://github.com/gundestrup/jekyll-imgflow-vscode).
38
41
 
39
42
  ## ✨ Key Features
40
43
 
@@ -213,8 +213,13 @@ module JekyllImgFlow
213
213
  # Use FilenameGenerator to generate proper filename
214
214
  operations = { width: width, format: format, quality: config.quality }
215
215
  filename = filename_generator.generate_filename(original_name, operations)
216
+
217
+ # Preserve original directory structure under output
218
+ subdir = File.dirname(original_name)
219
+ subdir = nil if subdir == "."
220
+
216
221
  # Write to source directory so Jekyll copies files to _site during write phase
217
- output_path = path_resolver.resolve_source_output_path(filename)
222
+ output_path = path_resolver.resolve_source_output_path(filename, subdir)
218
223
 
219
224
  tasks << {
220
225
  original_name: original_name,
@@ -42,12 +42,14 @@ module JekyllImgFlow
42
42
  original_paths = find_original_images
43
43
  Jekyll.logger.info "📸 Found #{original_paths.length} original images"
44
44
 
45
+ originals_dir = File.join(@site.source, @config.originals)
46
+
45
47
  # Build tasks for each original image
46
48
  original_paths.each do |path|
47
- original_name = File.basename(path)
49
+ original_name = path.sub("#{originals_dir}/", "")
48
50
 
49
51
  # Check if needs processing (file changed or provider changed)
50
- if needs_processing?(path)
52
+ if needs_processing?(original_name, path)
51
53
  Jekyll.logger.info "🔧 Queuing default versions for: #{original_name}"
52
54
 
53
55
  # Build default tasks
@@ -84,8 +86,10 @@ module JekyllImgFlow
84
86
  provider_name = @registry.current_provider.class.name.split("::").last.downcase
85
87
 
86
88
  # Convert absolute path to relative for manifest storage
89
+ # Default versions are written to the source directory so Jekyll can
90
+ # copy them to _site during the write phase.
87
91
  absolute_path = task[:result]
88
- relative_path = absolute_path.sub(@site.dest, "")
92
+ relative_path = absolute_path.sub(@site.source, "")
89
93
 
90
94
  # Register the version in manifest
91
95
  @manifest.register_version(
@@ -113,10 +117,13 @@ module JekyllImgFlow
113
117
  end
114
118
 
115
119
  # Check if image needs processing
116
- # @param path [String] Path to original image
120
+ # @param original_name [String] Path to original image relative to originals directory
121
+ # @param path [String, nil] Full path to original image (defaults to original_name)
117
122
  # @return [Boolean] True if processing needed
118
- def needs_processing?(path)
119
- original_name = File.basename(path)
123
+ def needs_processing?(original_name, path = nil)
124
+ path ||= original_name
125
+ # For single-argument calls, derive a flat original_name from the full path
126
+ original_name = File.basename(original_name) if original_name == path
120
127
 
121
128
  # If no versions exist, needs processing
122
129
  return true unless @manifest.versions?(original_name)
@@ -64,7 +64,15 @@ module Jekyll
64
64
 
65
65
  site = context.registers[:site]
66
66
  page = context.registers[:page]
67
- original_name = File.basename(parsed[:image_path])
67
+
68
+ # Resolve input path
69
+ input_path = resolve_image_path(parsed[:image_path], site, components[:config])
70
+ raise ArgumentError, "Input image file not found: #{input_path}" unless File.file?(input_path)
71
+
72
+ # Store original name relative to the configured originals directory
73
+ # so output can mirror the original directory structure
74
+ originals_dir = File.join(site.source, components[:config].originals)
75
+ original_name = input_path.sub("#{originals_dir}/", "")
68
76
 
69
77
  # Get page path for manifest tracking
70
78
  # Try multiple attributes to get the page identifier
@@ -74,10 +82,6 @@ module Jekyll
74
82
  "unknown"
75
83
  end
76
84
 
77
- # Resolve input path
78
- input_path = resolve_image_path(parsed[:image_path], site, components[:config])
79
- raise ArgumentError, "Input image file not found: #{input_path}" unless File.file?(input_path)
80
-
81
85
  # Process operations using clean architecture
82
86
  operations = parsed[:operations]
83
87
 
@@ -96,8 +100,12 @@ module Jekyll
96
100
  params[:quality] ||= components[:config].quality # Use default quality
97
101
  end
98
102
 
103
+ # Preserve original directory structure under output
104
+ subdir = File.dirname(original_name)
105
+ subdir = nil if subdir == "."
106
+
99
107
  filename = components[:filename_generator].generate_filename(input_path, params)
100
- output_path = components[:path_resolver].resolve_source_output_path(filename)
108
+ output_path = components[:path_resolver].resolve_source_output_path(filename, subdir)
101
109
 
102
110
  # Determine version type
103
111
  version_type = determine_version_type(params, components[:config])
@@ -199,12 +207,16 @@ module Jekyll
199
207
  path_resolver = JekyllImgFlow::PathResolver.new(config)
200
208
 
201
209
  # Handle different path formats
202
- if image_path.start_with?("/") || image_path.include?("/")
203
- # Absolute or relative path
204
- File.join(site.source, image_path)
210
+ normalized_path = image_path.delete_prefix("/")
211
+ originals_prefix = "#{config.originals.chomp('/')}/"
212
+
213
+ if image_path.start_with?("/") || normalized_path.start_with?(originals_prefix)
214
+ # Site-root path, with or without a leading slash:
215
+ # /assets/images/originals/valdemar/photo.jpg
216
+ File.join(site.source, normalized_path)
205
217
  else
206
- # Use PathResolver to get CLI path (full filesystem path)
207
- path_resolver.cli_path(image_path)
218
+ # Originals-relative path: photo.jpg or valdemar/photo.jpg
219
+ path_resolver.cli_path(normalized_path)
208
220
  end
209
221
  end
210
222
 
@@ -42,13 +42,18 @@ module JekyllImgFlow
42
42
  type = operation[:type]
43
43
  params = operation[:params]
44
44
 
45
+ # Determine version type
46
+ version_type = determine_version_type(params)
47
+
48
+ # Preserve original directory structure under output
49
+ subdir = File.dirname(original_name)
50
+ subdir = nil if subdir == "."
51
+
45
52
  # Generate filename using FilenameGenerator (JPT compatible)
46
53
  filename = @filename_generator.generate_filename(input_path, params)
47
- # Write to source directory so Jekyll copies files to _site during write phase
48
- actual_output_path = @path_resolver.resolve_source_output_path(filename)
49
54
 
50
- # Determine version type
51
- version_type = determine_version_type(params)
55
+ # Write to source directory so Jekyll copies files to _site during the write phase
56
+ actual_output_path = @path_resolver.resolve_source_output_path(filename, subdir)
52
57
 
53
58
  # Ensure output directory exists before processing
54
59
  FileUtils.mkdir_p(File.dirname(actual_output_path))
@@ -69,7 +74,7 @@ module JekyllImgFlow
69
74
  # Register in manifest
70
75
  if @manifest
71
76
  # Store relative path (with leading /) for manifest storage
72
- relative_path = "/#{@path_resolver.resolve_relative_output_path(filename)}"
77
+ relative_path = "/#{@path_resolver.resolve_relative_output_path(filename, subdir)}"
73
78
 
74
79
  provider_name = @provider.class.provider_name
75
80
  @manifest.register_version(
@@ -61,26 +61,29 @@ module JekyllImgFlow
61
61
 
62
62
  # Resolve output path for generated filename
63
63
  # @param filename [String] Generated filename
64
+ # @param subdir [String, nil] Optional subdirectory under output
64
65
  # @return [String] Full path to output file in _site (for specialized versions during rendering)
65
- def resolve_output_path(filename)
66
+ def resolve_output_path(filename, subdir = nil)
66
67
  # Resolve output path relative to site destination
67
- File.join(@config.site.dest, @config.output, filename)
68
+ File.join([@config.site.dest, @config.output, subdir, filename].compact)
68
69
  end
69
70
 
70
71
  # Resolve output path to source directory for default images
71
72
  # @param filename [String] Generated filename
73
+ # @param subdir [String, nil] Optional subdirectory under output
72
74
  # @return [String] Full path to output file in source (for default versions during pre_render)
73
- def resolve_source_output_path(filename)
75
+ def resolve_source_output_path(filename, subdir = nil)
74
76
  # Default images go to source directory so Jekyll can copy them to _site
75
- File.join(@config.site.source, @config.output, filename)
77
+ File.join([@config.site.source, @config.output, subdir, filename].compact)
76
78
  end
77
79
 
78
80
  # Resolve relative output path for manifest storage
79
81
  # @param filename [String] Generated filename
82
+ # @param subdir [String, nil] Optional subdirectory under output
80
83
  # @return [String] Relative path from site root
81
- def resolve_relative_output_path(filename)
84
+ def resolve_relative_output_path(filename, subdir = nil)
82
85
  # Return path relative to site root (without leading /)
83
- File.join(@config.output, filename)
86
+ File.join([@config.output, subdir, filename].compact)
84
87
  end
85
88
 
86
89
  # Get site destination directory
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllImgFlow
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.9"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-imgflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Svend Gundestrup