metalsmith-optimize-images 0.9.3 → 0.10.0

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.
package/lib/index.js CHANGED
@@ -860,6 +860,12 @@ function replacePictureElement($, $img, variants, config) {
860
860
  */
861
861
  async function processHtmlFile(htmlFile, fileData, files, metalsmith, processedImages, debug, config) {
862
862
  debug(`Processing HTML file: ${htmlFile}`);
863
+
864
+ // Validate file.contents before processing
865
+ if (!fileData.contents || !Buffer.isBuffer(fileData.contents)) {
866
+ debug(`Skipping ${htmlFile}: invalid or missing file contents`);
867
+ return;
868
+ }
863
869
  const content = fileData.contents.toString();
864
870
 
865
871
  // Parse HTML
@@ -1089,33 +1095,8 @@ function injectProgressiveAssets($) {
1089
1095
  * Creates a responsive images plugin for Metalsmith
1090
1096
  * Generates multiple sizes and formats of images and replaces img tags with picture elements
1091
1097
  *
1092
- * @param {Object} options - Configuration options for the plugin
1093
- * @param {number[]} [options.widths] - Array of image widths to generate
1094
- * @param {string[]} [options.formats] - Array of image formats to generate (in order of preference)
1095
- * @param {Object} [options.formatOptions] - Format-specific compression settings
1096
- * @param {Object} [options.formatOptions.avif] - AVIF compression options
1097
- * @param {Object} [options.formatOptions.webp] - WebP compression options
1098
- * @param {Object} [options.formatOptions.jpeg] - JPEG compression options
1099
- * @param {Object} [options.formatOptions.png] - PNG compression options
1100
- * @param {string} [options.htmlPattern] - Glob pattern to match HTML files
1101
- * @param {string} [options.imgSelector] - CSS selector for images to process
1102
- * @param {string} [options.outputDir] - Output directory for processed images
1103
- * @param {string} [options.outputPattern] - Output naming pattern
1104
- * @param {boolean} [options.skipLarger] - Whether to skip generating sizes larger than original
1105
- * @param {boolean} [options.lazy] - Whether to add loading="lazy" to images
1106
- * @param {boolean} [options.dimensionAttributes] - Whether to add width/height attributes
1107
- * @param {string} [options.sizes] - Default sizes attribute
1108
- * @param {number} [options.concurrency] - Maximum number of images to process in parallel
1109
- * @param {boolean} [options.generateMetadata] - Whether to generate a metadata JSON file
1110
- * @param {boolean} [options.isProgressive] - Whether to use progressive image loading (default: true)
1111
- * @param {Object} [options.placeholder] - Placeholder image settings for progressive loading
1112
- * @param {number} [options.placeholder.width] - Placeholder image width (default: 50)
1113
- * @param {number} [options.placeholder.quality] - Placeholder image quality (default: 30)
1114
- * @param {number} [options.placeholder.blur] - Placeholder image blur amount (default: 10)
1115
- * @param {boolean} [options.processUnusedImages] - Whether to process unused images for background use (default: true)
1116
- * @param {string} [options.imagePattern] - Glob pattern to find images for background processing (default: `**\/*.{jpg,jpeg,png,gif,webp,avif}`)
1117
- * @param {string} [options.imageFolder] - Folder to scan for background images, relative to source (default: 'lib/assets/images')
1118
- * @return {Function} - Metalsmith plugin function
1098
+ * @param {Options} [options={}] - Configuration options for the plugin
1099
+ * @returns {import('metalsmith').Plugin} - Metalsmith plugin function
1119
1100
  */
1120
1101
  function optimizeImagesPlugin(options = {}) {
1121
1102
  // Build configuration with defaults and user options
@@ -1541,5 +1522,10 @@ function generateBackgroundVariantPath(originalPath, width, format, config) {
1541
1522
  return path.join(config.outputDir, outputName);
1542
1523
  }
1543
1524
 
1525
+ // Set function name for better debugging
1526
+ Object.defineProperty(optimizeImagesPlugin, 'name', {
1527
+ value: 'metalsmith-optimize-images'
1528
+ });
1529
+
1544
1530
  export { optimizeImagesPlugin as default };
1545
1531
  //# sourceMappingURL=index.js.map