Improve/streamline camera text formatting

This commit is contained in:
Sam Becker 2025-02-04 20:43:27 -06:00
parent d132e85ced
commit 403c846d33
7 changed files with 60 additions and 42 deletions

View File

@ -14,19 +14,24 @@ const RICOH : Camera = {
describe('Camera', () => { describe('Camera', () => {
it('labels full text correctly', () => { it('labels full text correctly', () => {
expect(formatCameraText(APPLE)).toBe('iPhone 11 Pro'); expect(formatCameraText(APPLE)).toBe('iPhone 11 Pro');
expect(formatCameraText(APPLE, 'always')).toBe('Apple iPhone 11 Pro'); expect(formatCameraText(APPLE, 'long')).toBe('Apple iPhone 11 Pro');
expect(formatCameraText(APPLE, 'if-not-apple')).toBe('iPhone 11 Pro'); expect(formatCameraText(APPLE, 'medium')).toBe('iPhone 11 Pro');
expect(formatCameraText(APPLE, 'never')).toBe('iPhone 11 Pro'); expect(formatCameraText(APPLE, 'short')).toBe('11 Pro');
expect(formatCameraText(FUJIFILM)).toBe('Fujifilm X-T5'); expect(formatCameraText(FUJIFILM)).toBe('Fujifilm X-T5');
expect(formatCameraText(CANON)).toBe('Canon EOS 800D'); expect(formatCameraText(CANON)).toBe('Canon EOS 800D');
expect(formatCameraText(NIKON, 'long'))
.toBe('Nikon Corporation Nikon D7000');
expect(formatCameraText(NIKON)).toBe('Nikon D7000'); expect(formatCameraText(NIKON)).toBe('Nikon D7000');
expect(formatCameraText(RICOH)).toBe('RICOH GR III'); expect(formatCameraText(RICOH)).toBe('RICOH GR III');
}); });
it('labels models correctly', () => { it('labels models correctly', () => {
expect(formatCameraText(APPLE, 'never')).toBe('iPhone 11 Pro'); expect(formatCameraText(APPLE, 'medium')).toBe('iPhone 11 Pro');
expect(formatCameraText(APPLE, 'never', true)).toBe('11 Pro'); expect(formatCameraText(APPLE, 'short')).toBe('11 Pro');
expect(formatCameraText(APPLE_01, 'never', true)).toBe('iPhone 11'); expect(formatCameraText(APPLE_01, 'short')).toBe('iPhone 11');
expect(formatCameraText(APPLE_02, 'never', true)).toBe('15 Pro Max'); expect(formatCameraText(APPLE_02, 'short')).toBe('15 Pro Max');
expect(formatCameraText(FUJIFILM, 'short')).toBe('X-T5');
expect(formatCameraText(RICOH, 'short')).toBe('GR III');
expect(formatCameraText(NIKON, 'short')).toBe('D7000');
}); });
}); });

View File

@ -57,8 +57,11 @@ export const cameraFromPhoto = (
export const formatCameraText = ( export const formatCameraText = (
{ make, model: modelRaw }: Camera, { make, model: modelRaw }: Camera,
includeMake: 'always' | 'never' | 'if-not-apple' = 'if-not-apple', length:
removeIPhoneOnLongModels?: boolean, 'long' | // Unmodified make and model
'medium' | // Make and model, with modifiers removed
'short' // Model only
= 'medium',
) => { ) => {
// Capture simple make without modifiers like 'Corporation' or 'Company' // Capture simple make without modifiers like 'Corporation' or 'Company'
const makeSimple = make.match(/^(\S+)/)?.[1]; const makeSimple = make.match(/^(\S+)/)?.[1];
@ -67,20 +70,23 @@ export const formatCameraText = (
modelRaw.toLocaleLowerCase().startsWith(makeSimple.toLocaleLowerCase()) modelRaw.toLocaleLowerCase().startsWith(makeSimple.toLocaleLowerCase())
); );
let model = modelRaw; let model = modelRaw;
switch (length) {
case 'long':
return `${make} ${model}`;
case 'medium':
return doesModelStartWithMake || make === 'Apple'
? model
: `${make} ${model}`;
case 'short':
model = doesModelStartWithMake
? model.replace(makeSimple, '').trim()
: model;
if ( if (
removeIPhoneOnLongModels &&
model.includes('iPhone') && model.includes('iPhone') &&
model.length > 9 model.length > 9
) { ) {
model = model.replace(/iPhone\s*/i, ''); model = model.replace(/iPhone\s*/i, '');
} }
return ( return model;
includeMake === 'never' || }
doesModelStartWithMake ||
(includeMake === 'if-not-apple' && make === 'Apple')
) ? model
: `${make} ${model}`;
}; };
export const formatCameraModelTextShort = (camera: Camera) =>
formatCameraText(camera, 'never', true);

View File

@ -40,7 +40,6 @@ export default function CameraImageResponse({
icon: <IoMdCamera icon: <IoMdCamera
size={height * .079} size={height * .079}
style={{ style={{
transform: `translateY(${height * .003}px)`,
marginRight: height * .015, marginRight: height * .015,
}} }}
/>, />,

View File

@ -39,7 +39,7 @@ export default function FocalLengthImageResponse({
icon: <TbCone icon: <TbCone
size={height * .075} size={height * .075}
style={{ style={{
transform: `translateY(${height * .007}px) rotate(270deg)`, transform: `translateY(${height * .002}px) rotate(270deg)`,
marginRight: height * .01, marginRight: height * .01,
}} }}
/>, />,

View File

@ -5,7 +5,7 @@ import ImagePhotoGrid from './components/ImagePhotoGrid';
import ImageContainer from './components/ImageContainer'; import ImageContainer from './components/ImageContainer';
import { OG_TEXT_BOTTOM_ALIGNMENT } from '@/site/config'; import { OG_TEXT_BOTTOM_ALIGNMENT } from '@/site/config';
import { NextImageSize } from '@/services/next-image'; import { NextImageSize } from '@/services/next-image';
import { cameraFromPhoto, formatCameraModelTextShort } from '@/camera'; import { cameraFromPhoto, formatCameraText } from '@/camera';
export default function PhotoImageResponse({ export default function PhotoImageResponse({
photo, photo,
@ -22,7 +22,7 @@ export default function PhotoImageResponse({
}) { }) {
const caption = [ const caption = [
photo.model photo.model
? formatCameraModelTextShort(cameraFromPhoto(photo)) ? formatCameraText(cameraFromPhoto(photo), 'short')
: undefined, : undefined,
photo.focalLengthFormatted, photo.focalLengthFormatted,
photo.fNumberFormatted, photo.fNumberFormatted,

View File

@ -40,7 +40,6 @@ export default function TagImageResponse({
? <FaStar ? <FaStar
size={height * .066} size={height * .066}
style={{ style={{
transform: `translateY(${height * .0095}px)`,
// Fix horizontal distortion in icon size // Fix horizontal distortion in icon size
width: height * .076, width: height * .076,
marginRight: height * .015, marginRight: height * .015,
@ -49,7 +48,7 @@ export default function TagImageResponse({
: <FaTag : <FaTag
size={height * .06} size={height * .06}
style={{ style={{
transform: `translateY(${height * .016}px)`, transform: `translateY(${height * .006}px)`,
marginRight: height * .02, marginRight: height * .02,
}} }}
/>, />,

View File

@ -28,7 +28,7 @@ export default function ImageCaption({
fontFamily, fontFamily,
fontSize: height *.08, fontSize: height *.08,
gap: '1rem', // Mimic mono font space metric gap: '1rem', // Mimic mono font space metric
lineHeight: 1, lineHeight: 1.2,
left: 0, left: 0,
right: 0, right: 0,
...OG_TEXT_BOTTOM_ALIGNMENT ...OG_TEXT_BOTTOM_ALIGNMENT
@ -44,6 +44,14 @@ export default function ImageCaption({
background: `linear-gradient(to top, ${GRADIENT_STOPS})`, background: `linear-gradient(to top, ${GRADIENT_STOPS})`,
top: 0, top: 0,
}, },
}}>
<div style={{
display: 'flex',
alignItems: 'center',
gap: height * .034,
...OG_TEXT_BOTTOM_ALIGNMENT
? { marginBottom: -height * .008 }
: { marginTop: -height * .008 },
}}> }}>
{icon} {icon}
<div <div
@ -58,5 +66,6 @@ export default function ImageCaption({
{children} {children}
</div> </div>
</div> </div>
</div>
); );
} }