-
Notifications
You must be signed in to change notification settings - Fork 8
Add talk thumbnail rendering for slides and download #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
samholmes
wants to merge
1
commit into
main
Choose a base branch
from
sam/talk-thumbnails
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,283
−718
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| "use client" | ||
| import styled from "styled-components" | ||
|
|
||
| // | ||
| // Types | ||
| // | ||
|
|
||
| export type TalkThumbnailData = { | ||
| speakerName: string | ||
| talkTitle: string | ||
| profilePhotoUrl?: string | ||
| } | ||
|
|
||
| export type TalkThumbnailProps = TalkThumbnailData & { | ||
| /** Width in pixels; height is derived for 16:9 (YouTube thumbnail). */ | ||
| width?: number | ||
| className?: string | ||
| } | ||
|
|
||
| // | ||
| // Constants | ||
| // | ||
|
|
||
| const ASPECT_RATIO = 16 / 9 | ||
| const DEFAULT_WIDTH = 640 | ||
| const BG_IMAGE_PATH = "/images/devx-thumbnail-bg.png" | ||
| const LOGO_IMAGE_PATH = "/images/sd-devx-brand.png" | ||
|
|
||
| // | ||
| // Components | ||
| // | ||
|
|
||
| /** | ||
| * Renders a DEVx-style talk video thumbnail matching the DEVxYouTubeThumbnail.svg | ||
| * template layout: talk title on the left, circular speaker photo on the right, | ||
| * DEVxSD branding at bottom-left, dark silk texture background. | ||
| * | ||
| * 16:9 aspect ratio (YouTube standard 1280x720). | ||
| */ | ||
| export function TalkThumbnail({ | ||
| speakerName, | ||
| talkTitle, | ||
| profilePhotoUrl, | ||
| width = DEFAULT_WIDTH, | ||
| className | ||
| }: TalkThumbnailProps) { | ||
| const height = Math.round(width / ASPECT_RATIO) | ||
|
|
||
| // Layout proportions matching the template | ||
| const pad = width * 0.06 | ||
| const photoRadius = Math.round(height * 0.3) | ||
| const photoBackdropRadius = photoRadius + Math.round(width * 0.01) | ||
| const photoCx = width - pad - photoBackdropRadius | ||
| const photoCy = height * 0.44 | ||
| const titleX = pad | ||
| const photoLeftEdge = photoCx - photoBackdropRadius | ||
| const titleGap = width * 0.04 | ||
| const titleMaxWidth = photoLeftEdge - pad - titleGap | ||
| const titleFontSize = Math.round(width * 0.058) | ||
| const titleY = height * 0.38 | ||
| const logoWidth = Math.round(width * 0.18) | ||
| const logoHeight = Math.round(logoWidth * (582 / 2772)) | ||
| const logoX = pad | ||
| const logoY = height - pad - logoHeight | ||
|
|
||
| const titleLines = wrapText(talkTitle || "Your Talk Title", titleMaxWidth, titleFontSize) | ||
|
|
||
| return ( | ||
| <Wrapper className={className} $width={width} $height={height}> | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| xmlnsXlink="http://www.w3.org/1999/xlink" | ||
| viewBox={`0 0 ${width} ${height}`} | ||
| width="100%" | ||
| height="100%" | ||
| preserveAspectRatio="xMidYMid meet" | ||
| aria-label={`Talk thumbnail: ${talkTitle} by ${speakerName}`} | ||
| > | ||
| <defs> | ||
| {profilePhotoUrl ? ( | ||
| <clipPath id="thumbPhotoClip"> | ||
| <circle cx={photoCx} cy={photoCy} r={photoRadius} /> | ||
| </clipPath> | ||
| ) : null} | ||
| </defs> | ||
|
|
||
| {/* Dark silk texture background */} | ||
| <image | ||
| href={BG_IMAGE_PATH} | ||
| x={0} | ||
| y={0} | ||
| width={width} | ||
| height={height} | ||
| preserveAspectRatio="xMidYMid slice" | ||
| /> | ||
|
|
||
| {/* Speaker photo circle with light backdrop — right side */} | ||
| {profilePhotoUrl ? ( | ||
| <> | ||
| <circle | ||
| cx={photoCx} | ||
| cy={photoCy} | ||
| r={photoBackdropRadius} | ||
| fill="rgba(200, 200, 200, 0.25)" | ||
| /> | ||
| <image | ||
| href={profilePhotoUrl} | ||
| x={photoCx - photoRadius} | ||
| y={photoCy - photoRadius} | ||
| width={photoRadius * 2} | ||
| height={photoRadius * 2} | ||
| clipPath="url(#thumbPhotoClip)" | ||
| preserveAspectRatio="xMidYMid slice" | ||
| /> | ||
| </> | ||
| ) : ( | ||
| <circle | ||
| cx={photoCx} | ||
| cy={photoCy} | ||
| r={photoRadius} | ||
| fill="rgba(255, 255, 255, 0.06)" | ||
| stroke="rgba(255, 255, 255, 0.1)" | ||
| strokeWidth={2} | ||
| /> | ||
| )} | ||
|
|
||
| {/* Talk title — large bold white, left side */} | ||
| <text | ||
| x={titleX} | ||
| y={titleY} | ||
| fill="#ffffff" | ||
| fontFamily="'Chivo', 'Helvetica Neue', Helvetica, Arial, sans-serif" | ||
| fontSize={titleFontSize} | ||
| fontWeight="400" | ||
| > | ||
| {titleLines.map((line, i) => ( | ||
| <tspan key={i} x={titleX} dy={i === 0 ? 0 : titleFontSize * 1.15}> | ||
| {line} | ||
| </tspan> | ||
| ))} | ||
| </text> | ||
|
|
||
| {/* DEVxSD branding — bottom left */} | ||
| <image | ||
| href={LOGO_IMAGE_PATH} | ||
| x={logoX} | ||
| y={logoY} | ||
| width={logoWidth} | ||
| height={logoHeight} | ||
| opacity={0.9} | ||
| /> | ||
| </svg> | ||
| </Wrapper> | ||
| ) | ||
| } | ||
|
|
||
| const Wrapper = styled.div<{ $width: number; $height: number }>` | ||
| width: ${(p) => p.$width}px; | ||
| max-width: 100%; | ||
| aspect-ratio: 16 / 9; | ||
| overflow: hidden; | ||
| border-radius: 0.5rem; | ||
| border: 1px solid rgba(255, 255, 255, 0.1); | ||
| background: #0a0a0a; | ||
|
|
||
| svg { | ||
| display: block; | ||
| width: 100%; | ||
| height: auto; | ||
| } | ||
| ` | ||
|
|
||
| // | ||
| // Functions | ||
| // | ||
|
|
||
| /** Wrap text into lines that fit within maxWidth, max 3 lines. */ | ||
| function wrapText(text: string, maxWidth: number, fontSize: number): string[] { | ||
| if (!text.trim()) return ["Your Talk Title"] | ||
| const words = text.trim().split(/\s+/) | ||
| const approxCharWidth = fontSize * 0.52 | ||
| const maxLines = 3 | ||
| const lines: string[] = [] | ||
| let current = "" | ||
|
|
||
| for (const word of words) { | ||
| const candidate = current ? `${current} ${word}` : word | ||
| if (candidate.length * approxCharWidth <= maxWidth) { | ||
| current = candidate | ||
| } else { | ||
| if (current) lines.push(current) | ||
| if (lines.length >= maxLines) { | ||
| const last = lines[lines.length - 1] | ||
| if (last && word) { | ||
| lines[lines.length - 1] = last + "..." | ||
| } | ||
| return lines | ||
| } | ||
| current = word | ||
| } | ||
| } | ||
| if (current && lines.length < maxLines) lines.push(current) | ||
| return lines | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded SVG clipPath ID causes multi-instance collision
Medium Severity
The
clipPathuses a hardcodedid="thumbPhotoClip". SinceTalkThumbnailis an exported reusable component, rendering multiple instances on the same page (e.g., a talk listing) would create duplicate DOM IDs. TheclipPath="url(#thumbPhotoClip)"reference would resolve to the first instance's clip circle, causing all other thumbnails' photos to be clipped incorrectly. A unique ID per instance (e.g., usinguseId) would fix this.