Page features: directory and blog post tabs, image converter, version names

- Featured event badge: above the event's card from lg up, left out on phones
- Version names from the tag (The Region Cards Update) in the site and admin footers
- Tools -> Image converter (JPG, PNG, WebP in the browser) and Download as in Media
- People directory sections take several tags, a tab each (migration 078)
- Tab blocks split a blog post into tabs; contents follow the open tab (migration 079)
- The side nav sun fades out as the page scrolls into the footer

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aidan Dona 2026-10-16 19:37:07 -05:00
parent a6c66d4607
commit 31afa889d6
28 changed files with 878 additions and 70 deletions

View file

@ -87,6 +87,7 @@ const AdminClips = lazyPage(() => import("./pages/admin/AdminClips.tsx"))
const AdminVideoFrames = lazyPage(() => import("./pages/admin/AdminVideoFrames.tsx"))
const AdminNewsletter = lazyPage(() => import("./pages/admin/AdminNewsletter.tsx"))
const AdminProfiles = lazyPage(() => import("./pages/admin/AdminProfiles.tsx"))
const AdminConvert = lazyPage(() => import("./pages/admin/AdminConvert.tsx"))
const EntityList = lazyPage(() => import("./pages/admin/EntityList.tsx"))
const EntityEdit = lazyPage(() => import("./pages/admin/EntityEdit.tsx"))
@ -155,6 +156,7 @@ export default function App() {
<Route path="requests" element={<AdminFeedback kind="content" />} />
<Route path="media" element={<AdminMedia />} />
<Route path="newsletter" element={<AdminNewsletter />} />
<Route path="convert" element={<AdminConvert />} />
<Route element={<RequireRole role="editor" />}>
<Route path="thumbnails" element={<AdminVideoFrames />} />
</Route>

View file

@ -63,10 +63,13 @@ export default function ContentBlocks({
accent = BRAND,
className = '',
presentAt,
anchorPrefix = '',
}: {
blocks?: ContentBlock[] | null
accent?: string
className?: string
/** Put before each heading's id: a blog post's tab (contents.ts, splitTabs). */
anchorPrefix?: string
/** An event page's presentation route: each schedule gets a Present
* button to it, `?block=<n>` naming which schedule (from 0). */
presentAt?: string
@ -74,7 +77,7 @@ export default function ContentBlocks({
if (!blocks?.length) return null
// Headings get ids so a post's contents (PostContents) and a shared
// link (#getting-there) can point at them.
const { idAt } = headingAnchors(blocks)
const { idAt } = headingAnchors(blocks, anchorPrefix)
// The heading level a block's own headings take: under the last
// heading (h3) or subheading (h4) before it, else the section's h2.
let under = 2
@ -182,6 +185,9 @@ function Block({
const reading = useReadingMode()
switch (block.type) {
// A blog post's tab marker (BlogPost.tsx splits the post at
// them); anywhere else, it reads as a heading.
case 'tab':
case 'heading':
return (
<h3 id={anchor} className="text-2xl font-bold" style={{ color: accentText(accent) }}>

View file

@ -2,6 +2,7 @@ import { Link } from "react-router-dom";
import { useNavSections } from "../lib/navSections.ts";
import { useSiteNav } from "../lib/useSiteNav.ts";
import { useAuth } from "../lib/auth.tsx";
import { VERSION_NAME, VERSION_NUMBER } from "../lib/version.ts";
import SiteLink from "./SiteLink.tsx";
import siteLogo from "../assets/logos/NGU_Logo.svg";
import PlatformIcon from "./PlatformIcon.tsx";
@ -146,7 +147,13 @@ export default function Footer() {
</nav>
<div className="border-t border-white/10 pt-8 flex flex-col md:flex-row items-center justify-between gap-4">
<p className="text-white/65 text-sm">© 2026 Next Generation of Unity. All rights reserved.</p>
<div className="text-center md:text-left">
<p className="text-white/65 text-sm">© 2026 Next Generation of Unity. All rights reserved.</p>
<p className="mt-1 text-white/50 text-xs">
{VERSION_NUMBER}
{VERSION_NAME && <> · {VERSION_NAME}</>}
</p>
</div>
<div className="flex flex-wrap justify-center gap-x-6 gap-y-2">
{nav.legal.map((link) => (
<SiteLink key={`${link.label}${link.path}`} link={link} className={footerLinkClass}>

View file

@ -15,7 +15,12 @@
width 0.6s ease-in-out,
height 0.6s ease-in-out,
left 0.6s ease-in-out,
top 0.6s ease-in-out;
top 0.6s ease-in-out,
opacity 0.4s ease-in-out;
}
/* The page has scrolled into the footer (PageShell.tsx, leaving). */
.side-nav-circle[data-leaving] {
opacity: 0;
}
.side-nav-circle[data-family="green"] {
background: var(--pal-green-3);

View file

@ -215,7 +215,12 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
// Stuck: the page has scrolled the list up to its place under the
// header. The circle then becomes the corner sun (below).
// Leaving: the last section is going up past the list, so the list
// goes with it into the footer; the sun, far bigger than its sticky
// layer, would hang over the footer, so it fades out.
const [stuck, setStuck] = useState(false);
const [leaving, setLeaving] = useState(false);
const listHeight = listBox?.height ?? 0;
useEffect(() => {
const column = columnRef.current;
if (!sideNav || !column) return;
@ -223,7 +228,9 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
const measure = () => {
frame = 0;
const header = parseFloat(getComputedStyle(column).getPropertyValue("--header-h")) || 80;
setStuck(column.getBoundingClientRect().top + listTop <= header + STUCK_TOP + 1);
const box = column.getBoundingClientRect();
setStuck(box.top + listTop <= header + STUCK_TOP + 1);
setLeaving(box.bottom <= header + STUCK_TOP + listHeight + CIRCLE_MARGIN);
};
const onScroll = () => {
if (!frame) frame = requestAnimationFrame(measure);
@ -236,7 +243,7 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
window.removeEventListener("resize", onScroll);
if (frame) cancelAnimationFrame(frame);
};
}, [sideNav, listTop]);
}, [sideNav, listTop, listHeight]);
// The circle's box, from its layer's top left (which sticks with
// the list). At rest: `rest` above. Stuck: a sun in the corner,
@ -314,6 +321,7 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
<div
className="side-nav-circle absolute rounded-full"
data-family={circleFamily(activeAccent)}
data-leaving={leaving || undefined}
style={{
width: circleBox.width,
height: circleBox.height,

View file

@ -0,0 +1,45 @@
import { useId, useState } from 'react'
import { OUTPUT_FORMATS, convertImage, renamed, saveBlob, type OutputType } from '../../lib/convertImage.ts'
/* A Media library image saved as JPG, PNG or WebP, converted in the
browser (src/lib/convertImage.ts). */
export default function DownloadAs({ url, name }: { url: string; name: string }) {
const id = useId()
const [state, setState] = useState<'idle' | 'busy' | string>('idle')
async function download(type: OutputType) {
setState('busy')
try {
const response = await fetch(url)
if (!response.ok) throw new Error(`Couldn't fetch the picture (HTTP ${response.status}).`)
saveBlob(await convertImage(await response.blob(), type), renamed(name, type))
setState('idle')
} catch (err) {
setState(err instanceof Error ? err.message : "Couldn't convert it.")
}
}
return (
<span className="inline-flex flex-wrap items-center gap-1">
<label htmlFor={id} className="sr-only">
Download {name} as
</label>
<select
id={id}
value=""
disabled={state === 'busy'}
onChange={(e) => e.target.value && download(e.target.value as OutputType)}
className="border border-muted/25 bg-surface px-1 py-0.5 text-xs text-link"
>
<option value="">{state === 'busy' ? 'Converting…' : 'Download as…'}</option>
{OUTPUT_FORMATS.map((format) => (
<option key={format.type} value={format.type}>
{format.label}
</option>
))}
</select>
{state !== 'idle' && state !== 'busy' && <span className="text-xs text-danger">{state}</span>}
</span>
)
}

View file

@ -1,17 +1,42 @@
import { mediaUrl } from "../media.ts";
import { PUBLISHED_FIELD, LISTED_FIELD, blocksChild } from "./shared.ts";
import { PUBLISHED_FIELD, LISTED_FIELD, BLOCK_TYPES, TEXT_TYPES, blocksChild } from "./shared.ts";
/* ── Blog (031_blog.sql) ─────────────────────────────────────────
Posts at /blog/:id. The Community page's blog section is edited
with that page (sitePages.ts). */
/* A post's body is the content blocks without the card/body choice:
a post only has a body. */
a post only has a body. Posts also take Tab blocks (079), which
split the post into tabs (BlogPost.tsx, splitTabs). */
const TAB_TYPE = [
"tab",
"Tab",
"Starts a tab, titled by its text, holding the blocks after it up to the next Tab. Blocks before the first Tab are the intro above the tabs. The contents list follows the open tab.",
];
const POST_BLOCK_TYPES = [...BLOCK_TYPES, TAB_TYPE];
const blogBlocksChild = {
...blocksChild,
label: "Post body",
note: "The post, top to bottom. The first paragraph doubles as the excerpt when that's left blank.",
fields: blocksChild.fields.filter((field) => field.path !== "slot"),
note: "The post, top to bottom. The first paragraph doubles as the excerpt when that's left blank. Add Tab blocks to split it into tabs.",
fields: blocksChild.fields
.filter((field) => field.path !== "slot")
.map((field) =>
field.path === "type"
? {
...field,
options: POST_BLOCK_TYPES.map(([value, label]) => [value, label]),
help: (row) => POST_BLOCK_TYPES.find(([value]) => value === row?.type)?.[2],
}
: field.path === "text"
? {
...field,
label: (row) => (row?.type === "tab" ? "Tab title" : (field.label as any)(row)),
when: { path: "type", value: [...TEXT_TYPES, "tab"] },
help: (row) => (row?.type === "tab" ? "eg. Overview" : (field.help as any)(row)),
}
: field,
),
};
export const blogPosts = {

View file

@ -102,19 +102,6 @@ const sectionsChild = (presets: string[]) => ({
},
]
: []),
...(presets.includes("people_directory")
? [
{
path: "tag_id",
label: "Directory: tag",
widget: "select",
optionsFrom: "person_tag_types",
blankLabel: "Default: none (shows nothing)",
help: "Shows the first of its people and links to the full directory",
when: { path: "preset", value: "people_directory" },
},
]
: []),
...(presets.includes("partner_list")
? [
{
@ -146,6 +133,16 @@ const sectionsChild = (presets: string[]) => ({
: []),
],
children: [
{
key: "tags",
label: "Directory: tags",
note: "Each People tag is a tab, in this order, eg. Musicians, Authors, Creators: the first of its people, and a link to its full directory. One tag shows without tabs. Tags are made under Data → People tags.",
addLabel: "Add tag",
when: { path: "preset", value: "people_directory" },
title: (row, options) => options?.person_tag_types?.find((t) => t.id === row.tag_id)?.label ?? "New tag",
blank: { tag_id: "" },
fields: [{ path: "tag_id", label: "Tag", widget: "select", optionsFrom: "person_tag_types", required: true }],
},
{
key: "orgs",
label: "Cards: organizations",

View file

@ -25,8 +25,9 @@ const slug = (text: string) =>
.slice(0, 60) || 'section'
/* One entry per heading or subheading block, in order, and the id
for each block index that is one. */
export function headingAnchors(blocks?: ContentBlock[] | null): {
for each block index that is one. prefix keeps a blog post's tabs
apart (splitTabs): "Overview" in two tabs is two ids. */
export function headingAnchors(blocks?: ContentBlock[] | null, prefix = ''): {
entries: ContentsEntry[]
idAt: Map<number, string>
} {
@ -40,9 +41,39 @@ export function headingAnchors(blocks?: ContentBlock[] | null): {
const base = slug(text)
const n = (seen.get(base) ?? 0) + 1
seen.set(base, n)
const id = n === 1 ? base : `${base}-${n}`
const id = `${prefix}${n === 1 ? base : `${base}-${n}`}`
idAt.set(index, id)
entries.push({ id, text, level: block.type === 'heading' ? 1 : 2 })
})
return { entries, idAt }
}
/* ── A blog post's tabs (079) ──────────────────────────────────
A 'tab' block starts a tab, titled by its text, holding the
blocks after it up to the next; the blocks before the first are
the intro above the tabs. Each tab's heading ids start with its
own, so the same heading in two tabs is two ids; the intro's
keep their plain ids. */
export type PostTab = { id: string; title: string; prefix: string; blocks: ContentBlock[] }
export function splitTabs(blocks?: ContentBlock[] | null): { intro: ContentBlock[]; tabs: PostTab[] } {
const intro: ContentBlock[] = []
const tabs: PostTab[] = []
const seen = new Map<string, number>()
for (const block of blocks ?? []) {
if (block.type === 'tab') {
const title = (block.text ?? '').trim() || `Part ${tabs.length + 1}`
const base = `tab-${slug(title)}`
const n = (seen.get(base) ?? 0) + 1
seen.set(base, n)
const id = n === 1 ? base : `${base}-${n}`
tabs.push({ id, title, prefix: `${id}-`, blocks: [] })
} else if (tabs.length) {
tabs[tabs.length - 1].blocks.push(block)
} else {
intro.push(block)
}
}
return { intro, tabs }
}

72
src/lib/convertImage.ts Normal file
View file

@ -0,0 +1,72 @@
/* ═══════════════════════════════════════════════════════════════
IMAGE CONVERSION, in the browser
Tools → Image converter and the Media library's Download as: a
picture redrawn on a canvas and saved as another format. Nothing
is uploaded. Reads whatever this browser can show (JPEG, PNG,
WebP, GIF's first frame, AVIF, BMP, SVG; HEIC in Safari only).
JPEG has no transparency, so a JPEG's see-through parts are
filled white.
═══════════════════════════════════════════════════════════════ */
export const OUTPUT_FORMATS = [
{ type: 'image/jpeg', label: 'JPG', ext: 'jpg', lossy: true },
{ type: 'image/png', label: 'PNG', ext: 'png', lossy: false },
{ type: 'image/webp', label: 'WebP', ext: 'webp', lossy: true },
] as const
export type OutputType = (typeof OUTPUT_FORMATS)[number]['type']
/* An SVG with no size of its own is drawn this wide. */
const SVG_EDGE = 2048
function loadImage(blob: Blob): Promise<HTMLImageElement> {
const url = URL.createObjectURL(blob)
return new Promise((resolve, reject) => {
const img = new Image()
img.onload = () => resolve(img)
img.onerror = () => reject(new Error("This browser can't read that picture."))
img.src = url
}).finally(() => URL.revokeObjectURL(url)) as Promise<HTMLImageElement>
}
/** The picture as `type`; quality 0 to 1 for JPG and WebP. */
export async function convertImage(blob: Blob, type: OutputType, quality = 0.9): Promise<Blob> {
const img = await loadImage(blob)
const width = img.naturalWidth || SVG_EDGE
const height = img.naturalHeight || SVG_EDGE
const canvas = document.createElement('canvas')
canvas.width = width
canvas.height = height
const context = canvas.getContext('2d')
if (!context) throw new Error("This browser can't draw the picture.")
if (type === 'image/jpeg') {
context.fillStyle = '#ffffff'
context.fillRect(0, 0, width, height)
}
context.drawImage(img, 0, 0, width, height)
const out = await new Promise<Blob | null>((resolve) => canvas.toBlob(resolve, type, quality))
// A browser that can't write the format (old Safari and WebP)
// hands back a PNG, or nothing.
if (!out || out.type !== type) throw new Error(`This browser can't save ${type.split('/')[1].toUpperCase()}.`)
return out
}
/** A file name with the new format's extension. */
export function renamed(name: string, type: OutputType): string {
const ext = OUTPUT_FORMATS.find((f) => f.type === type)?.ext ?? 'img'
const stem = name.replace(/\.[^./]+$/, '') || 'image'
return `${stem}.${ext}`
}
/** Hands the browser a file to save. */
export function saveBlob(blob: Blob, filename: string) {
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = filename
document.body.appendChild(a)
a.click()
a.remove()
setTimeout(() => URL.revokeObjectURL(url), 1000)
}

View file

@ -38,6 +38,7 @@ export type ContentBlock = {
| 'callout'
| 'schedule'
| 'table'
| 'tab'
| 'cards'
| 'people'
text?: string | null

View file

@ -15,8 +15,8 @@ export type SitePageSection = {
scope_id?: string | null
event_type?: string | null
view?: string | null
/** A people_directory preset's tag (Data → People tags). */
tag_id?: string | null
/** A people_directory preset's tags (Data → People tags), a tab each, in order. */
tag_ids: string[]
/** Organization cards: the kinds listed ('partner', 'ministry' or both, comma separated). */
org_kinds?: string | null
/** Organization cards: a hand-picked list, in order, shown instead. */

View file

@ -2,9 +2,27 @@
SITE VERSION: src/lib/version.ts
One string, bumped by hand when the working directory name
changes. The admin footer is the only thing reading it today;
keep it here rather than in a component so the panel, an about
box or a build banner can read the same value later.
changes. Read by the admin's footer and home, and the site's
footer.
Each version has a name, Minecraft style: the tag's words after
the number, "v1.13.2-region-cards" → "The Region Cards Update".
A version with no words after its number has no name.
═══════════════════════════════════════════════════════════════ */
export const SITE_VERSION = "NGU-Web.v1.13.2-region-cards";
/** The number, eg. v1.13.2. */
export const VERSION_NUMBER: string = SITE_VERSION.match(/v\d+(?:\.\d+)*/)?.[0] ?? SITE_VERSION
/** The version's name from its tag, eg. The Region Cards Update, or null. */
export const VERSION_NAME: string | null = (() => {
const words = SITE_VERSION.match(/v\d+(?:\.\d+)*-(.+)$/)?.[1]
if (!words) return null
const title = words
.split('-')
.filter(Boolean)
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ')
return `The ${title} Update`
})()

View file

@ -8,9 +8,16 @@
There's no /blog index on purpose: the Community page's blog
section is where posts are listed, so "back" goes there.
Tab blocks (079) split the body into tabs (contents.ts,
splitTabs): the blocks before the first are an intro above them,
and the contents list follows the open tab. A link to a heading
in another tab (#tab-…) opens that tab. Printed (Download PDF) or
in reading mode, every tab shows, each under its title.
═══════════════════════════════════════════════════════════════ */
import { Link, useParams } from "react-router-dom"
import { useEffect, useId, useState, type KeyboardEvent } from "react"
import { Link, useLocation, useParams } from "react-router-dom"
import PageShell, { type ShellSection } from "../components/PageShell.tsx"
import PageState from "../components/PageState.tsx"
@ -18,9 +25,11 @@ import ContentBlocks from "../components/ContentBlocks.tsx"
import PeopleTiles from "../components/PeopleTiles.tsx"
import { mediaUrl } from "../lib/media.ts"
import { postDate, useBlogPost } from "../lib/useBlog.ts"
import { accentText, BRAND } from "../lib/color.ts"
import { accentText, BRAND, readableOn, withAlpha } from "../lib/color.ts"
import { useReadingMode } from "../lib/readingMode.ts"
import { jumpTo } from "../lib/focus.ts"
import PostContents from "../components/PostContents.tsx"
import { headingAnchors } from "../lib/contents.ts"
import { headingAnchors, splitTabs, type PostTab } from "../lib/contents.ts"
import QrCode from "../components/QrCode.tsx"
import RequestLink from "../components/RequestLink.tsx"
import { siteUrl } from "../lib/site.ts"
@ -34,6 +43,22 @@ const BACK = { to: "/community#blog", label: "Community Blog" }
export default function BlogPost() {
const { id } = useParams()
const { data: post, loading, error, notFound, reload } = useBlogPost(id)
const [tabIndex, setTabIndex] = useState(0)
const reading = useReadingMode()
const { hash } = useLocation()
// A link into another tab (#tab-…) opens it, then goes to the heading.
useEffect(() => {
if (!post || !hash.startsWith("#tab-")) return
const target = decodeURIComponent(hash.slice(1))
const found = splitTabs(post.blocks).tabs
const index = found.findIndex((tab) => target === tab.id || target.startsWith(tab.prefix))
if (index < 0) return
setTabIndex(index)
// The tab's own id is its printed title, hidden on screen: opening
// it is enough. A heading inside it is scrolled to once it shows.
if (target !== found[index].id) requestAnimationFrame(() => jumpTo(target))
}, [post, hash])
if (!post) {
return (
@ -49,8 +74,16 @@ export default function BlogPost() {
)
}
// Two headings or more make a list worth showing.
const contents = post.show_contents ? headingAnchors(post.blocks).entries : []
const { intro, tabs } = splitTabs(post.blocks)
const current = Math.min(tabIndex, Math.max(tabs.length - 1, 0))
// Two headings or more make a list worth showing: the intro's and
// the open tab's.
const contents = post.show_contents
? tabs.length
? [...headingAnchors(intro).entries, ...headingAnchors(tabs[current].blocks, tabs[current].prefix).entries]
: headingAnchors(post.blocks).entries
: []
const withContents = contents.length >= 2
const postUrl = siteUrl(`/blog/${post.id}`)
@ -146,7 +179,14 @@ export default function BlogPost() {
/>
)}
<ContentBlocks blocks={post.blocks} accent={BRAND} />
{tabs.length ? (
<>
<ContentBlocks blocks={intro} accent={BRAND} />
<PostTabs tabs={tabs} current={current} onSelect={setTabIndex} all={reading} />
</>
) : (
<ContentBlocks blocks={post.blocks} accent={BRAND} />
)}
<div className="flex flex-wrap items-center gap-3 border-t border-brand/15 pt-6 text-sm text-muted print:hidden">
Have a story to share?
@ -190,3 +230,86 @@ export default function BlogPost() {
/>
)
}
/* The post's tabs: a row of buttons, then the open tab's blocks. The
others stay in the page, hidden, so print shows them all; `all`
(reading mode) shows every tab, each under its title. */
function PostTabs({
tabs,
current,
onSelect,
all,
}: {
tabs: PostTab[]
current: number
onSelect: (index: number) => void
all: boolean
}) {
const baseId = useId()
// Arrows move one tab and wrap; Home and End jump to the ends.
const onKey = (e: KeyboardEvent<HTMLButtonElement>) => {
const last = tabs.length - 1
const next =
e.key === "ArrowRight" ? (current + 1) % tabs.length
: e.key === "ArrowLeft" ? (current + last) % tabs.length
: e.key === "Home" ? 0
: e.key === "End" ? last
: null
if (next === null) return
e.preventDefault()
onSelect(next)
document.getElementById(`${baseId}-tab-${next}`)?.focus()
}
return (
<div className="space-y-6">
{!all && (
<div role="tablist" aria-label="Parts of this post" className="flex flex-wrap gap-2 print:hidden">
{tabs.map((tab, index) => {
const selected = index === current
return (
<button
key={tab.id}
id={`${baseId}-tab-${index}`}
type="button"
role="tab"
aria-selected={selected}
aria-controls={`${baseId}-panel-${index}`}
tabIndex={selected ? 0 : -1}
onClick={() => onSelect(index)}
onKeyDown={onKey}
className="btn border px-5 py-2 text-sm transition-colors"
style={
selected
? { background: BRAND, borderColor: BRAND, color: readableOn(BRAND) }
: { borderColor: withAlpha(BRAND, 33), color: accentText(BRAND) }
}
>
{tab.title}
</button>
)
})}
</div>
)}
{tabs.map((tab, index) => (
<div
key={tab.id}
id={`${baseId}-panel-${index}`}
role={all ? undefined : "tabpanel"}
aria-labelledby={all ? undefined : `${baseId}-tab-${index}`}
className={all || index === current ? "space-y-6" : "hidden space-y-6 print:block"}
>
<h2
id={tab.id}
className={`text-3xl font-bold ${all ? "" : "hidden print:block"}`}
style={{ color: accentText(BRAND) }}
>
{tab.title}
</h2>
<ContentBlocks blocks={tab.blocks} accent={BRAND} anchorPrefix={tab.prefix} />
</div>
))}
</div>
)
}

View file

@ -31,7 +31,7 @@ import OrgListCards from './sections/OrgList-Card.tsx'
import EventListCards, { EventCardsToggle } from './sections/EventList-Cards.tsx'
import CommunityBlog from './sections/CommunityBlog.tsx'
import HistoryTimeline from './sections/history/HistoryTimeline.tsx'
import PeopleDirectory, { DIRECTORY_PREVIEW } from './sections/PeopleDirectory.tsx'
import { DirectoryTabs, DIRECTORY_PREVIEW } from './sections/PeopleDirectory.tsx'
/* Year the program starts: decades ending before it get the
pre-program look on the timeline. */
@ -91,8 +91,8 @@ const PRESETS: Record<string, (section: SitePageSection) => Record<string, any>>
}),
timeline: () => ({ Component: Timeline }),
people_directory: (section) => ({
Component: PeopleDirectory,
props: { tag: section.tag_id, limit: DIRECTORY_PREVIEW },
Component: DirectoryTabs,
props: { tags: section.tag_ids, limit: DIRECTORY_PREVIEW },
}),
}

View file

@ -0,0 +1,196 @@
/* ═══════════════════════════════════════════════════════════════
ADMIN: IMAGE CONVERTER (Tools → Image converter, everyone)
Pictures turned into JPG, PNG or WebP in the browser
(src/lib/convertImage.ts): pick or drop any number, choose the
format (and quality, for JPG and WebP), download each. Nothing is
uploaded or kept. The Media library's Download as does the same
for a picture already there.
═══════════════════════════════════════════════════════════════ */
import { useId, useState } from "react";
import { OUTPUT_FORMATS, convertImage, renamed, saveBlob, type OutputType } from "../../lib/convertImage.ts";
const MUTED = "var(--color-muted)";
const button =
"btn border border-brand px-4 py-2 text-sm text-link transition-colors hover:bg-tint disabled:cursor-default disabled:opacity-50";
const primary =
"btn bg-action px-5 py-2.5 text-white transition-colors hover:bg-action-hover disabled:bg-muted/25";
type Item = { file: File; result?: Blob; error?: string };
const kb = (bytes: number) => (bytes >= 1024 * 1024 ? `${(bytes / 1024 / 1024).toFixed(1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`);
export default function AdminConvert() {
const inputId = useId();
const formatId = useId();
const qualityId = useId();
const [items, setItems] = useState<Item[]>([]);
const [type, setType] = useState<OutputType>("image/jpeg");
const [quality, setQuality] = useState(90);
const [busy, setBusy] = useState(false);
const [over, setOver] = useState(false);
const lossy = OUTPUT_FORMATS.find((f) => f.type === type)?.lossy;
const add = (files: FileList | null) => {
const pictures = [...(files ?? [])].filter((file) => file.type.startsWith("image/") || /\.(heic|heif)$/i.test(file.name));
setItems((current) => [...current, ...pictures.map((file) => ({ file }))]);
};
async function convertAll() {
setBusy(true);
const next: Item[] = [];
for (const item of items) {
try {
next.push({ file: item.file, result: await convertImage(item.file, type, quality / 100) });
} catch (err) {
next.push({ file: item.file, error: err instanceof Error ? err.message : "Couldn't convert it." });
}
}
setItems(next);
setBusy(false);
}
const done = items.filter((item) => item.result);
return (
<div>
<div className="flex flex-wrap items-baseline gap-3">
<h1 className="text-2xl font-bold text-link">Image converter</h1>
<p className="text-sm" style={{ color: MUTED }}>
Turn pictures into JPG, PNG or WebP. Done in your browser: nothing is uploaded.
</p>
</div>
<section className="mt-6 bg-raised p-5 shadow-md">
<label
htmlFor={inputId}
onDragOver={(e) => {
e.preventDefault();
setOver(true);
}}
onDragLeave={() => setOver(false)}
onDrop={(e) => {
e.preventDefault();
setOver(false);
add(e.dataTransfer.files);
}}
className={`block cursor-pointer border-2 p-8 text-center text-sm transition-colors ${
over ? "border-brand bg-tint" : "border-muted/30"
}`}
>
<span className="font-semibold text-link">Choose pictures</span> or drop them here
<span className="mt-1 block text-xs" style={{ color: MUTED }}>
JPEG, PNG, WebP, GIF, AVIF, BMP or SVG (HEIC in Safari only)
</span>
<input
id={inputId}
type="file"
accept="image/*,.heic,.heif"
multiple
className="sr-only"
onChange={(e) => {
add(e.target.files);
e.target.value = "";
}}
/>
</label>
<div className="mt-5 flex flex-wrap items-end gap-4">
<div>
<label htmlFor={formatId} className="block text-sm font-medium text-body">
Save as
</label>
<select
id={formatId}
value={type}
onChange={(e) => {
setType(e.target.value as OutputType);
setItems((current) => current.map(({ file }) => ({ file })));
}}
className="mt-1 border border-muted/25 bg-surface px-3 py-2 text-sm text-body"
>
{OUTPUT_FORMATS.map((format) => (
<option key={format.type} value={format.type}>
{format.label}
</option>
))}
</select>
</div>
{lossy && (
<div>
<label htmlFor={qualityId} className="block text-sm font-medium text-body">
Quality: {quality}
</label>
<input
id={qualityId}
type="range"
min={40}
max={100}
value={quality}
onChange={(e) => {
setQuality(Number(e.target.value));
setItems((current) => current.map(({ file }) => ({ file })));
}}
className="mt-2 w-48 accent-[var(--color-action)]"
/>
</div>
)}
<button type="button" className={primary} disabled={busy || items.length === 0} onClick={convertAll}>
{busy ? "Converting…" : `Convert ${items.length || ""}`.trim()}
</button>
{done.length > 1 && (
<button
type="button"
className={button}
onClick={() => done.forEach((item) => saveBlob(item.result as Blob, renamed(item.file.name, type)))}
>
Download all
</button>
)}
{items.length > 0 && (
<button type="button" className={button} disabled={busy} onClick={() => setItems([])}>
Clear
</button>
)}
</div>
{type === "image/jpeg" && (
<p className="mt-2 text-xs" style={{ color: MUTED }}>
JPG has no transparency: see-through parts turn white.
</p>
)}
</section>
{items.length > 0 && (
<ul className="mt-6 divide-y divide-brand/10 bg-raised shadow-md">
{items.map((item, index) => (
<li key={`${item.file.name}-${index}`} className="flex flex-wrap items-center gap-3 px-4 py-3 text-sm">
<span className="min-w-0 flex-1 truncate text-body" title={item.file.name}>
{item.file.name}
</span>
<span style={{ color: MUTED }}>{kb(item.file.size)}</span>
{item.result ? (
<>
<span className="text-body">→ {kb(item.result.size)}</span>
<button
type="button"
className={button}
onClick={() => saveBlob(item.result as Blob, renamed(item.file.name, type))}
>
Download {renamed(item.file.name, type)}
</button>
</>
) : item.error ? (
<span className="text-danger">{item.error}</span>
) : (
<span style={{ color: MUTED }}>Ready</span>
)}
</li>
))}
</ul>
)}
</div>
);
}

View file

@ -26,7 +26,7 @@ import { ArrowRight, ArrowUpRight } from "@phosphor-icons/react";
import { Link } from "react-router-dom";
import { useAuth } from "../../lib/auth.tsx";
import { useWideAdminPage } from "../../lib/adminWidth.tsx";
import { SITE_VERSION } from "../../lib/version.ts";
import { SITE_VERSION, VERSION_NAME } from "../../lib/version.ts";
import { ROLE_LABELS, isSuper } from "../../lib/roles.ts";
import { PALETTE } from "../../lib/color.ts";
import { DATA_NAV, FORMS_NAV, PAGES_NAV, PANEL_NAV, TOOLS_NAV, target, visibleItems } from "./adminNav.ts";
@ -187,7 +187,7 @@ export default function AdminHome() {
</PanelSection>
<PanelSection title="Site">
<p className="font-mono text-xs text-muted/80">{SITE_VERSION}</p>
<p className="font-mono text-xs text-muted/80">{SITE_VERSION}{VERSION_NAME && ` · ${VERSION_NAME}`}</p>
<a
href="/"
target="_blank"

View file

@ -26,7 +26,7 @@ import { Link, NavLink, Outlet, useLocation, useNavigate } from "react-router-do
import { useAuth } from "../../lib/auth.tsx";
import { AdminTitleContext } from "../../lib/adminTitle.tsx";
import { AdminWidthContext, type AdminWidth } from "../../lib/adminWidth.tsx";
import { SITE_VERSION } from "../../lib/version.ts";
import { SITE_VERSION, VERSION_NAME } from "../../lib/version.ts";
import { ROLE_LABELS, isSuper } from "../../lib/roles.ts";
import siteLogo from "../../assets/logos/NGU_Logo.svg";
import ThemeToggle from "../../components/ThemeToggle.tsx";
@ -226,7 +226,7 @@ export default function AdminLayout() {
<img src={siteLogo} alt="NGU" className="h-6 w-auto" />
</Link>
<span className="ml-auto font-mono text-xs text-muted/70">
{SITE_VERSION}
{SITE_VERSION}{VERSION_NAME && ` · ${VERSION_NAME}`}
</span>
</div>
</footer>

View file

@ -17,6 +17,7 @@
a page (an image field stores the path, not a foreign key).
═══════════════════════════════════════════════════════════════ */
import DownloadAs from "../../components/admin/DownloadAs.tsx";
import { useEffect, useState, type FormEvent } from "react";
import { Link } from "react-router-dom";
@ -641,6 +642,9 @@ export default function AdminMedia() {
>
Open
</a>
{item.content_type?.startsWith("image/") && (
<DownloadAs url={item.url} name={item.original_name} />
)}
{roleCanWrite(user) && (
<RenameControl
item={item}

View file

@ -201,6 +201,11 @@ export const TOOLS_NAV = {
label: "Media",
blurb: "Uploaded images: logos, photos and backgrounds, ready to reuse.",
},
{
to: "/admin/convert",
label: "Image converter",
blurb: "Turn pictures into JPG, PNG or WebP, in your browser. Images in Media can also be downloaded as any of them.",
},
{
to: "/admin/clips",
label: "Video clips",

View file

@ -11,14 +11,21 @@
"Vocals, piano · Gospel, folk"), or their tagline without one;
their details panel adds their links. With a limit, the first that
many show and a link leads to the full directory.
DirectoryTabs is the preset with several tags (078): a tab each,
in the order picked (Community's Directories: Musicians, Authors,
Creators). One tag shows without tabs; reading mode lists every
tag's people, each under its name.
═══════════════════════════════════════════════════════════════ */
import { ArrowRight } from '@phosphor-icons/react'
import { useId, useState, type KeyboardEvent } from 'react'
import { Link } from 'react-router-dom'
import { PeopleTilesView } from '../../components/PeopleTiles.tsx'
import { useDirectory } from '../../lib/useDirectory.ts'
import { accentText, BRAND } from '../../lib/color.ts'
import { useReadingMode } from '../../lib/readingMode.ts'
import { accentText, BRAND, readableOn, withAlpha } from '../../lib/color.ts'
/* How many people a section shows before "See the full directory". */
export const DIRECTORY_PREVIEW = 12
@ -78,3 +85,95 @@ export default function PeopleDirectory({ tag, limit, accent = BRAND }: PeopleDi
</div>
)
}
/* ── Several tags, a tab each ────────────────────────────────── */
type DirectoryTabsProps = {
tags: string[]
limit?: number
accent?: string
}
export function DirectoryTabs({ tags, limit, accent = BRAND }: DirectoryTabsProps) {
const [active, setActive] = useState(0)
const baseId = useId()
const reading = useReadingMode()
if (tags.length <= 1) return <PeopleDirectory tag={tags[0]} limit={limit} accent={accent} />
if (reading) {
return (
<>
{tags.map((tag) => (
<div key={tag} className="mb-10">
<div className="mx-auto max-w-6xl px-6">
<h3 className="mb-4 text-xl font-bold">
<TagName tag={tag} />
</h3>
</div>
<PeopleDirectory tag={tag} limit={limit} accent={accent} />
</div>
))}
</>
)
}
const current = Math.min(active, tags.length - 1)
// Arrows move one tab and wrap; Home and End jump to the ends.
const onKey = (e: KeyboardEvent<HTMLButtonElement>) => {
const last = tags.length - 1
const next =
e.key === 'ArrowRight' ? (current + 1) % tags.length
: e.key === 'ArrowLeft' ? (current + last) % tags.length
: e.key === 'Home' ? 0
: e.key === 'End' ? last
: null
if (next === null) return
e.preventDefault()
setActive(next)
document.getElementById(`${baseId}-tab-${next}`)?.focus()
}
return (
<>
<div className="mx-auto max-w-6xl px-6">
<div role="tablist" aria-label="Directories" className="mb-8 flex flex-wrap gap-2">
{tags.map((tag, index) => {
const selected = index === current
return (
<button
key={tag}
id={`${baseId}-tab-${index}`}
type="button"
role="tab"
aria-selected={selected}
aria-controls={`${baseId}-panel`}
tabIndex={selected ? 0 : -1}
onClick={() => setActive(index)}
onKeyDown={onKey}
className="btn border px-5 py-2 text-sm transition-colors"
style={
selected
? { background: accent, borderColor: accent, color: readableOn(accent) }
: { borderColor: withAlpha(accent, 33), color: accentText(accent) }
}
>
<TagName tag={tag} />
</button>
)
})}
</div>
</div>
<div id={`${baseId}-panel`} role="tabpanel" aria-labelledby={`${baseId}-tab-${current}`}>
<PeopleDirectory key={tags[current]} tag={tags[current]} limit={limit} accent={accent} />
</div>
</>
)
}
/* A tag's name, from its directory (asked once, and kept for its tab). */
function TagName({ tag }: { tag: string }) {
const { data } = useDirectory(tag)
return <>{data?.name ?? tag}</>
}

View file

@ -19,9 +19,11 @@
video a featured video under a "Featured video" badge.
Never autoplays: an embed waits for play, a file
shows the browser's player
event an event's card under a "Featured event" badge:
its photo, dates, place and buttons. The API picks
the event (pinned, else the countdown's)
event an event's card, under a "Featured event" badge
from lg up (on a phone the card sits under the
words and the badge is left out): its photo, dates,
place and buttons. The API picks the event (pinned,
else the countdown's)
A choice with nothing to show falls back: photos with no photos
to brand, a feature with no link set (or no event to show) to
@ -125,6 +127,12 @@ export default function HeroStage({ hero }: { hero: Hero | null }) {
{feature === 'event' && hero?.event && (
<div className="lg:col-span-7">
{/* Over the card it names, not over the headline beside it;
on a phone the card under the words speaks for itself. */}
<p className="mb-4 hidden items-center gap-3 bg-white/10 px-4 py-1.5 text-sm font-semibold uppercase tracking-[0.2em] text-white backdrop-blur lg:inline-flex">
<Star className="text-[var(--pal-amber-2)]" weight="fill" aria-hidden="true" />
Featured event
</p>
<EventPanel event={hero.event} />
</div>
)}
@ -151,12 +159,7 @@ function Words({ hero, feature }: { hero: Hero; feature: HeroFeature }) {
</span>
)}
</p>
) : feature === 'event' ? (
<p className="mb-6 inline-flex items-center gap-3 bg-white/10 px-4 py-1.5 text-sm font-semibold uppercase tracking-[0.2em] backdrop-blur">
<Star className="text-[var(--pal-amber-2)]" weight="fill" aria-hidden="true" />
Featured event
</p>
) : feature === 'video' ? (
) : feature === 'event' ? null : feature === 'video' ? (
<p className="mb-6 inline-flex items-center gap-3 bg-white/10 px-4 py-1.5 text-sm font-semibold uppercase tracking-[0.2em] backdrop-blur">
<Play className="text-[var(--pal-amber-2)]" weight="fill" aria-hidden="true" />
Featured video