Files
immich-folio/lib/photoHash.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

37 lines
1.3 KiB
TypeScript

/**
* The `#photo-N` permalink shared by the photo grid and the lightbox.
*
* The grid writes and restores it; the lightbox offers a button that copies it
* (#478). The format lives here so the two cannot drift apart.
*
* The link is positional, as `gallery.yaml.example` documents: it names a
* place in the album, not an asset, so reordering an album moves where a
* shared link lands.
*/
/** Parse `#photo-N`. Returns a 0-based index, or null if it is not one. */
export function parsePhotoHash(hash: string): number | null {
const match = hash.match(/^#photo-(\d+)$/);
if (!match) return null;
const index = parseInt(match[1], 10) - 1; // 1-indexed in the URL
return index >= 0 ? index : null;
}
/** The hash for a 0-based index, 1-indexed for the reader. */
export function buildPhotoHash(index: number): string {
return `#photo-${index + 1}`;
}
/**
* An absolute permalink to one photo.
*
* Takes the location parts rather than reading `window`, so it is pure and the
* caller does not depend on the grid's hash-sync effect having run yet.
*/
export function buildPhotoPermalink(
location: { origin: string; pathname: string; search: string },
index: number,
): string {
return `${location.origin}${location.pathname}${location.search}${buildPhotoHash(index)}`;
}