Resolve every record image from the uploads folder
A bare image filename, whatever it belongs to (organization and event logos, people photos, team and award logos, backgrounds, hero photos, block images), now resolves to /uploads/<file>, in media.ts and for link previews in pageMeta.js. The per-kind public/ folders were guesses that don't exist. Only the site's own chosen assets, the NGU logos in the nav, footer and admin, stay bundled from src/assets/logos. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9eeb13c5ec
commit
dad3803ccc
6 changed files with 55 additions and 56 deletions
|
|
@ -57,7 +57,7 @@ In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API mu
|
||||||
- `navConfig.ts` is the single source of truth for navigation, routes, and actions (header, footer, pages).
|
- `navConfig.ts` is the single source of truth for navigation, routes, and actions (header, footer, pages).
|
||||||
- `api.ts` is the shared caching client used by frontend data hooks.
|
- `api.ts` is the shared caching client used by frontend data hooks.
|
||||||
- `docs/updating-data-in-code.md`: where content that isn't in the database lives (admin dropdown labels, fixed value lists, nav, banner, decades, map grid) and how to change it. Keep it current when adding a dropdown or code-owned content.
|
- `docs/updating-data-in-code.md`: where content that isn't in the database lives (admin dropdown labels, fixed value lists, nav, banner, decades, map grid) and how to change it. Keep it current when adding a dropdown or code-owned content.
|
||||||
- Logos: org logos in `public/org-logos/` (served at `/org-logos/`); event logos are uploads (`/uploads/`, a bare filename resolves there). The site's own NGU logos are bundled from `src/assets/logos/`. Image paths resolve through `src/lib/media.ts`. The `<Logo>` component hides itself on load error.
|
- Images: every record image (logos, photos, backgrounds, block images) is an upload. A bare filename resolves to `/uploads/<file>` (`src/lib/media.ts`, and `server/src/pageMeta.js` for previews). Only the site's own chosen assets, the NGU logos in the nav, footer and admin, are bundled from `src/assets/logos/`. The `<Logo>` component hides itself on load error.
|
||||||
|
|
||||||
## Rules and gotchas
|
## Rules and gotchas
|
||||||
- **Role checks must use ladder comparisons, never equality.** Roles rank viewer → editor → admin → superadmin. Use the minimum-rank helpers from `src/lib/roles.ts` (`canWrite`, `canDelete`, `isSuper`, `atLeast`). Where a local variable shadows the name, import with an alias, e.g. `canWrite as roleCanWrite`. `role === "admin"` silently excludes higher roles and has caused repeated bugs.
|
- **Role checks must use ladder comparisons, never equality.** Roles rank viewer → editor → admin → superadmin. Use the minimum-rank helpers from `src/lib/roles.ts` (`canWrite`, `canDelete`, `isSuper`, `atLeast`). Where a local variable shadows the name, import with an alias, e.g. `canWrite as roleCanWrite`. `role === "admin"` silently excludes higher roles and has caused repeated bugs.
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@
|
||||||
/admin noindex
|
/admin noindex
|
||||||
|
|
||||||
Image paths resolve like src/lib/media.ts does: a bare filename
|
Image paths resolve like src/lib/media.ts does: a bare filename
|
||||||
lives in that record kind's public/ directory, anything starting
|
is in the uploads directory, anything starting with / or a scheme
|
||||||
with / or a scheme is used as it is. Keep DIRS in step with it.
|
is used as it is.
|
||||||
An SVG isn't used as a preview image (the big sites won't show
|
An SVG isn't used as a preview image (the big sites won't show
|
||||||
one), so it falls back to the site default.
|
one), so it falls back to the site default.
|
||||||
═══════════════════════════════════════════════════════════════ */
|
═══════════════════════════════════════════════════════════════ */
|
||||||
|
|
@ -45,16 +45,9 @@ export const SITE_CONFIG = path.resolve(process.env.SITE_CONFIG ?? path.join(her
|
||||||
|
|
||||||
const DESCRIPTION_CHARS = 160;
|
const DESCRIPTION_CHARS = 160;
|
||||||
|
|
||||||
/* Where a bare filename lives, per kind. Mirrors src/lib/media.ts. */
|
/* Where a bare filename lives: record images are uploads, whatever
|
||||||
const DIRS = {
|
kind they are. Mirrors src/lib/media.ts. */
|
||||||
person: "/people",
|
const UPLOADS = "/uploads";
|
||||||
eventLogo: "/uploads",
|
|
||||||
eventBackground: "/event-backgrounds",
|
|
||||||
organization: "/org-logos",
|
|
||||||
team: "/team-logos",
|
|
||||||
award: "/award-logos",
|
|
||||||
blog: "/blog",
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ── site.json, reread when it changes ─────────────────────── */
|
/* ── site.json, reread when it changes ─────────────────────── */
|
||||||
|
|
||||||
|
|
@ -94,9 +87,9 @@ const first = (...values) => values.find((v) => v != null && String(v).trim() !=
|
||||||
|
|
||||||
function imageUrl(site, file, kind) {
|
function imageUrl(site, file, kind) {
|
||||||
if (!file || /\.svg(\?|#|$)/i.test(file)) return null;
|
if (!file || /\.svg(\?|#|$)/i.test(file)) return null;
|
||||||
// A bare filename is in that kind's directory, or at the site's
|
// A record's bare filename is an upload; the site's own default
|
||||||
// root for the site's own default (kind null).
|
// image (kind null) is a path from the site's root.
|
||||||
const pathOrUrl = /^(https?:|\/)/.test(file) ? file : kind ? `${DIRS[kind]}/${file}` : `/${file}`;
|
const pathOrUrl = /^(https?:|\/)/.test(file) ? file : kind ? `${UPLOADS}/${file}` : `/${file}`;
|
||||||
return /^https?:/.test(pathOrUrl) ? pathOrUrl : `${origin(site)}${pathOrUrl}`;
|
return /^https?:/.test(pathOrUrl) ? pathOrUrl : `${origin(site)}${pathOrUrl}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1305,7 +1305,7 @@ const frontPage = {
|
||||||
full: true,
|
full: true,
|
||||||
help:
|
help:
|
||||||
"A YouTube, Vimeo or Facebook link, or a video file: a filename in " +
|
"A YouTube, Vimeo or Facebook link, or a video file: a filename in " +
|
||||||
"/front-page/ or a link ending in .mp4 or .webm",
|
"the uploads folder, or a link ending in .mp4 or .webm",
|
||||||
},
|
},
|
||||||
{ path: "video_title", label: "Video title", full: true, help: "Shown after \"Featured video\" above the headline" },
|
{ path: "video_title", label: "Video title", full: true, help: "Shown after \"Featured video\" above the headline" },
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
so the visitor presses play.
|
so the visitor presses play.
|
||||||
|
|
||||||
A featured video can also be a file rather than a link: a
|
A featured video can also be a file rather than a link: a
|
||||||
filename in public/front-page/, a /path, or an https URL ending
|
filename in the uploads directory, a /path, or an https URL ending
|
||||||
in a video extension. videoSource() says which, so the hero can
|
in a video extension. videoSource() says which, so the hero can
|
||||||
hand a file to <video> and a link to an <iframe>.
|
hand a file to <video> and a link to an <iframe>.
|
||||||
═══════════════════════════════════════════════════════════════ */
|
═══════════════════════════════════════════════════════════════ */
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,25 @@
|
||||||
/* ═══════════════════════════════════════════════════════════════
|
/* ═══════════════════════════════════════════════════════════════
|
||||||
MEDIA PATHS
|
MEDIA PATHS
|
||||||
|
|
||||||
Every image field in the API is a bare filename — "where the
|
Every image field in the API is a filename or a path, and where a
|
||||||
images live is the component's business", as history.js puts it.
|
bare filename lives is decided here, in one file.
|
||||||
This is that business, in one file, so moving a directory is one
|
|
||||||
edit rather than a grep.
|
|
||||||
|
|
||||||
⚠ Only two of these directories are confirmed by the admin help
|
One rule: record images are uploads. A value from the media
|
||||||
text: people/. Event logos are uploads. The other three are a guess at
|
library is already '/uploads/<file>'; a bare filename is a file
|
||||||
your convention. Check public/ and fix them here — nothing else
|
copied into the uploads directory by hand (fall-retreat-logo.svg
|
||||||
references the paths.
|
was), so it resolves to /uploads/<file> too. That covers logos,
|
||||||
|
photos, backgrounds, hero slides, block images: everything an
|
||||||
|
editor picks.
|
||||||
|
|
||||||
|
The site's own chosen assets (the NGU logos in the nav, footer
|
||||||
|
and admin) are the exception: they're bundled from
|
||||||
|
src/assets/logos and imported where they're used, not resolved
|
||||||
|
here.
|
||||||
|
|
||||||
A value that already looks like a path or a URL is returned
|
A value that already looks like a path or a URL is returned
|
||||||
untouched, so a hand-written entry can point anywhere.
|
untouched, so a hand-written entry can point anywhere.
|
||||||
|
server/src/pageMeta.js resolves images for link previews by the
|
||||||
|
same rule; keep the two in step.
|
||||||
═══════════════════════════════════════════════════════════════ */
|
═══════════════════════════════════════════════════════════════ */
|
||||||
|
|
||||||
const ABSOLUTE = /^(https?:|\/|data:)/
|
const ABSOLUTE = /^(https?:|\/|data:)/
|
||||||
|
|
@ -29,43 +36,42 @@ function inDir(dir: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const personPhoto = inDir('/people') // confirmed
|
export const UPLOADS = '/uploads'
|
||||||
// Event logos are uploads. A bare filename is one copied into the
|
|
||||||
// uploads directory by hand (fall-retreat-logo.svg was); anything
|
|
||||||
// uploaded through the admin is already /uploads/…
|
|
||||||
export const eventLogo = inDir('/uploads')
|
|
||||||
export const eventBackground = inDir('/event-backgrounds')
|
|
||||||
export const orgLogo = inDir('/org-logos') // ⚠ guess
|
|
||||||
export const teamLogo = inDir('/team-logos') // ⚠ guess
|
|
||||||
export const awardLogo = inDir('/award-logos') // ⚠ guess
|
|
||||||
|
|
||||||
/* front_page_slides.media — the home page hero's photos. New with
|
const inUploads = inDir(UPLOADS)
|
||||||
the Front page editor, which names the directory in its help. */
|
|
||||||
export const heroPhoto = inDir('/front-page')
|
|
||||||
|
|
||||||
/* front_page.video_url when it names a file rather than a link:
|
/* One helper per field, all the same rule, so a caller says what the
|
||||||
same directory as the photos. */
|
image is and a future exception is one line here. */
|
||||||
export const heroVideo = inDir('/front-page')
|
export const personPhoto = inUploads
|
||||||
|
export const eventLogo = inUploads
|
||||||
|
export const eventBackground = inUploads
|
||||||
|
export const orgLogo = inUploads
|
||||||
|
export const teamLogo = inUploads
|
||||||
|
export const awardLogo = inUploads
|
||||||
|
|
||||||
/* content_blocks.media, which can be an image on any owner's page,
|
/* front_page_slides.media, the hero's photos. */
|
||||||
so it can't share a per-entity directory. */
|
export const heroPhoto = inUploads
|
||||||
export const blockMedia = inDir('/media') // ⚠ guess
|
|
||||||
|
|
||||||
/* featured_cards.image, a card's own picture. Normally an upload
|
/* front_page.video_url when it names a file rather than a link.
|
||||||
('/uploads/…'); a bare filename looks here. */
|
Videos can't be uploaded through the media library, so a file is
|
||||||
export const featuredImage = inDir('/featured')
|
one copied into the uploads directory by hand. */
|
||||||
|
export const heroVideo = inUploads
|
||||||
|
|
||||||
/* blog_posts.cover_image and guest_photo. Normally uploads. */
|
/* content_blocks.media and content_block_items.media. */
|
||||||
export const blogImage = inDir('/blog')
|
export const blockMedia = inUploads
|
||||||
|
|
||||||
|
/* featured_cards.image. */
|
||||||
|
export const featuredImage = inUploads
|
||||||
|
|
||||||
|
/* blog_posts.cover_image and guest_photo. */
|
||||||
|
export const blogImage = inUploads
|
||||||
|
|
||||||
/* ── By record kind ────────────────────────────────────────────
|
/* ── By record kind ────────────────────────────────────────────
|
||||||
The timeline sends `logo: { file, kind }` rather than a path,
|
The timeline sends `logo: { file, kind }` rather than a path,
|
||||||
because v_timeline COALESCEs across five tables and only the
|
because v_timeline COALESCEs across five tables and only the
|
||||||
ref_kind says which one the filename came from.
|
ref_kind says which one the filename came from. Featured cards
|
||||||
|
send the same shape. Every kind resolves to the uploads directory
|
||||||
⚠ Three of these directories are the guesses above. Your current
|
today; the map is what lets one kind differ later.
|
||||||
timelineRefs.ts already has the real ones — timeline logos render
|
|
||||||
today — so copy them into the map above and delete this note.
|
|
||||||
───────────────────────────────────────────────────────────── */
|
───────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
const BY_KIND: Record<string, (file?: string | null) => string | null> = {
|
const BY_KIND: Record<string, (file?: string | null) => string | null> = {
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@ import { eventBackground, eventLogo as eventLogoSrc, orgLogo as orgLogoSrc } fro
|
||||||
const DEFAULT_ORG_LOGO = null;
|
const DEFAULT_ORG_LOGO = null;
|
||||||
|
|
||||||
/* An <img> that removes itself if the file 404s. `src` is already
|
/* An <img> that removes itself if the file 404s. `src` is already
|
||||||
resolved by media.ts: an event logo from the uploads directory, an
|
resolved by media.ts: a bare filename from the uploads directory,
|
||||||
organization's from org-logos, anything with a path or URL as is. */
|
anything with a path or URL as it is. */
|
||||||
function Logo({ src, alt = "", className }) {
|
function Logo({ src, alt = "", className }) {
|
||||||
const [failed, setFailed] = useState(false);
|
const [failed, setFailed] = useState(false);
|
||||||
if (!src || failed) return null;
|
if (!src || failed) return null;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue