From d4d63cf5d1f1dc90faa083850854964ef850f4f8 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Tue, 22 Apr 2025 09:38:08 -0500 Subject: [PATCH] Introduce short share urls --- README.md | 1 + src/app/config.ts | 22 ++++++++++++------ src/app/paths.ts | 36 ++++++++++++++++------------- src/camera/CameraShareModal.tsx | 2 +- src/film/FilmShareModal.tsx | 2 +- src/focal/FocalLengthShareModal.tsx | 2 +- src/lens/LensShareModal.tsx | 2 +- src/photo/PhotoShareModal.tsx | 2 +- src/recipe/RecipeShareModal.tsx | 2 +- src/tag/TagShareModal.tsx | 2 +- 10 files changed, 43 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 871ce992..fbb480fe 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ Application behavior can be changed by configuring the following environment var - `NEXT_PUBLIC_NAV_TITLE` (defaults to domain when not configured) - `NEXT_PUBLIC_NAV_CAPTION` (seen in navigation, beneath title) - `NEXT_PUBLIC_PAGE_ABOUT` (seen in grid sidebar—accepts rich formatting tags: ``, ``, ``, ``, ``, `
`) +- `NEXT_PUBLIC_DOMAIN_SHARE` (seen in share modals where a shorter url may be desirable) #### Performance > ⚠️ Enabling may result in increased project usage. Static optimization [troubleshooting hints](#why-do-production-deployments-fail-when-static-optimization-is-enabled) in FAQ. diff --git a/src/app/config.ts b/src/app/config.ts index 29d842b1..b504efb1 100644 --- a/src/app/config.ts +++ b/src/app/config.ts @@ -77,15 +77,22 @@ const SITE_DOMAIN = VERCEL_PRODUCTION_URL || VERCEL_PROJECT_URL || VERCEL_DEPLOYMENT_URL; +const SITE_DOMAIN_SHARE = process.env.NEXT_PUBLIC_DOMAIN_SHARE; // Used primarily for absolute references such as OG images -export const BASE_URL = makeUrlAbsolute(( - process.env.NODE_ENV === 'production' && - VERCEL_ENV !== 'preview' -) ? SITE_DOMAIN - : VERCEL_ENV === 'preview' - ? VERCEL_BRANCH_URL || VERCEL_DEPLOYMENT_URL - : 'http://localhost:3000')?.toLocaleLowerCase(); +export const BASE_URL = + makeUrlAbsolute(( + process.env.NODE_ENV === 'production' && + VERCEL_ENV !== 'preview' + ) ? SITE_DOMAIN + : VERCEL_ENV === 'preview' + ? VERCEL_BRANCH_URL || VERCEL_DEPLOYMENT_URL + : 'http://localhost:3000')?.toLocaleLowerCase(); +export const BASE_URL_SHARE = + makeUrlAbsolute(SITE_DOMAIN_SHARE)?.toLocaleLowerCase(); + +export const getBaseUrl = (share?: boolean) => + share ? BASE_URL_SHARE : BASE_URL; const SITE_DOMAIN_SHORT = shortenUrl(SITE_DOMAIN); @@ -400,6 +407,7 @@ export const APP_CONFIGURATION = { isAdminSqlDebugEnabled: ADMIN_SQL_DEBUG_ENABLED, // Misc baseUrl: BASE_URL, + baseUrlShare: BASE_URL_SHARE, commitSha: VERCEL_GIT_COMMIT_SHA_SHORT, commitMessage: VERCEL_GIT_COMMIT_MESSAGE, commitUrl: VERCEL_GIT_COMMIT_URL, diff --git a/src/app/paths.ts b/src/app/paths.ts index 1c3d0465..5a06f14d 100644 --- a/src/app/paths.ts +++ b/src/app/paths.ts @@ -1,6 +1,6 @@ import { Photo } from '@/photo'; import { PhotoSetCategory } from '@/category'; -import { BASE_URL, GRID_HOMEPAGE_ENABLED } from './config'; +import { getBaseUrl, GRID_HOMEPAGE_ENABLED } from './config'; import { Camera } from '@/camera'; import { parameterize } from '@/utility/string'; import { TAG_HIDDEN } from '@/tag'; @@ -167,28 +167,32 @@ export const pathForRecipe = (recipe: string) => `${PREFIX_RECIPE}/${recipe}`; // Absolute paths -export const ABSOLUTE_PATH_FOR_HOME_IMAGE = `${BASE_URL}/home-image`; +export const ABSOLUTE_PATH_FOR_HOME_IMAGE = + `${getBaseUrl()}/home-image`; -export const absolutePathForPhoto = (params: PhotoPathParams) => - `${BASE_URL}${pathForPhoto(params)}`; +export const absolutePathForPhoto = ( + params: PhotoPathParams, + share?: boolean, +) => + `${getBaseUrl(share)}${pathForPhoto(params)}`; -export const absolutePathForTag = (tag: string) => - `${BASE_URL}${pathForTag(tag)}`; +export const absolutePathForTag = (tag: string, share?: boolean) => + `${getBaseUrl(share)}${pathForTag(tag)}`; -export const absolutePathForCamera= (camera: Camera) => - `${BASE_URL}${pathForCamera(camera)}`; +export const absolutePathForCamera= (camera: Camera, share?: boolean) => + `${getBaseUrl(share)}${pathForCamera(camera)}`; -export const absolutePathForLens= (lens: Lens) => - `${BASE_URL}${pathForLens(lens)}`; +export const absolutePathForLens= (lens: Lens, share?: boolean) => + `${getBaseUrl(share)}${pathForLens(lens)}`; -export const absolutePathForFilm = (film: string) => - `${BASE_URL}${pathForFilm(film)}`; +export const absolutePathForFilm = (film: string, share?: boolean) => + `${getBaseUrl(share)}${pathForFilm(film)}`; -export const absolutePathForRecipe = (recipe: string) => - `${BASE_URL}${pathForRecipe(recipe)}`; +export const absolutePathForRecipe = (recipe: string, share?: boolean) => + `${getBaseUrl(share)}${pathForRecipe(recipe)}`; -export const absolutePathForFocalLength = (focal: number) => - `${BASE_URL}${pathForFocalLength(focal)}`; +export const absolutePathForFocalLength = (focal: number, share?: boolean) => + `${getBaseUrl(share)}${pathForFocalLength(focal)}`; export const absolutePathForPhotoImage = (photo: PhotoOrPhotoId) => `${absolutePathForPhoto({ photo })}/image`; diff --git a/src/camera/CameraShareModal.tsx b/src/camera/CameraShareModal.tsx index e0cb2faf..6bb02073 100644 --- a/src/camera/CameraShareModal.tsx +++ b/src/camera/CameraShareModal.tsx @@ -15,7 +15,7 @@ export default function CameraShareModal({ } & PhotoSetAttributes) { return ( diff --git a/src/film/FilmShareModal.tsx b/src/film/FilmShareModal.tsx index 096cfb29..ee3a6e32 100644 --- a/src/film/FilmShareModal.tsx +++ b/src/film/FilmShareModal.tsx @@ -14,7 +14,7 @@ export default function FilmShareModal({ } & PhotoSetAttributes) { return ( diff --git a/src/focal/FocalLengthShareModal.tsx b/src/focal/FocalLengthShareModal.tsx index 931d60d8..3c2a0d83 100644 --- a/src/focal/FocalLengthShareModal.tsx +++ b/src/focal/FocalLengthShareModal.tsx @@ -14,7 +14,7 @@ export default function FocalLengthShareModal({ } & PhotoSetAttributes) { return ( diff --git a/src/lens/LensShareModal.tsx b/src/lens/LensShareModal.tsx index f18a32c1..d2c5259b 100644 --- a/src/lens/LensShareModal.tsx +++ b/src/lens/LensShareModal.tsx @@ -15,7 +15,7 @@ export default function LensShareModal({ } & PhotoSetAttributes) { return ( diff --git a/src/photo/PhotoShareModal.tsx b/src/photo/PhotoShareModal.tsx index 02576b7f..c2a84ca8 100644 --- a/src/photo/PhotoShareModal.tsx +++ b/src/photo/PhotoShareModal.tsx @@ -9,7 +9,7 @@ export default function PhotoShareModal( ) { return ( diff --git a/src/recipe/RecipeShareModal.tsx b/src/recipe/RecipeShareModal.tsx index f5396473..7c94dd2b 100644 --- a/src/recipe/RecipeShareModal.tsx +++ b/src/recipe/RecipeShareModal.tsx @@ -14,7 +14,7 @@ export default function RecipeShareModal({ } & PhotoSetAttributes) { return ( diff --git a/src/tag/TagShareModal.tsx b/src/tag/TagShareModal.tsx index 38bfaeb0..673ae047 100644 --- a/src/tag/TagShareModal.tsx +++ b/src/tag/TagShareModal.tsx @@ -14,7 +14,7 @@ export default function TagShareModal({ } & PhotoSetAttributes) { return (