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