simple-photo-gallery 2.0.11-rc.5 → 2.0.11-rc.7

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/dist/index.js CHANGED
@@ -46,9 +46,9 @@ async function cropAndResizeImage(image, outputPath, width, height, format = "av
46
46
  withoutEnlargement: true
47
47
  }).toFormat(format).toFile(outputPath);
48
48
  }
49
- async function getImageDescription(imagePath) {
49
+ async function getImageDescription(image) {
50
50
  try {
51
- const tags = await ExifReader.load(imagePath);
51
+ const tags = await ExifReader.load(image);
52
52
  if (tags.description?.description) return tags.description.description;
53
53
  if (tags.ImageDescription?.description) return tags.ImageDescription.description;
54
54
  if (tags.UserComment && typeof tags.UserComment === "object" && tags.UserComment !== null && "description" in tags.UserComment) {
@@ -94,10 +94,10 @@ async function generateBlurHash(imagePath, componentX = 4, componentY = 3) {
94
94
  // src/modules/build/utils/index.ts
95
95
  path7.dirname(new URL(import.meta.url).pathname);
96
96
  async function createGallerySocialMediaCardImage(headerPhotoPath, title, ouputPath, ui) {
97
- ui.start(`Creating social media card image`);
97
+ ui?.start(`Creating social media card image`);
98
98
  const headerBasename = path7.basename(headerPhotoPath, path7.extname(headerPhotoPath));
99
99
  if (fs8.existsSync(ouputPath)) {
100
- ui.success(`Social media card image already exists`);
100
+ ui?.success(`Social media card image already exists`);
101
101
  return headerBasename;
102
102
  }
103
103
  const image = await loadImage(headerPhotoPath);
@@ -116,23 +116,23 @@ async function createGallerySocialMediaCardImage(headerPhotoPath, title, ouputPa
116
116
  `;
117
117
  const finalImageBuffer = await sharp2(resizedImageBuffer).composite([{ input: Buffer.from(svgText), top: 0, left: 0 }]).jpeg({ quality: 90 }).toBuffer();
118
118
  await sharp2(finalImageBuffer).toFile(outputPath);
119
- ui.success(`Created social media card image successfully`);
119
+ ui?.success(`Created social media card image successfully`);
120
120
  return headerBasename;
121
121
  }
122
122
  async function createOptimizedHeaderImage(headerPhotoPath, outputFolder, ui) {
123
- ui.start(`Creating optimized header images`);
123
+ ui?.start(`Creating optimized header images`);
124
124
  const image = await loadImage(headerPhotoPath);
125
125
  const headerBasename = path7.basename(headerPhotoPath, path7.extname(headerPhotoPath));
126
126
  const generatedFiles = [];
127
- ui.debug("Generating blurhash for header image");
127
+ ui?.debug("Generating blurhash for header image");
128
128
  const blurHash = await generateBlurHash(headerPhotoPath);
129
129
  const landscapeYFactor = 3 / 4;
130
130
  for (const width of HEADER_IMAGE_LANDSCAPE_WIDTHS) {
131
- ui.debug(`Creating landscape header image ${width}`);
131
+ ui?.debug(`Creating landscape header image ${width}`);
132
132
  const avifFilename = `${headerBasename}_landscape_${width}.avif`;
133
133
  const jpgFilename = `${headerBasename}_landscape_${width}.jpg`;
134
134
  if (fs8.existsSync(path7.join(outputFolder, avifFilename))) {
135
- ui.debug(`Landscape header image ${width} AVIF already exists`);
135
+ ui?.debug(`Landscape header image ${width} AVIF already exists`);
136
136
  } else {
137
137
  await cropAndResizeImage(
138
138
  image.clone(),
@@ -144,7 +144,7 @@ async function createOptimizedHeaderImage(headerPhotoPath, outputFolder, ui) {
144
144
  }
145
145
  generatedFiles.push(avifFilename);
146
146
  if (fs8.existsSync(path7.join(outputFolder, jpgFilename))) {
147
- ui.debug(`Landscape header image ${width} JPG already exists`);
147
+ ui?.debug(`Landscape header image ${width} JPG already exists`);
148
148
  } else {
149
149
  await cropAndResizeImage(image.clone(), path7.join(outputFolder, jpgFilename), width, width * landscapeYFactor, "jpg");
150
150
  }
@@ -152,23 +152,23 @@ async function createOptimizedHeaderImage(headerPhotoPath, outputFolder, ui) {
152
152
  }
153
153
  const portraitYFactor = 4 / 3;
154
154
  for (const width of HEADER_IMAGE_PORTRAIT_WIDTHS) {
155
- ui.debug(`Creating portrait header image ${width}`);
155
+ ui?.debug(`Creating portrait header image ${width}`);
156
156
  const avifFilename = `${headerBasename}_portrait_${width}.avif`;
157
157
  const jpgFilename = `${headerBasename}_portrait_${width}.jpg`;
158
158
  if (fs8.existsSync(path7.join(outputFolder, avifFilename))) {
159
- ui.debug(`Portrait header image ${width} AVIF already exists`);
159
+ ui?.debug(`Portrait header image ${width} AVIF already exists`);
160
160
  } else {
161
161
  await cropAndResizeImage(image.clone(), path7.join(outputFolder, avifFilename), width, width * portraitYFactor, "avif");
162
162
  }
163
163
  generatedFiles.push(avifFilename);
164
164
  if (fs8.existsSync(path7.join(outputFolder, jpgFilename))) {
165
- ui.debug(`Portrait header image ${width} JPG already exists`);
165
+ ui?.debug(`Portrait header image ${width} JPG already exists`);
166
166
  } else {
167
167
  await cropAndResizeImage(image.clone(), path7.join(outputFolder, jpgFilename), width, width * portraitYFactor, "jpg");
168
168
  }
169
169
  generatedFiles.push(jpgFilename);
170
170
  }
171
- ui.success(`Created optimized header image successfully`);
171
+ ui?.success(`Created optimized header image successfully`);
172
172
  return { headerBasename, generatedFiles, blurHash };
173
173
  }
174
174
  function hasOldHeaderImages(outputFolder, currentHeaderBasename) {
@@ -186,9 +186,9 @@ function hasOldHeaderImages(outputFolder, currentHeaderBasename) {
186
186
  return false;
187
187
  }
188
188
  function cleanupOldHeaderImages(outputFolder, currentHeaderBasename, ui) {
189
- ui.start(`Cleaning up old header images`);
189
+ ui?.start(`Cleaning up old header images`);
190
190
  if (!fs8.existsSync(outputFolder)) {
191
- ui.debug(`Output folder ${outputFolder} does not exist, skipping cleanup`);
191
+ ui?.debug(`Output folder ${outputFolder} does not exist, skipping cleanup`);
192
192
  return;
193
193
  }
194
194
  const files = fs8.readdirSync(outputFolder);
@@ -198,20 +198,20 @@ function cleanupOldHeaderImages(outputFolder, currentHeaderBasename, ui) {
198
198
  const portraitMatch = file.match(/^(.+)_portrait_\d+\.(avif|jpg)$/);
199
199
  if (landscapeMatch && landscapeMatch[1] !== currentHeaderBasename) {
200
200
  const filePath = path7.join(outputFolder, file);
201
- ui.debug(`Deleting old landscape header image: ${file}`);
201
+ ui?.debug(`Deleting old landscape header image: ${file}`);
202
202
  fs8.unlinkSync(filePath);
203
203
  deletedCount++;
204
204
  } else if (portraitMatch && portraitMatch[1] !== currentHeaderBasename) {
205
205
  const filePath = path7.join(outputFolder, file);
206
- ui.debug(`Deleting old portrait header image: ${file}`);
206
+ ui?.debug(`Deleting old portrait header image: ${file}`);
207
207
  fs8.unlinkSync(filePath);
208
208
  deletedCount++;
209
209
  }
210
210
  }
211
211
  if (deletedCount > 0) {
212
- ui.success(`Deleted ${deletedCount} old header image(s)`);
212
+ ui?.success(`Deleted ${deletedCount} old header image(s)`);
213
213
  } else {
214
- ui.debug(`No old header images to clean up`);
214
+ ui?.debug(`No old header images to clean up`);
215
215
  }
216
216
  }
217
217
  function findGalleries(basePath, recursive) {
@@ -626,7 +626,7 @@ async function processVideo(videoPath, thumbnailPath, thumbnailPathRetina, thumb
626
626
  lastMediaTimestamp: fileMtime.toISOString()
627
627
  };
628
628
  }
629
- async function processMediaFile(mediaFile, mediaBasePath, galleryDir, thumbnailsPath, thumbnailSize, ui) {
629
+ async function processMediaFile(mediaFile, mediaBasePath, thumbnailsPath, thumbnailSize, ui) {
630
630
  try {
631
631
  const filePath = path7.resolve(path7.join(mediaBasePath, mediaFile.filename));
632
632
  const fileName = mediaFile.filename;
@@ -679,14 +679,7 @@ async function processGalleryThumbnails(galleryDir, ui) {
679
679
  let processedCount = 0;
680
680
  for (const section of galleryData.sections) {
681
681
  for (const [index, mediaFile] of section.images.entries()) {
682
- section.images[index] = await processMediaFile(
683
- mediaFile,
684
- mediaBasePath,
685
- galleryDir,
686
- thumbnailsPath,
687
- thumbnailSize,
688
- ui
689
- );
682
+ section.images[index] = await processMediaFile(mediaFile, mediaBasePath, thumbnailsPath, thumbnailSize, ui);
690
683
  }
691
684
  processedCount += section.images.length;
692
685
  }
@@ -881,26 +874,26 @@ async function cleanGallery(galleryDir, ui) {
881
874
  if (fs8.existsSync(indexHtmlPath)) {
882
875
  try {
883
876
  fs8.rmSync(indexHtmlPath);
884
- ui.debug(`Removed: ${indexHtmlPath}`);
877
+ ui?.debug(`Removed: ${indexHtmlPath}`);
885
878
  filesRemoved++;
886
879
  } catch (error) {
887
- ui.warn(`Failed to remove index.html: ${error}`);
880
+ ui?.warn(`Failed to remove index.html: ${error}`);
888
881
  }
889
882
  }
890
883
  const galleryPath = path7.join(galleryDir, "gallery");
891
884
  if (fs8.existsSync(galleryPath)) {
892
885
  try {
893
886
  fs8.rmSync(galleryPath, { recursive: true, force: true });
894
- ui.debug(`Removed directory: ${galleryPath}`);
887
+ ui?.debug(`Removed directory: ${galleryPath}`);
895
888
  filesRemoved++;
896
889
  } catch (error) {
897
- ui.warn(`Failed to remove gallery directory: ${error}`);
890
+ ui?.warn(`Failed to remove gallery directory: ${error}`);
898
891
  }
899
892
  }
900
893
  if (filesRemoved > 0) {
901
- ui.success(`Cleaned gallery at: ${galleryDir}`);
894
+ ui?.success(`Cleaned gallery at: ${galleryDir}`);
902
895
  } else {
903
- ui.info(`No gallery files found at: ${galleryDir}`);
896
+ ui?.info(`No gallery files found at: ${galleryDir}`);
904
897
  }
905
898
  return { processedGalleryCount: filesRemoved };
906
899
  }
@@ -1164,7 +1157,7 @@ async function waitForUpdateCheck(checkPromise) {
1164
1157
  // package.json
1165
1158
  var package_default = {
1166
1159
  name: "simple-photo-gallery",
1167
- version: "2.0.11-rc.5"};
1160
+ version: "2.0.11-rc.7"};
1168
1161
 
1169
1162
  // src/index.ts
1170
1163
  var program = new Command();