simple-photo-gallery 2.0.11-rc.8 → 2.0.11
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/assets/fonts/dejavu/DejaVuSans-Bold.ttf +0 -0
- package/assets/fonts/dejavu/LICENSE.txt +78 -0
- package/dist/index.cjs +75 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +73 -23
- package/dist/index.js.map +1 -1
- package/dist/lib/browser.cjs +29 -0
- package/dist/lib/browser.cjs.map +1 -0
- package/dist/lib/browser.d.cts +8 -0
- package/dist/lib/browser.d.ts +8 -0
- package/dist/lib/browser.js +23 -0
- package/dist/lib/browser.js.map +1 -0
- package/dist/lib/index.cjs +38 -21
- package/dist/lib/index.cjs.map +1 -1
- package/dist/lib/index.d.cts +1 -8
- package/dist/lib/index.d.ts +1 -8
- package/dist/lib/index.js +38 -20
- package/dist/lib/index.js.map +1 -1
- package/package.json +9 -4
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import process4, { stdout } from 'process';
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import { LogLevels, createConsola } from 'consola';
|
|
5
5
|
import { execSync, spawn } from 'child_process';
|
|
6
6
|
import fs8, { promises } from 'fs';
|
|
7
7
|
import path7 from 'path';
|
|
8
8
|
import { Buffer } from 'buffer';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
9
10
|
import sharp2 from 'sharp';
|
|
10
11
|
import { encode } from 'blurhash';
|
|
11
12
|
import { GalleryDataSchema, GalleryDataDeprecatedSchema } from '@simple-photo-gallery/common';
|
|
@@ -76,7 +77,33 @@ async function generateBlurHash(imagePath, componentX = 4, componentY = 3) {
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
// src/modules/build/utils/index.ts
|
|
79
|
-
path7.dirname(
|
|
80
|
+
var __dirname = path7.dirname(fileURLToPath(import.meta.url));
|
|
81
|
+
var SOCIAL_CARD_FONT_RELATIVE_PATH = path7.join("assets", "fonts", "dejavu", "DejaVuSans-Bold.ttf");
|
|
82
|
+
var socialCardFontBase64;
|
|
83
|
+
function resolveFromCurrentDir(...segments) {
|
|
84
|
+
return path7.resolve(__dirname, ...segments);
|
|
85
|
+
}
|
|
86
|
+
function findSocialCardFontPath() {
|
|
87
|
+
const fontCandidates = [
|
|
88
|
+
resolveFromCurrentDir("../../../../", SOCIAL_CARD_FONT_RELATIVE_PATH),
|
|
89
|
+
path7.resolve(__dirname, "../", SOCIAL_CARD_FONT_RELATIVE_PATH),
|
|
90
|
+
path7.resolve(process4.cwd(), SOCIAL_CARD_FONT_RELATIVE_PATH)
|
|
91
|
+
];
|
|
92
|
+
for (const candidate of fontCandidates) {
|
|
93
|
+
if (fs8.existsSync(candidate)) {
|
|
94
|
+
return candidate;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
throw new Error("Social media card font file not found");
|
|
98
|
+
}
|
|
99
|
+
function getSocialCardFontBase64() {
|
|
100
|
+
if (socialCardFontBase64) {
|
|
101
|
+
return socialCardFontBase64;
|
|
102
|
+
}
|
|
103
|
+
const fontPath = findSocialCardFontPath();
|
|
104
|
+
socialCardFontBase64 = fs8.readFileSync(fontPath).toString("base64");
|
|
105
|
+
return socialCardFontBase64;
|
|
106
|
+
}
|
|
80
107
|
async function createGallerySocialMediaCardImage(headerPhotoPath, title, ouputPath, ui) {
|
|
81
108
|
ui?.start(`Creating social media card image`);
|
|
82
109
|
const headerBasename = path7.basename(headerPhotoPath, path7.extname(headerPhotoPath));
|
|
@@ -88,11 +115,18 @@ async function createGallerySocialMediaCardImage(headerPhotoPath, title, ouputPa
|
|
|
88
115
|
const resizedImageBuffer = await image.resize(1200, 631, { fit: "cover" }).jpeg({ quality: 90 }).toBuffer();
|
|
89
116
|
const outputPath = ouputPath;
|
|
90
117
|
await sharp2(resizedImageBuffer).toFile(outputPath);
|
|
118
|
+
const fontBase64 = getSocialCardFontBase64();
|
|
91
119
|
const svgText = `
|
|
92
120
|
<svg width="1200" height="631" xmlns="http://www.w3.org/2000/svg">
|
|
93
121
|
<defs>
|
|
94
122
|
<style>
|
|
95
|
-
|
|
123
|
+
@font-face {
|
|
124
|
+
font-family: 'DejaVu Sans';
|
|
125
|
+
src: url('data:font/ttf;base64,${fontBase64}') format('truetype');
|
|
126
|
+
font-weight: 700;
|
|
127
|
+
font-style: normal;
|
|
128
|
+
}
|
|
129
|
+
.title { font-family: 'DejaVu Sans', Arial, sans-serif; font-size: 96px; font-weight: bold; fill: white; stroke: black; stroke-width: 5; paint-order: stroke; text-anchor: middle; }
|
|
96
130
|
</style>
|
|
97
131
|
</defs>
|
|
98
132
|
<text x="600" y="250" class="title">${title}</text>
|
|
@@ -356,7 +390,7 @@ async function getGallerySettingsFromUser(galleryName, defaultImage, ui) {
|
|
|
356
390
|
});
|
|
357
391
|
return { title, description, url, headerImage };
|
|
358
392
|
}
|
|
359
|
-
async function createGalleryJson(mediaFiles, galleryJsonPath, scanPath, subGalleries = [], useDefaultSettings, ui) {
|
|
393
|
+
async function createGalleryJson(mediaFiles, galleryJsonPath, scanPath, subGalleries = [], useDefaultSettings, ctaBanner, ui) {
|
|
360
394
|
const galleryDir = path7.dirname(galleryJsonPath);
|
|
361
395
|
const isSameLocation = path7.relative(scanPath, path7.join(galleryDir, "..")) === "";
|
|
362
396
|
const mediaBasePath = isSameLocation ? void 0 : scanPath;
|
|
@@ -378,7 +412,8 @@ async function createGalleryJson(mediaFiles, galleryJsonPath, scanPath, subGalle
|
|
|
378
412
|
subGalleries: {
|
|
379
413
|
title: "Sub Galleries",
|
|
380
414
|
galleries: relativeSubGalleries
|
|
381
|
-
}
|
|
415
|
+
},
|
|
416
|
+
...ctaBanner !== void 0 && { ctaBanner }
|
|
382
417
|
};
|
|
383
418
|
if (!useDefaultSettings) {
|
|
384
419
|
galleryData = {
|
|
@@ -402,7 +437,7 @@ async function galleryExists(outputPath) {
|
|
|
402
437
|
return false;
|
|
403
438
|
}
|
|
404
439
|
}
|
|
405
|
-
async function processDirectory(scanPath, outputPath, recursive, useDefaultSettings, force, ui) {
|
|
440
|
+
async function processDirectory(scanPath, outputPath, recursive, useDefaultSettings, force, ctaBanner, ui) {
|
|
406
441
|
ui.start(`Scanning ${scanPath}`);
|
|
407
442
|
let totalFiles = 0;
|
|
408
443
|
let totalGalleries = 1;
|
|
@@ -417,6 +452,7 @@ async function processDirectory(scanPath, outputPath, recursive, useDefaultSetti
|
|
|
417
452
|
recursive,
|
|
418
453
|
useDefaultSettings,
|
|
419
454
|
force,
|
|
455
|
+
ctaBanner,
|
|
420
456
|
ui
|
|
421
457
|
);
|
|
422
458
|
totalFiles += result2.totalFiles;
|
|
@@ -442,7 +478,7 @@ async function processDirectory(scanPath, outputPath, recursive, useDefaultSetti
|
|
|
442
478
|
}
|
|
443
479
|
try {
|
|
444
480
|
await promises.mkdir(galleryPath, { recursive: true });
|
|
445
|
-
await createGalleryJson(mediaFiles, galleryJsonPath, scanPath, subGalleries, useDefaultSettings, ui);
|
|
481
|
+
await createGalleryJson(mediaFiles, galleryJsonPath, scanPath, subGalleries, useDefaultSettings, ctaBanner, ui);
|
|
446
482
|
ui.success(
|
|
447
483
|
`Create gallery with ${mediaFiles.length} files and ${subGalleries.length} subgalleries at: ${galleryJsonPath}`
|
|
448
484
|
);
|
|
@@ -466,7 +502,15 @@ async function init(options, ui) {
|
|
|
466
502
|
try {
|
|
467
503
|
const scanPath = path7.resolve(options.photos);
|
|
468
504
|
const outputPath = options.gallery ? path7.resolve(options.gallery) : scanPath;
|
|
469
|
-
const result = await processDirectory(
|
|
505
|
+
const result = await processDirectory(
|
|
506
|
+
scanPath,
|
|
507
|
+
outputPath,
|
|
508
|
+
options.recursive,
|
|
509
|
+
options.default,
|
|
510
|
+
options.force,
|
|
511
|
+
options.ctaBanner,
|
|
512
|
+
ui
|
|
513
|
+
);
|
|
470
514
|
ui.box(
|
|
471
515
|
`Created ${result.totalGalleries} ${result.totalGalleries === 1 ? "gallery" : "galleries"} with ${result.totalFiles} media ${result.totalFiles === 1 ? "file" : "files"}`
|
|
472
516
|
);
|
|
@@ -660,6 +704,12 @@ async function processMediaFile(mediaFile, mediaBasePath, thumbnailsPath, thumbn
|
|
|
660
704
|
if (updatedMediaFile.thumbnail) {
|
|
661
705
|
updatedMediaFile.thumbnail.path = path7.basename(thumbnailPath);
|
|
662
706
|
updatedMediaFile.thumbnail.pathRetina = path7.basename(thumbnailPathRetina);
|
|
707
|
+
if (mediaFile.thumbnail?.baseUrl) {
|
|
708
|
+
updatedMediaFile.thumbnail.baseUrl = mediaFile.thumbnail.baseUrl;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
if (mediaFile.url) {
|
|
712
|
+
updatedMediaFile.url = mediaFile.url;
|
|
663
713
|
}
|
|
664
714
|
return updatedMediaFile;
|
|
665
715
|
} catch (error) {
|
|
@@ -823,8 +873,8 @@ async function buildGallery(galleryDir, templateDir, scan, shouldCreateThumbnail
|
|
|
823
873
|
}
|
|
824
874
|
ui.debug("Building gallery from template");
|
|
825
875
|
try {
|
|
826
|
-
|
|
827
|
-
|
|
876
|
+
process4.env.GALLERY_JSON_PATH = galleryJsonPath;
|
|
877
|
+
process4.env.GALLERY_OUTPUT_DIR = path7.join(galleryDir, "gallery");
|
|
828
878
|
execSync("npx astro build", { cwd: templateDir, stdio: ui.level === LogLevels.debug ? "inherit" : "ignore" });
|
|
829
879
|
} catch (error) {
|
|
830
880
|
ui.error(`Build failed for ${galleryDir}`);
|
|
@@ -948,7 +998,7 @@ var ApiTelemetryClient = class {
|
|
|
948
998
|
axios.post(this.endpoint, event, {
|
|
949
999
|
headers: {
|
|
950
1000
|
"content-type": "application/json",
|
|
951
|
-
"user-agent": `simple-photo-gallery/${event.packageVersion} (${
|
|
1001
|
+
"user-agent": `simple-photo-gallery/${event.packageVersion} (${process4.platform}; ${process4.arch})`
|
|
952
1002
|
}
|
|
953
1003
|
});
|
|
954
1004
|
} catch {
|
|
@@ -985,11 +1035,11 @@ var TelemetryService = class {
|
|
|
985
1035
|
if (override) {
|
|
986
1036
|
return override === "1";
|
|
987
1037
|
}
|
|
988
|
-
if (
|
|
1038
|
+
if (process4.env.CI || process4.env.DO_NOT_TRACK) {
|
|
989
1039
|
return false;
|
|
990
1040
|
}
|
|
991
|
-
if (
|
|
992
|
-
return
|
|
1041
|
+
if (process4.env.SPG_TELEMETRY) {
|
|
1042
|
+
return process4.env.SPG_TELEMETRY === "1";
|
|
993
1043
|
}
|
|
994
1044
|
const stored = this.getStoredPreference();
|
|
995
1045
|
if (stored === void 0) {
|
|
@@ -1031,7 +1081,7 @@ var TelemetryService = class {
|
|
|
1031
1081
|
durationMs: now - startedAt,
|
|
1032
1082
|
packageName: this.packageName,
|
|
1033
1083
|
packageVersion: this.packageVersion,
|
|
1034
|
-
nodeVersion:
|
|
1084
|
+
nodeVersion: process4.version,
|
|
1035
1085
|
osPlatform: os.platform(),
|
|
1036
1086
|
osRelease: os.release(),
|
|
1037
1087
|
osArch: os.arch(),
|
|
@@ -1065,7 +1115,7 @@ var TelemetryService = class {
|
|
|
1065
1115
|
/** Returns the telemetry client. */
|
|
1066
1116
|
getClient() {
|
|
1067
1117
|
if (!this.client) {
|
|
1068
|
-
switch (
|
|
1118
|
+
switch (process4.env.SPG_TELEMETRY_PROVIDER) {
|
|
1069
1119
|
case "none": {
|
|
1070
1120
|
this.client = void 0;
|
|
1071
1121
|
break;
|
|
@@ -1157,7 +1207,7 @@ async function waitForUpdateCheck(checkPromise) {
|
|
|
1157
1207
|
// package.json
|
|
1158
1208
|
var package_default = {
|
|
1159
1209
|
name: "simple-photo-gallery",
|
|
1160
|
-
version: "2.0.11
|
|
1210
|
+
version: "2.0.11"};
|
|
1161
1211
|
|
|
1162
1212
|
// src/index.ts
|
|
1163
1213
|
var program = new Command();
|
|
@@ -1199,7 +1249,7 @@ function withCommandContext(handler) {
|
|
|
1199
1249
|
} catch (error) {
|
|
1200
1250
|
ui.debug(error);
|
|
1201
1251
|
errorInfo = error instanceof Error ? { name: error.name, message: error.message } : { name: "UnknownError", message: String(error) };
|
|
1202
|
-
|
|
1252
|
+
process4.exitCode = 1;
|
|
1203
1253
|
}
|
|
1204
1254
|
const updateInfo = await waitForUpdateCheck(updateCheckPromise);
|
|
1205
1255
|
if (updateInfo) {
|
|
@@ -1221,14 +1271,14 @@ function withCommandContext(handler) {
|
|
|
1221
1271
|
program.command("init").description("Initialize a gallery by scaning a folder for images and videos").option(
|
|
1222
1272
|
"-p, --photos <path>",
|
|
1223
1273
|
"Path to the folder where the photos are stored. Default: current working directory",
|
|
1224
|
-
|
|
1274
|
+
process4.cwd()
|
|
1225
1275
|
).option(
|
|
1226
1276
|
"-g, --gallery <path>",
|
|
1227
1277
|
"Path to the directory where the gallery will be initialized. Default: same directory as the photos folder"
|
|
1228
|
-
).option("-r, --recursive", "Recursively create galleries from all photos subdirectories", false).option("-d, --default", "Use default gallery settings instead of asking the user", false).option("-f, --force", "Force override existing galleries without asking", false).action(withCommandContext((options, ui) => init(options, ui)));
|
|
1229
|
-
program.command("thumbnails").description("Create thumbnails for all media files in the gallery").option("-g, --gallery <path>", "Path to the directory of the gallery. Default: current working directory",
|
|
1230
|
-
program.command("build").description("Build the HTML gallery in the specified directory").option("-g, --gallery <path>", "Path to the directory of the gallery. Default: current working directory",
|
|
1231
|
-
program.command("clean").description("Remove all gallery files and folders (index.html, gallery/)").option("-g, --gallery <path>", "Path to the directory of the gallery. Default: current working directory",
|
|
1278
|
+
).option("-r, --recursive", "Recursively create galleries from all photos subdirectories", false).option("-d, --default", "Use default gallery settings instead of asking the user", false).option("-f, --force", "Force override existing galleries without asking", false).option("--cta-banner", "Add a Simple Photo Gallery call-to-action banner to the end of the gallery", false).action(withCommandContext((options, ui) => init(options, ui)));
|
|
1279
|
+
program.command("thumbnails").description("Create thumbnails for all media files in the gallery").option("-g, --gallery <path>", "Path to the directory of the gallery. Default: current working directory", process4.cwd()).option("-r, --recursive", "Scan subdirectories recursively", false).action(withCommandContext((options, ui) => thumbnails(options, ui)));
|
|
1280
|
+
program.command("build").description("Build the HTML gallery in the specified directory").option("-g, --gallery <path>", "Path to the directory of the gallery. Default: current working directory", process4.cwd()).option("-r, --recursive", "Scan subdirectories recursively", false).option("-b, --base-url <url>", "Base URL where the photos are hosted").option("-t, --thumbs-base-url <url>", "Base URL where the thumbnails are hosted").option("--no-thumbnails", "Skip creating thumbnails when building the gallery", true).option("--no-scan", "Do not scan for new photos when building the gallery", true).action(withCommandContext((options, ui) => build(options, ui)));
|
|
1281
|
+
program.command("clean").description("Remove all gallery files and folders (index.html, gallery/)").option("-g, --gallery <path>", "Path to the directory of the gallery. Default: current working directory", process4.cwd()).option("-r, --recursive", "Clean subdirectories recursively", false).action(withCommandContext((options, ui) => clean(options, ui)));
|
|
1232
1282
|
program.command("telemetry").description("Manage anonymous telemetry preferences. Use 1 to enable, 0 to disable, or no argument to check status").option("-s, --state <state>", "Enable (1) or disable (0) telemetry", parseTelemetryOption).action(withCommandContext((options, ui) => telemetry(options, ui, telemetryService)));
|
|
1233
1283
|
program.parse();
|
|
1234
1284
|
//# sourceMappingURL=index.js.map
|