simple-photo-gallery 2.0.11 → 2.0.12
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.cjs +89 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +88 -79
- package/dist/index.js.map +1 -1
- package/dist/lib/index.cjs +18 -9
- package/dist/lib/index.cjs.map +1 -1
- package/dist/lib/index.js +18 -9
- package/dist/lib/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var commander = require('commander');
|
|
|
6
6
|
var consola = require('consola');
|
|
7
7
|
var child_process = require('child_process');
|
|
8
8
|
var fs8 = require('fs');
|
|
9
|
-
var
|
|
9
|
+
var path = require('path');
|
|
10
10
|
var buffer = require('buffer');
|
|
11
11
|
var url = require('url');
|
|
12
12
|
var sharp2 = require('sharp');
|
|
@@ -24,7 +24,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
24
24
|
|
|
25
25
|
var process4__default = /*#__PURE__*/_interopDefault(process4);
|
|
26
26
|
var fs8__default = /*#__PURE__*/_interopDefault(fs8);
|
|
27
|
-
var
|
|
27
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
28
28
|
var sharp2__default = /*#__PURE__*/_interopDefault(sharp2);
|
|
29
29
|
var ExifReader__default = /*#__PURE__*/_interopDefault(ExifReader);
|
|
30
30
|
var ffprobe__default = /*#__PURE__*/_interopDefault(ffprobe);
|
|
@@ -92,36 +92,42 @@ async function generateBlurHash(imagePath, componentX = 4, componentY = 3) {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
// src/modules/build/utils/index.ts
|
|
95
|
-
var __dirname$1 =
|
|
96
|
-
var SOCIAL_CARD_FONT_RELATIVE_PATH =
|
|
95
|
+
var __dirname$1 = path__default.default.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
96
|
+
var SOCIAL_CARD_FONT_RELATIVE_PATH = path__default.default.join("assets", "fonts", "dejavu", "DejaVuSans-Bold.ttf");
|
|
97
97
|
var socialCardFontBase64;
|
|
98
98
|
function resolveFromCurrentDir(...segments) {
|
|
99
|
-
return
|
|
99
|
+
return path__default.default.resolve(__dirname$1, ...segments);
|
|
100
100
|
}
|
|
101
101
|
function findSocialCardFontPath() {
|
|
102
102
|
const fontCandidates = [
|
|
103
103
|
resolveFromCurrentDir("../../../../", SOCIAL_CARD_FONT_RELATIVE_PATH),
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
path__default.default.resolve(__dirname$1, "../", SOCIAL_CARD_FONT_RELATIVE_PATH),
|
|
105
|
+
path__default.default.resolve(__dirname$1, "../../", SOCIAL_CARD_FONT_RELATIVE_PATH),
|
|
106
|
+
path__default.default.resolve(process4__default.default.cwd(), SOCIAL_CARD_FONT_RELATIVE_PATH),
|
|
107
|
+
path__default.default.resolve(process4__default.default.cwd(), "../", SOCIAL_CARD_FONT_RELATIVE_PATH)
|
|
106
108
|
];
|
|
107
109
|
for (const candidate of fontCandidates) {
|
|
108
110
|
if (fs8__default.default.existsSync(candidate)) {
|
|
109
111
|
return candidate;
|
|
110
112
|
}
|
|
111
113
|
}
|
|
112
|
-
|
|
114
|
+
return null;
|
|
113
115
|
}
|
|
114
116
|
function getSocialCardFontBase64() {
|
|
115
|
-
if (socialCardFontBase64) {
|
|
117
|
+
if (socialCardFontBase64 !== void 0) {
|
|
116
118
|
return socialCardFontBase64;
|
|
117
119
|
}
|
|
118
120
|
const fontPath = findSocialCardFontPath();
|
|
121
|
+
if (!fontPath) {
|
|
122
|
+
socialCardFontBase64 = null;
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
119
125
|
socialCardFontBase64 = fs8__default.default.readFileSync(fontPath).toString("base64");
|
|
120
126
|
return socialCardFontBase64;
|
|
121
127
|
}
|
|
122
128
|
async function createGallerySocialMediaCardImage(headerPhotoPath, title, ouputPath, ui) {
|
|
123
129
|
ui?.start(`Creating social media card image`);
|
|
124
|
-
const headerBasename =
|
|
130
|
+
const headerBasename = path__default.default.basename(headerPhotoPath, path__default.default.extname(headerPhotoPath));
|
|
125
131
|
if (fs8__default.default.existsSync(ouputPath)) {
|
|
126
132
|
ui?.success(`Social media card image already exists`);
|
|
127
133
|
return headerBasename;
|
|
@@ -131,17 +137,20 @@ async function createGallerySocialMediaCardImage(headerPhotoPath, title, ouputPa
|
|
|
131
137
|
const outputPath = ouputPath;
|
|
132
138
|
await sharp2__default.default(resizedImageBuffer).toFile(outputPath);
|
|
133
139
|
const fontBase64 = getSocialCardFontBase64();
|
|
134
|
-
const
|
|
135
|
-
<svg width="1200" height="631" xmlns="http://www.w3.org/2000/svg">
|
|
136
|
-
<defs>
|
|
137
|
-
<style>
|
|
140
|
+
const fontFace = fontBase64 ? `
|
|
138
141
|
@font-face {
|
|
139
142
|
font-family: 'DejaVu Sans';
|
|
140
143
|
src: url('data:font/ttf;base64,${fontBase64}') format('truetype');
|
|
141
144
|
font-weight: 700;
|
|
142
145
|
font-style: normal;
|
|
143
|
-
}
|
|
144
|
-
|
|
146
|
+
}` : "";
|
|
147
|
+
const fontFamily = fontBase64 ? "'DejaVu Sans', Arial, sans-serif" : "Arial, sans-serif";
|
|
148
|
+
const svgText = `
|
|
149
|
+
<svg width="1200" height="631" xmlns="http://www.w3.org/2000/svg">
|
|
150
|
+
<defs>
|
|
151
|
+
<style>
|
|
152
|
+
${fontFace}
|
|
153
|
+
.title { font-family: ${fontFamily}; font-size: 96px; font-weight: bold; fill: white; stroke: black; stroke-width: 5; paint-order: stroke; text-anchor: middle; }
|
|
145
154
|
</style>
|
|
146
155
|
</defs>
|
|
147
156
|
<text x="600" y="250" class="title">${title}</text>
|
|
@@ -155,7 +164,7 @@ async function createGallerySocialMediaCardImage(headerPhotoPath, title, ouputPa
|
|
|
155
164
|
async function createOptimizedHeaderImage(headerPhotoPath, outputFolder, ui) {
|
|
156
165
|
ui?.start(`Creating optimized header images`);
|
|
157
166
|
const image = await loadImage(headerPhotoPath);
|
|
158
|
-
const headerBasename =
|
|
167
|
+
const headerBasename = path__default.default.basename(headerPhotoPath, path__default.default.extname(headerPhotoPath));
|
|
159
168
|
const generatedFiles = [];
|
|
160
169
|
ui?.debug("Generating blurhash for header image");
|
|
161
170
|
const blurHash = await generateBlurHash(headerPhotoPath);
|
|
@@ -164,22 +173,22 @@ async function createOptimizedHeaderImage(headerPhotoPath, outputFolder, ui) {
|
|
|
164
173
|
ui?.debug(`Creating landscape header image ${width}`);
|
|
165
174
|
const avifFilename = `${headerBasename}_landscape_${width}.avif`;
|
|
166
175
|
const jpgFilename = `${headerBasename}_landscape_${width}.jpg`;
|
|
167
|
-
if (fs8__default.default.existsSync(
|
|
176
|
+
if (fs8__default.default.existsSync(path__default.default.join(outputFolder, avifFilename))) {
|
|
168
177
|
ui?.debug(`Landscape header image ${width} AVIF already exists`);
|
|
169
178
|
} else {
|
|
170
179
|
await cropAndResizeImage(
|
|
171
180
|
image.clone(),
|
|
172
|
-
|
|
181
|
+
path__default.default.join(outputFolder, avifFilename),
|
|
173
182
|
width,
|
|
174
183
|
width * landscapeYFactor,
|
|
175
184
|
"avif"
|
|
176
185
|
);
|
|
177
186
|
}
|
|
178
187
|
generatedFiles.push(avifFilename);
|
|
179
|
-
if (fs8__default.default.existsSync(
|
|
188
|
+
if (fs8__default.default.existsSync(path__default.default.join(outputFolder, jpgFilename))) {
|
|
180
189
|
ui?.debug(`Landscape header image ${width} JPG already exists`);
|
|
181
190
|
} else {
|
|
182
|
-
await cropAndResizeImage(image.clone(),
|
|
191
|
+
await cropAndResizeImage(image.clone(), path__default.default.join(outputFolder, jpgFilename), width, width * landscapeYFactor, "jpg");
|
|
183
192
|
}
|
|
184
193
|
generatedFiles.push(jpgFilename);
|
|
185
194
|
}
|
|
@@ -188,16 +197,16 @@ async function createOptimizedHeaderImage(headerPhotoPath, outputFolder, ui) {
|
|
|
188
197
|
ui?.debug(`Creating portrait header image ${width}`);
|
|
189
198
|
const avifFilename = `${headerBasename}_portrait_${width}.avif`;
|
|
190
199
|
const jpgFilename = `${headerBasename}_portrait_${width}.jpg`;
|
|
191
|
-
if (fs8__default.default.existsSync(
|
|
200
|
+
if (fs8__default.default.existsSync(path__default.default.join(outputFolder, avifFilename))) {
|
|
192
201
|
ui?.debug(`Portrait header image ${width} AVIF already exists`);
|
|
193
202
|
} else {
|
|
194
|
-
await cropAndResizeImage(image.clone(),
|
|
203
|
+
await cropAndResizeImage(image.clone(), path__default.default.join(outputFolder, avifFilename), width, width * portraitYFactor, "avif");
|
|
195
204
|
}
|
|
196
205
|
generatedFiles.push(avifFilename);
|
|
197
|
-
if (fs8__default.default.existsSync(
|
|
206
|
+
if (fs8__default.default.existsSync(path__default.default.join(outputFolder, jpgFilename))) {
|
|
198
207
|
ui?.debug(`Portrait header image ${width} JPG already exists`);
|
|
199
208
|
} else {
|
|
200
|
-
await cropAndResizeImage(image.clone(),
|
|
209
|
+
await cropAndResizeImage(image.clone(), path__default.default.join(outputFolder, jpgFilename), width, width * portraitYFactor, "jpg");
|
|
201
210
|
}
|
|
202
211
|
generatedFiles.push(jpgFilename);
|
|
203
212
|
}
|
|
@@ -230,12 +239,12 @@ function cleanupOldHeaderImages(outputFolder, currentHeaderBasename, ui) {
|
|
|
230
239
|
const landscapeMatch = file.match(/^(.+)_landscape_\d+\.(avif|jpg)$/);
|
|
231
240
|
const portraitMatch = file.match(/^(.+)_portrait_\d+\.(avif|jpg)$/);
|
|
232
241
|
if (landscapeMatch && landscapeMatch[1] !== currentHeaderBasename) {
|
|
233
|
-
const filePath =
|
|
242
|
+
const filePath = path__default.default.join(outputFolder, file);
|
|
234
243
|
ui?.debug(`Deleting old landscape header image: ${file}`);
|
|
235
244
|
fs8__default.default.unlinkSync(filePath);
|
|
236
245
|
deletedCount++;
|
|
237
246
|
} else if (portraitMatch && portraitMatch[1] !== currentHeaderBasename) {
|
|
238
|
-
const filePath =
|
|
247
|
+
const filePath = path__default.default.join(outputFolder, file);
|
|
239
248
|
ui?.debug(`Deleting old portrait header image: ${file}`);
|
|
240
249
|
fs8__default.default.unlinkSync(filePath);
|
|
241
250
|
deletedCount++;
|
|
@@ -249,7 +258,7 @@ function cleanupOldHeaderImages(outputFolder, currentHeaderBasename, ui) {
|
|
|
249
258
|
}
|
|
250
259
|
function findGalleries(basePath, recursive) {
|
|
251
260
|
const galleryDirs = [];
|
|
252
|
-
const galleryJsonPath =
|
|
261
|
+
const galleryJsonPath = path__default.default.join(basePath, "gallery", "gallery.json");
|
|
253
262
|
if (fs8__default.default.existsSync(galleryJsonPath)) {
|
|
254
263
|
galleryDirs.push(basePath);
|
|
255
264
|
}
|
|
@@ -258,7 +267,7 @@ function findGalleries(basePath, recursive) {
|
|
|
258
267
|
const entries = fs8__default.default.readdirSync(basePath, { withFileTypes: true });
|
|
259
268
|
for (const entry of entries) {
|
|
260
269
|
if (entry.isDirectory() && entry.name !== "gallery") {
|
|
261
|
-
const subPath =
|
|
270
|
+
const subPath = path__default.default.join(basePath, entry.name);
|
|
262
271
|
const subResults = findGalleries(subPath, recursive);
|
|
263
272
|
galleryDirs.push(...subResults);
|
|
264
273
|
}
|
|
@@ -317,20 +326,20 @@ function migrateGalleryJson(deprecatedGalleryData, galleryJsonPath, ui) {
|
|
|
317
326
|
ui.start("Old gallery.json format detected. Migrating gallery.json to the new data format.");
|
|
318
327
|
let mediaBasePath;
|
|
319
328
|
const imagePath = deprecatedGalleryData.sections[0].images[0].path;
|
|
320
|
-
if (imagePath && imagePath !==
|
|
321
|
-
mediaBasePath =
|
|
329
|
+
if (imagePath && imagePath !== path__default.default.join("..", path__default.default.basename(imagePath))) {
|
|
330
|
+
mediaBasePath = path__default.default.resolve(path__default.default.join(path__default.default.dirname(galleryJsonPath)), path__default.default.dirname(imagePath));
|
|
322
331
|
}
|
|
323
332
|
const sections = deprecatedGalleryData.sections.map((section) => ({
|
|
324
333
|
...section,
|
|
325
334
|
images: section.images.map((image) => ({
|
|
326
335
|
...image,
|
|
327
336
|
path: void 0,
|
|
328
|
-
filename:
|
|
337
|
+
filename: path__default.default.basename(image.path)
|
|
329
338
|
}))
|
|
330
339
|
}));
|
|
331
340
|
const galleryData = {
|
|
332
341
|
...deprecatedGalleryData,
|
|
333
|
-
headerImage:
|
|
342
|
+
headerImage: path__default.default.basename(deprecatedGalleryData.headerImage),
|
|
334
343
|
sections,
|
|
335
344
|
mediaBasePath
|
|
336
345
|
};
|
|
@@ -342,7 +351,7 @@ function migrateGalleryJson(deprecatedGalleryData, galleryJsonPath, ui) {
|
|
|
342
351
|
return galleryData;
|
|
343
352
|
}
|
|
344
353
|
function getMediaFileType(fileName) {
|
|
345
|
-
const ext =
|
|
354
|
+
const ext = path__default.default.extname(fileName).toLowerCase();
|
|
346
355
|
if (IMAGE_EXTENSIONS.has(ext)) return "image";
|
|
347
356
|
if (VIDEO_EXTENSIONS.has(ext)) return "video";
|
|
348
357
|
return null;
|
|
@@ -370,7 +379,7 @@ async function scanDirectory(dirPath, ui) {
|
|
|
370
379
|
mediaFiles.push(mediaFile);
|
|
371
380
|
}
|
|
372
381
|
} else if (entry.isDirectory() && entry.name !== "gallery") {
|
|
373
|
-
subGalleryDirectories.push(
|
|
382
|
+
subGalleryDirectories.push(path__default.default.join(dirPath, entry.name));
|
|
374
383
|
}
|
|
375
384
|
}
|
|
376
385
|
} catch (error) {
|
|
@@ -406,12 +415,12 @@ async function getGallerySettingsFromUser(galleryName, defaultImage, ui) {
|
|
|
406
415
|
return { title, description, url, headerImage };
|
|
407
416
|
}
|
|
408
417
|
async function createGalleryJson(mediaFiles, galleryJsonPath, scanPath, subGalleries = [], useDefaultSettings, ctaBanner, ui) {
|
|
409
|
-
const galleryDir =
|
|
410
|
-
const isSameLocation =
|
|
418
|
+
const galleryDir = path__default.default.dirname(galleryJsonPath);
|
|
419
|
+
const isSameLocation = path__default.default.relative(scanPath, path__default.default.join(galleryDir, "..")) === "";
|
|
411
420
|
const mediaBasePath = isSameLocation ? void 0 : scanPath;
|
|
412
421
|
const relativeSubGalleries = subGalleries.map((subGallery) => ({
|
|
413
422
|
...subGallery,
|
|
414
|
-
headerImage: subGallery.headerImage ?
|
|
423
|
+
headerImage: subGallery.headerImage ? path__default.default.relative(galleryDir, subGallery.headerImage) : ""
|
|
415
424
|
}));
|
|
416
425
|
let galleryData = {
|
|
417
426
|
title: "My Gallery",
|
|
@@ -434,8 +443,8 @@ async function createGalleryJson(mediaFiles, galleryJsonPath, scanPath, subGalle
|
|
|
434
443
|
galleryData = {
|
|
435
444
|
...galleryData,
|
|
436
445
|
...await getGallerySettingsFromUser(
|
|
437
|
-
|
|
438
|
-
|
|
446
|
+
path__default.default.basename(path__default.default.join(galleryDir, "..")),
|
|
447
|
+
path__default.default.basename(mediaFiles[0]?.filename || ""),
|
|
439
448
|
ui
|
|
440
449
|
)
|
|
441
450
|
};
|
|
@@ -443,8 +452,8 @@ async function createGalleryJson(mediaFiles, galleryJsonPath, scanPath, subGalle
|
|
|
443
452
|
await fs8.promises.writeFile(galleryJsonPath, JSON.stringify(galleryData, null, 2));
|
|
444
453
|
}
|
|
445
454
|
async function galleryExists(outputPath) {
|
|
446
|
-
const galleryPath =
|
|
447
|
-
const galleryJsonPath =
|
|
455
|
+
const galleryPath = path__default.default.join(outputPath, "gallery");
|
|
456
|
+
const galleryJsonPath = path__default.default.join(galleryPath, "gallery.json");
|
|
448
457
|
try {
|
|
449
458
|
await fs8.promises.access(galleryJsonPath);
|
|
450
459
|
return true;
|
|
@@ -463,7 +472,7 @@ async function processDirectory(scanPath, outputPath, recursive, useDefaultSetti
|
|
|
463
472
|
for (const subGalleryDir of subGalleryDirectories) {
|
|
464
473
|
const result2 = await processDirectory(
|
|
465
474
|
subGalleryDir,
|
|
466
|
-
|
|
475
|
+
path__default.default.join(outputPath, path__default.default.basename(subGalleryDir)),
|
|
467
476
|
recursive,
|
|
468
477
|
useDefaultSettings,
|
|
469
478
|
force,
|
|
@@ -478,8 +487,8 @@ async function processDirectory(scanPath, outputPath, recursive, useDefaultSetti
|
|
|
478
487
|
}
|
|
479
488
|
}
|
|
480
489
|
if (mediaFiles.length > 0 || subGalleries.length > 0) {
|
|
481
|
-
const galleryPath =
|
|
482
|
-
const galleryJsonPath =
|
|
490
|
+
const galleryPath = path__default.default.join(outputPath, "gallery");
|
|
491
|
+
const galleryJsonPath = path__default.default.join(galleryPath, "gallery.json");
|
|
483
492
|
const exists = await galleryExists(outputPath);
|
|
484
493
|
if (exists && !force) {
|
|
485
494
|
const shouldOverride = await ui.prompt(`Gallery already exists at ${galleryJsonPath}. Do you want to override it?`, {
|
|
@@ -504,19 +513,19 @@ async function processDirectory(scanPath, outputPath, recursive, useDefaultSetti
|
|
|
504
513
|
}
|
|
505
514
|
const result = { totalFiles, totalGalleries };
|
|
506
515
|
if (mediaFiles.length > 0 || subGalleries.length > 0) {
|
|
507
|
-
const dirName =
|
|
516
|
+
const dirName = path__default.default.basename(scanPath);
|
|
508
517
|
result.subGallery = {
|
|
509
518
|
title: capitalizeTitle(dirName),
|
|
510
519
|
headerImage: mediaFiles[0]?.filename || "",
|
|
511
|
-
path:
|
|
520
|
+
path: path__default.default.join("..", dirName)
|
|
512
521
|
};
|
|
513
522
|
}
|
|
514
523
|
return result;
|
|
515
524
|
}
|
|
516
525
|
async function init(options, ui) {
|
|
517
526
|
try {
|
|
518
|
-
const scanPath =
|
|
519
|
-
const outputPath = options.gallery ?
|
|
527
|
+
const scanPath = path__default.default.resolve(options.photos);
|
|
528
|
+
const outputPath = options.gallery ? path__default.default.resolve(options.gallery) : scanPath;
|
|
520
529
|
const result = await processDirectory(
|
|
521
530
|
scanPath,
|
|
522
531
|
outputPath,
|
|
@@ -640,7 +649,7 @@ async function processImage(imagePath, thumbnailPath, thumbnailPathRetina, thumb
|
|
|
640
649
|
const blurHash = await generateBlurHash(thumbnailPath);
|
|
641
650
|
return {
|
|
642
651
|
type: "image",
|
|
643
|
-
filename:
|
|
652
|
+
filename: path__default.default.basename(imagePath),
|
|
644
653
|
alt: description,
|
|
645
654
|
width: imageDimensions.width,
|
|
646
655
|
height: imageDimensions.height,
|
|
@@ -671,7 +680,7 @@ async function processVideo(videoPath, thumbnailPath, thumbnailPathRetina, thumb
|
|
|
671
680
|
const blurHash = await generateBlurHash(thumbnailPath);
|
|
672
681
|
return {
|
|
673
682
|
type: "video",
|
|
674
|
-
filename:
|
|
683
|
+
filename: path__default.default.basename(videoPath),
|
|
675
684
|
alt: void 0,
|
|
676
685
|
width: videoDimensions.width,
|
|
677
686
|
height: videoDimensions.height,
|
|
@@ -687,11 +696,11 @@ async function processVideo(videoPath, thumbnailPath, thumbnailPathRetina, thumb
|
|
|
687
696
|
}
|
|
688
697
|
async function processMediaFile(mediaFile, mediaBasePath, thumbnailsPath, thumbnailSize, ui) {
|
|
689
698
|
try {
|
|
690
|
-
const filePath =
|
|
699
|
+
const filePath = path__default.default.resolve(path__default.default.join(mediaBasePath, mediaFile.filename));
|
|
691
700
|
const fileName = mediaFile.filename;
|
|
692
|
-
const fileNameWithoutExt =
|
|
701
|
+
const fileNameWithoutExt = path__default.default.parse(fileName).name;
|
|
693
702
|
const thumbnailFileName = `${fileNameWithoutExt}.avif`;
|
|
694
|
-
const thumbnailPath =
|
|
703
|
+
const thumbnailPath = path__default.default.join(thumbnailsPath, thumbnailFileName);
|
|
695
704
|
const thumbnailPathRetina = thumbnailPath.replace(".avif", "@2x.avif");
|
|
696
705
|
const lastMediaTimestamp = mediaFile.lastMediaTimestamp ? new Date(mediaFile.lastMediaTimestamp) : void 0;
|
|
697
706
|
const verbose = ui.level === consola.LogLevels.debug;
|
|
@@ -717,8 +726,8 @@ async function processMediaFile(mediaFile, mediaBasePath, thumbnailsPath, thumbn
|
|
|
717
726
|
}
|
|
718
727
|
updatedMediaFile.filename = mediaFile.filename;
|
|
719
728
|
if (updatedMediaFile.thumbnail) {
|
|
720
|
-
updatedMediaFile.thumbnail.path =
|
|
721
|
-
updatedMediaFile.thumbnail.pathRetina =
|
|
729
|
+
updatedMediaFile.thumbnail.path = path__default.default.basename(thumbnailPath);
|
|
730
|
+
updatedMediaFile.thumbnail.pathRetina = path__default.default.basename(thumbnailPathRetina);
|
|
722
731
|
if (mediaFile.thumbnail?.baseUrl) {
|
|
723
732
|
updatedMediaFile.thumbnail.baseUrl = mediaFile.thumbnail.baseUrl;
|
|
724
733
|
}
|
|
@@ -733,14 +742,14 @@ async function processMediaFile(mediaFile, mediaBasePath, thumbnailsPath, thumbn
|
|
|
733
742
|
}
|
|
734
743
|
}
|
|
735
744
|
async function processGalleryThumbnails(galleryDir, ui) {
|
|
736
|
-
const galleryJsonPath =
|
|
737
|
-
const thumbnailsPath =
|
|
745
|
+
const galleryJsonPath = path__default.default.join(galleryDir, "gallery", "gallery.json");
|
|
746
|
+
const thumbnailsPath = path__default.default.join(galleryDir, "gallery", "images");
|
|
738
747
|
ui.start(`Creating thumbnails: ${galleryDir}`);
|
|
739
748
|
try {
|
|
740
749
|
fs8__default.default.mkdirSync(thumbnailsPath, { recursive: true });
|
|
741
750
|
const galleryData = parseGalleryJson(galleryJsonPath, ui);
|
|
742
751
|
const thumbnailSize = galleryData.thumbnailSize || DEFAULT_THUMBNAIL_SIZE;
|
|
743
|
-
const mediaBasePath = galleryData.mediaBasePath ??
|
|
752
|
+
const mediaBasePath = galleryData.mediaBasePath ?? path__default.default.join(galleryDir);
|
|
744
753
|
let processedCount = 0;
|
|
745
754
|
for (const section of galleryData.sections) {
|
|
746
755
|
for (const [index, mediaFile] of section.images.entries()) {
|
|
@@ -787,8 +796,8 @@ function copyPhotos(galleryData, galleryDir, ui) {
|
|
|
787
796
|
for (const section of galleryData.sections) {
|
|
788
797
|
for (const image of section.images) {
|
|
789
798
|
if (galleryData.mediaBasePath) {
|
|
790
|
-
const sourcePath =
|
|
791
|
-
const destPath =
|
|
799
|
+
const sourcePath = path__default.default.join(galleryData.mediaBasePath, image.filename);
|
|
800
|
+
const destPath = path__default.default.join(galleryDir, image.filename);
|
|
792
801
|
ui.debug(`Copying photo to ${destPath}`);
|
|
793
802
|
fs8__default.default.copyFileSync(sourcePath, destPath);
|
|
794
803
|
}
|
|
@@ -827,17 +836,17 @@ async function scanAndAppendNewFiles(galleryDir, galleryJsonPath, galleryData, u
|
|
|
827
836
|
}
|
|
828
837
|
async function buildGallery(galleryDir, templateDir, scan, shouldCreateThumbnails, ui, baseUrl, thumbsBaseUrl) {
|
|
829
838
|
ui.start(`Building gallery ${galleryDir}`);
|
|
830
|
-
const galleryJsonPath =
|
|
839
|
+
const galleryJsonPath = path__default.default.join(galleryDir, "gallery", "gallery.json");
|
|
831
840
|
let galleryData = parseGalleryJson(galleryJsonPath, ui);
|
|
832
841
|
if (scan) {
|
|
833
842
|
galleryData = await scanAndAppendNewFiles(galleryDir, galleryJsonPath, galleryData, ui);
|
|
834
843
|
}
|
|
835
|
-
const socialMediaCardImagePath =
|
|
844
|
+
const socialMediaCardImagePath = path__default.default.join(galleryDir, "gallery", "images", "social-media-card.jpg");
|
|
836
845
|
const mediaBasePath = galleryData.mediaBasePath;
|
|
837
846
|
const mediaBaseUrl = baseUrl || galleryData.mediaBaseUrl;
|
|
838
|
-
const headerImagePath = mediaBasePath ?
|
|
839
|
-
const imagesFolder =
|
|
840
|
-
const currentHeaderBasename =
|
|
847
|
+
const headerImagePath = mediaBasePath ? path__default.default.join(mediaBasePath, galleryData.headerImage) : path__default.default.resolve(galleryDir, galleryData.headerImage);
|
|
848
|
+
const imagesFolder = path__default.default.join(galleryDir, "gallery", "images");
|
|
849
|
+
const currentHeaderBasename = path__default.default.basename(headerImagePath, path__default.default.extname(headerImagePath));
|
|
841
850
|
if (shouldCreateThumbnails) {
|
|
842
851
|
if (!fs8__default.default.existsSync(imagesFolder)) {
|
|
843
852
|
fs8__default.default.mkdirSync(imagesFolder, { recursive: true });
|
|
@@ -880,7 +889,7 @@ async function buildGallery(galleryDir, templateDir, scan, shouldCreateThumbnail
|
|
|
880
889
|
}
|
|
881
890
|
if (!galleryData.metadata.image) {
|
|
882
891
|
ui.debug("Updating gallery.json with social media card URL");
|
|
883
|
-
galleryData.metadata.image = thumbsBaseUrl ? `${thumbsBaseUrl}/${
|
|
892
|
+
galleryData.metadata.image = thumbsBaseUrl ? `${thumbsBaseUrl}/${path__default.default.basename(socialMediaCardImagePath)}` : `${galleryData.url || ""}/${path__default.default.relative(galleryDir, socialMediaCardImagePath)}`;
|
|
884
893
|
fs8__default.default.writeFileSync(galleryJsonPath, JSON.stringify(galleryData, null, 2));
|
|
885
894
|
}
|
|
886
895
|
if (shouldCreateThumbnails) {
|
|
@@ -889,19 +898,19 @@ async function buildGallery(galleryDir, templateDir, scan, shouldCreateThumbnail
|
|
|
889
898
|
ui.debug("Building gallery from template");
|
|
890
899
|
try {
|
|
891
900
|
process4__default.default.env.GALLERY_JSON_PATH = galleryJsonPath;
|
|
892
|
-
process4__default.default.env.GALLERY_OUTPUT_DIR =
|
|
901
|
+
process4__default.default.env.GALLERY_OUTPUT_DIR = path__default.default.join(galleryDir, "gallery");
|
|
893
902
|
child_process.execSync("npx astro build", { cwd: templateDir, stdio: ui.level === consola.LogLevels.debug ? "inherit" : "ignore" });
|
|
894
903
|
} catch (error) {
|
|
895
904
|
ui.error(`Build failed for ${galleryDir}`);
|
|
896
905
|
throw error;
|
|
897
906
|
}
|
|
898
|
-
const outputDir =
|
|
899
|
-
const buildDir =
|
|
907
|
+
const outputDir = path__default.default.join(galleryDir, "gallery");
|
|
908
|
+
const buildDir = path__default.default.join(outputDir, "_build");
|
|
900
909
|
ui.debug(`Copying build output to ${outputDir}`);
|
|
901
910
|
fs8__default.default.cpSync(buildDir, outputDir, { recursive: true });
|
|
902
911
|
ui.debug("Moving index.html to gallery directory");
|
|
903
|
-
fs8__default.default.copyFileSync(
|
|
904
|
-
fs8__default.default.rmSync(
|
|
912
|
+
fs8__default.default.copyFileSync(path__default.default.join(outputDir, "index.html"), path__default.default.join(galleryDir, "index.html"));
|
|
913
|
+
fs8__default.default.rmSync(path__default.default.join(outputDir, "index.html"));
|
|
905
914
|
ui.debug("Cleaning up build directory");
|
|
906
915
|
fs8__default.default.rmSync(buildDir, { recursive: true, force: true });
|
|
907
916
|
ui.success(`Gallery built successfully`);
|
|
@@ -914,12 +923,12 @@ async function build(options, ui) {
|
|
|
914
923
|
return { processedGalleryCount: 0 };
|
|
915
924
|
}
|
|
916
925
|
const themePath = await undefined("@simple-photo-gallery/theme-modern/package.json");
|
|
917
|
-
const themeDir =
|
|
926
|
+
const themeDir = path__default.default.dirname(new URL(themePath).pathname);
|
|
918
927
|
let totalGalleries = 0;
|
|
919
928
|
for (const dir of galleryDirs) {
|
|
920
|
-
const baseUrl = options.baseUrl ? `${options.baseUrl}${
|
|
921
|
-
const thumbsBaseUrl = options.thumbsBaseUrl ? `${options.thumbsBaseUrl}${
|
|
922
|
-
await buildGallery(
|
|
929
|
+
const baseUrl = options.baseUrl ? `${options.baseUrl}${path__default.default.relative(options.gallery, dir)}` : void 0;
|
|
930
|
+
const thumbsBaseUrl = options.thumbsBaseUrl ? `${options.thumbsBaseUrl}${path__default.default.relative(options.gallery, dir)}` : void 0;
|
|
931
|
+
await buildGallery(path__default.default.resolve(dir), themeDir, options.scan, options.thumbnails, ui, baseUrl, thumbsBaseUrl);
|
|
923
932
|
++totalGalleries;
|
|
924
933
|
}
|
|
925
934
|
ui.box(`Built ${totalGalleries} ${totalGalleries === 1 ? "gallery" : "galleries"} successfully`);
|
|
@@ -935,7 +944,7 @@ async function build(options, ui) {
|
|
|
935
944
|
}
|
|
936
945
|
async function cleanGallery(galleryDir, ui) {
|
|
937
946
|
let filesRemoved = 0;
|
|
938
|
-
const indexHtmlPath =
|
|
947
|
+
const indexHtmlPath = path__default.default.join(galleryDir, "index.html");
|
|
939
948
|
if (fs8__default.default.existsSync(indexHtmlPath)) {
|
|
940
949
|
try {
|
|
941
950
|
fs8__default.default.rmSync(indexHtmlPath);
|
|
@@ -945,7 +954,7 @@ async function cleanGallery(galleryDir, ui) {
|
|
|
945
954
|
ui?.warn(`Failed to remove index.html: ${error}`);
|
|
946
955
|
}
|
|
947
956
|
}
|
|
948
|
-
const galleryPath =
|
|
957
|
+
const galleryPath = path__default.default.join(galleryDir, "gallery");
|
|
949
958
|
if (fs8__default.default.existsSync(galleryPath)) {
|
|
950
959
|
try {
|
|
951
960
|
fs8__default.default.rmSync(galleryPath, { recursive: true, force: true });
|
|
@@ -964,7 +973,7 @@ async function cleanGallery(galleryDir, ui) {
|
|
|
964
973
|
}
|
|
965
974
|
async function clean(options, ui) {
|
|
966
975
|
try {
|
|
967
|
-
const basePath =
|
|
976
|
+
const basePath = path__default.default.resolve(options.gallery);
|
|
968
977
|
if (!fs8__default.default.existsSync(basePath)) {
|
|
969
978
|
ui.error(`Directory does not exist: ${basePath}`);
|
|
970
979
|
return { processedGalleryCount: 0 };
|
|
@@ -1222,7 +1231,7 @@ async function waitForUpdateCheck(checkPromise) {
|
|
|
1222
1231
|
// package.json
|
|
1223
1232
|
var package_default = {
|
|
1224
1233
|
name: "simple-photo-gallery",
|
|
1225
|
-
version: "2.0.
|
|
1234
|
+
version: "2.0.12"};
|
|
1226
1235
|
|
|
1227
1236
|
// src/index.ts
|
|
1228
1237
|
var program = new commander.Command();
|