Add image uploads with a media library, and event card backgrounds
Uploads (migration 028, server/src/media.js, routes/media.js): editors and up upload JPEG, PNG, GIF, WebP or SVG. Photos are resized to 2400px and saved as WebP by default, or kept as uploaded on request. Files live in UPLOADS_DIR, served by nginx in production and by the API in dev. Admins and up delete, after seeing what still uses the file. Every image field in the editor is now an image widget: preview, the path as text, Upload and Choose from library. A new Media page lists the library. Org lists and event cards now resolve logos through media.ts, so uploaded paths work there. Events get a card_image (migration 029): a photo behind the card under a light veil so the text stays readable. The card's size is unchanged. Setup for production is in docs/media-uploads.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cd393e4ab2
commit
eaff23839f
26 changed files with 1234 additions and 22 deletions
|
|
@ -5,6 +5,7 @@ import { eventHref } from "../../lib/hrefs.ts";
|
|||
import { EVENT_TYPES, eventTypeLabel } from "../../lib/eventTypes.ts";
|
||||
import { seriesLabel } from "../../lib/eventSeries.ts";
|
||||
import PlatformIcon from "../../components/PlatformIcon.tsx";
|
||||
import { eventBackground, isAbsoluteMedia } from "../../lib/media.ts";
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════════
|
||||
EVENT LIST — CARDS
|
||||
|
|
@ -35,7 +36,9 @@ const LOGOS = Object.fromEntries(
|
|||
Object.entries(LOGO_FILES).map(([path, src]) => [path.split("/").pop(), src])
|
||||
);
|
||||
|
||||
const logoSrc = file => (file && LOGOS[file]) || null;
|
||||
/* A bundled logo by filename, or an upload or URL as it is. */
|
||||
const logoSrc = file =>
|
||||
(file && LOGOS[file]) || (isAbsoluteMedia(file) ? file : null);
|
||||
|
||||
/* Last resort only. The API already falls back to the host
|
||||
organization's logo when an event doesn't name its own, so this
|
||||
|
|
@ -60,6 +63,25 @@ function Logo({ file, alt = "", className }) {
|
|||
const TEAL = "#138ba0"; // last-resort card color
|
||||
const CARD_BG = "#ffffff"; // sits under every card, gradient or not
|
||||
|
||||
/* Laid over a card's background image so black text reads on any
|
||||
photo. Heavier at the top, where the title and dates are, and
|
||||
lighter lower down so more of the picture shows through. */
|
||||
const CARD_IMAGE_VEIL =
|
||||
"linear-gradient(to bottom, rgba(255,255,255,0.9), rgba(255,255,255,0.78))";
|
||||
|
||||
/* The card's background layers, top first: its gradient if it has
|
||||
one, then the veil and photo if it has one, then white. */
|
||||
function cardBackground(ev) {
|
||||
const layers: string[] = [];
|
||||
if (ev.gradient) layers.push(ev.gradient);
|
||||
const image = eventBackground(ev.card_image);
|
||||
if (image) {
|
||||
layers.push(CARD_IMAGE_VEIL, `url(${JSON.stringify(image)}) center / cover no-repeat`);
|
||||
}
|
||||
layers.push(CARD_BG);
|
||||
return layers.join(", ");
|
||||
}
|
||||
|
||||
/* ── Grid view ────────────────────────────────────────────────
|
||||
The grid fits as many columns as the screen allows, with no
|
||||
breakpoints: each card is at least CARD_MIN wide, and the
|
||||
|
|
@ -185,7 +207,7 @@ export function Card({
|
|||
}`}
|
||||
style={{
|
||||
border: `1px solid ${color}`,
|
||||
background: ev.gradient ? `${ev.gradient}, ${CARD_BG}` : CARD_BG,
|
||||
background: cardBackground(ev),
|
||||
filter: past ? "saturate(0.75)" : "none",
|
||||
pointerEvents: interactive ? "auto" : "none",
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { useState } from "react";
|
||||
import ArrowLink from "../../components/ArrowLink.tsx";
|
||||
import { orgLogo } from "../../lib/media.ts";
|
||||
import {
|
||||
initialsFor,
|
||||
orgPath,
|
||||
|
|
@ -21,8 +22,6 @@ import {
|
|||
array — only the short card description.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
const LOGO_BASE = "/org-logos/";
|
||||
|
||||
const MUTED = "#7a9299";
|
||||
const INK = "#2c4a50";
|
||||
const FALLBACK_COLOR = "#4a6b72";
|
||||
|
|
@ -39,7 +38,7 @@ function OrgMark({ org, color }) {
|
|||
if (org.logo && !failed) {
|
||||
return (
|
||||
<img
|
||||
src={`${LOGO_BASE}${org.logo}`}
|
||||
src={orgLogo(org.logo) ?? undefined}
|
||||
alt=""
|
||||
onError={() => setFailed(true)}
|
||||
className="h-14 w-14 object-contain rounded-xl shrink-0"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from "react";
|
|||
import { useCommunity } from "../../data/chapters.ts";
|
||||
import { Link } from "react-router-dom";
|
||||
import ArrowLink from "../../components/ArrowLink.tsx";
|
||||
import { orgLogo } from "../../lib/media.ts";
|
||||
import { initialsFor, orgPath } from "../../data/organizations.ts";
|
||||
import { AREAS, AREA_NAMES } from "../../data/mapGrid.ts";
|
||||
|
||||
|
|
@ -39,8 +40,6 @@ const ROWS = 7;
|
|||
// stays at max-w-6xl, so this deliberately breaks out past it.
|
||||
const CONTENT_MAX = "88rem";
|
||||
|
||||
const LOGO_BASE = "/org-logos/";
|
||||
|
||||
const MUTED = "#7a9299";
|
||||
const RULE = "#cfe3e7";
|
||||
const INK = "#2c4a50";
|
||||
|
|
@ -472,7 +471,7 @@ function OrgLogo({ org, color, size = "h-14 w-14" }) {
|
|||
if (org.logo && !failed) {
|
||||
return (
|
||||
<img
|
||||
src={`${LOGO_BASE}${org.logo}`}
|
||||
src={orgLogo(org.logo) ?? undefined}
|
||||
alt={org.name}
|
||||
onError={() => setFailed(true)}
|
||||
className={`${size} object-contain rounded-xl shrink-0`}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { useId, useState } from "react";
|
||||
import ArrowLink from "../../components/ArrowLink.tsx";
|
||||
import { orgLogo } from "../../lib/media.ts";
|
||||
import PlatformIcon from "../../components/PlatformIcon.tsx";
|
||||
import {
|
||||
areasSentence,
|
||||
|
|
@ -36,8 +37,6 @@ import {
|
|||
a partner row simply doesn't have them.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
const LOGO_BASE = "/org-logos/";
|
||||
|
||||
const MUTED = "#7a9299";
|
||||
const RULE = "#cfe3e7";
|
||||
const INK = "#2c4a50";
|
||||
|
|
@ -66,7 +65,7 @@ function OrgMark({ org, color }) {
|
|||
if (org.logo && !failed) {
|
||||
return (
|
||||
<img
|
||||
src={`${LOGO_BASE}${org.logo}`}
|
||||
src={orgLogo(org.logo) ?? undefined}
|
||||
alt=""
|
||||
onError={() => setFailed(true)}
|
||||
className="h-8 w-8 object-contain shrink-0"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue