From 66e5b7b31ffa3dc50332e284df30bd69cbda03b6 Mon Sep 17 00:00:00 2001 From: Vladimir Haltakov Date: Sun, 30 Nov 2025 22:31:48 +0100 Subject: [PATCH 1/2] feat: add optional assets URL --- common/src/gallery.ts | 1 + gallery/src/modules/build/index.ts | 8 ++++++++ themes/modern/astro.config.ts | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/common/src/gallery.ts b/common/src/gallery.ts index aee1950..c8f9f71 100644 --- a/common/src/gallery.ts +++ b/common/src/gallery.ts @@ -83,6 +83,7 @@ export const GalleryDataSchema = z.object({ metadata: GalleryMetadataSchema, mediaBaseUrl: z.string().optional(), thumbsBaseUrl: z.string().optional(), + assetsBaseUrl: z.string().optional(), analyticsScript: z.string().optional(), ctaBanner: z.boolean().optional(), sections: z.array(GallerySectionSchema), diff --git a/gallery/src/modules/build/index.ts b/gallery/src/modules/build/index.ts index d46614a..79f7fdf 100644 --- a/gallery/src/modules/build/index.ts +++ b/gallery/src/modules/build/index.ts @@ -229,6 +229,14 @@ async function buildGallery( process.env.GALLERY_JSON_PATH = galleryJsonPath; process.env.GALLERY_OUTPUT_DIR = path.join(galleryDir, 'gallery'); + // Set the assets base URL if specified in the gallery data + if (galleryData.assetsBaseUrl) { + process.env.GALLERY_ASSETS_BASE_URL = galleryData.assetsBaseUrl; + } else { + // Clear the environment variable to use the default value + delete process.env.GALLERY_ASSETS_BASE_URL; + } + execSync('npx astro build', { cwd: templateDir, stdio: ui.level === LogLevels.debug ? 'inherit' : 'ignore' }); } catch (error) { ui.error(`Build failed for ${galleryDir}`); diff --git a/themes/modern/astro.config.ts b/themes/modern/astro.config.ts index 00dca29..5ee58bc 100644 --- a/themes/modern/astro.config.ts +++ b/themes/modern/astro.config.ts @@ -12,6 +12,9 @@ if (!sourceGalleryPath) throw new Error('GALLERY_JSON_PATH environment variable const outputDir = process.env.GALLERY_OUTPUT_DIR || sourceGalleryPath.replace('gallery.json', ''); +// Get the assets base URL from environment variable (defaults to 'gallery' for local assets) +const assetsBaseUrl = process.env.GALLERY_ASSETS_BASE_URL || 'gallery'; + /** * Astro integration to prevent empty content collection files from being generated * These files (content-assets.mjs and content-modules.mjs) are generated by Astro @@ -49,7 +52,7 @@ export default defineConfig({ outDir: outputDir + '/_build', build: { assets: 'assets', - assetsPrefix: 'gallery', + assetsPrefix: assetsBaseUrl, }, integrations: [relativeLinks(), preventEmptyContentFiles()], publicDir: 'public', From 8ed793d90f62db4c0ea438c76fd57b44b8b9d4ad Mon Sep 17 00:00:00 2001 From: Vladimir Haltakov Date: Sat, 13 Dec 2025 22:21:25 +0100 Subject: [PATCH 2/2] chore: update docs --- docs/configuration.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/docs/configuration.md b/docs/configuration.md index 7092e40..f4d3a34 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -236,6 +236,46 @@ Markdown formatting is available in: Thumbnails will automatically be generated using sizes that fit the theme (300px height and 600px height for retina displays). If you want, you can change the size using the `thumbnailSize` attribute in the `gallery.json` file. +## Static assets (CSS and JavaScript) + +By default, each gallery includes its own copy of the static asset files (CSS and JavaScript) in the `gallery/assets/` folder. However, if you're hosting multiple galleries built with the same version of Simple Photo Gallery, you can share these assets between all galleries to reduce storage and improve caching. + +Use the `assetsBaseUrl` option to specify the base URL where the shared static assets are hosted: + +```json +{ + "title": "My Gallery", + "description": "...", + "assetsBaseUrl": "https://cdn.example.com/simple-photo-gallery/v1.0.0" +} +``` + +When set, the generated HTML will load CSS and JavaScript files from the specified URL instead of the local `gallery/assets/` folder: + +```html + +