Files
immich-folio/lib/publicPages.ts
Ralksta a813433891 release: v0.13.0 (#535)
Twenty-nine commits since v0.12.0. See CHANGELOG.md for the full list
and the upgrade notes.

Ten additions — the SEO package (site URL, robots.txt, sitemap.xml,
JSON-LD), slideshow mode, opt-in original downloads, copy-link,
previous/next album navigation, alt text from the Immich description,
per-album location precision, the update notice, a Help tab, and a
subpage cover grid separate from its photo grid. Two fixes: CJK album
slugs, and the lightbox control bar.

Photo of the Day (#476) was built on `dev` and reverted as not planned;
it never appears in a release.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01DmsHVRL9yQvckUB1ZpVWre

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: ralksta <ralksta@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-25 10:08:12 +02:00

97 lines
3.1 KiB
TypeScript

/**
* Which pages a crawler — or a feed reader — may be told about (#472, #471).
*
* This is the part that matters. A sitemap and a feed collect exactly what
* access control otherwise hides: titles, cover images, publication dates. It
* is a leak surface nobody notices, because it never shows up in the browser.
*
* The rules are kept here, as a pure function over a description of the site,
* so both surfaces answer the same question the same way and every exclusion
* can be stated as a test.
*/
export interface PublicAlbum {
id: string;
slug: string;
}
export interface PublicSubpage {
slug: string;
/** `enabled: false` in gallery.yaml — the subpage does not exist publicly. */
enabled: boolean;
/** `hidden: true` — reachable by direct link only, which a listing is not. */
hidden: boolean;
/** The subpage carries a password. */
isProtected: boolean;
albums: PublicAlbum[];
}
export interface PublicJournalEntry {
slug: string;
draft: boolean;
}
export interface SiteShape {
/** A global site password is on and no one is past it. */
siteLocked: boolean;
subpages: PublicSubpage[];
/** Albums that are not part of any subpage. */
standaloneAlbums: PublicAlbum[];
journal: PublicJournalEntry[];
/** Whether an album carries its own password. Keyed by Immich album id. */
isAlbumProtected: (albumId: string) => boolean;
aboutEnabled: boolean;
mapEnabled: boolean;
journalEnabled: boolean;
}
/**
* Every path that may appear in a public listing, in a stable order.
*
* A locked site yields nothing at all: the gate covers the whole site, so
* naming its pages would describe exactly what the password withholds.
*/
export function publicPaths(site: SiteShape): string[] {
if (site.siteLocked) return [];
const paths: string[] = ['/'];
if (site.aboutEnabled) paths.push('/about');
if (site.mapEnabled) paths.push('/map');
if (site.journalEnabled) paths.push('/journal');
for (const subpage of site.subpages) {
// A subpage that is off, unlisted, or behind a password is not a public
// page — and neither is anything underneath it. Inheritance is the case
// that is easy to miss: a public album under a protected subpage is not
// reachable, so listing it would advertise a URL that only asks for a
// password, and name the album while doing it.
if (!subpage.enabled || subpage.hidden || subpage.isProtected) continue;
paths.push(`/${subpage.slug}`);
for (const album of subpage.albums) {
if (site.isAlbumProtected(album.id)) continue;
paths.push(`/${subpage.slug}/${album.slug}`);
}
}
for (const album of site.standaloneAlbums) {
if (site.isAlbumProtected(album.id)) continue;
paths.push(`/${album.slug}`);
}
if (site.journalEnabled) {
for (const entry of site.journal) {
// Drafts stay visible to the logged-in admin and absent for everyone
// else; a listing is "everyone else".
if (entry.draft) continue;
paths.push(`/journal/${entry.slug}`);
}
}
// A slug collision between a subpage and a standalone album would otherwise
// emit the same URL twice.
return [...new Set(paths)];
}