Fix page cover display (#291)

* Fix page cover display

Make it always looks good with the recommended size of 1990x480.

* Take maximum size on mobile

* Stabilize visual testing
This commit is contained in:
Greg Bergé
2024-03-18 11:04:28 +01:00
committed by GitHub
parent bda3080b94
commit 5f70ed73b9
4 changed files with 32 additions and 13 deletions
+6
View File
@@ -404,6 +404,12 @@ for (const testCase of testCases) {
}
await argosScreenshot(page, `${testCase.name} - ${testEntry.name}`, {
viewports: ['macbook-13', 'iphone-x', 'ipad-2'],
argosCSS: `
/* Hide Intercom */
.intercom-lightweight-app {
display: none !important;
}
`,
});
});
}
+19 -11
View File
@@ -1,12 +1,14 @@
import { RevisionPageDocument, RevisionPageDocumentCover } from '@gitbook/api';
import { Image } from '@/components/utils';
import { Image, ImageSize } from '@/components/utils';
import { ContentRefContext, resolveContentRef } from '@/lib/references';
import { tcls } from '@/lib/tailwind';
import defaultPageCover from './default-page-cover.svg';
import { PAGE_COVER_HEIGHT } from '../layout';
const PAGE_COVER_SIZE: ImageSize = { width: 1990, height: 480 };
/**
* Cover for the page.
*/
@@ -22,23 +24,29 @@ export async function PageCover(props: {
return (
<div
className={tcls(
PAGE_COVER_HEIGHT,
'overflow-hidden',
'-mx-4',
// Negative margin to balance the container padding
as === 'full'
? ['-mx-4', 'sm:-mx-6', 'md:-mx-8']
: ['max-w-3xl', 'mx-auto', 'rounded-md', 'mb-8'],
? ['sm:-mx-6', 'md:-mx-8', 'lg:ml-0', '-lg:mr-8']
: ['sm:mx-auto', 'max-w-3xl', 'sm:rounded-md', 'mb-8'],
)}
>
<Image
alt="Page cover image"
sources={{
light: {
src: resolved?.href ?? defaultPageCover.src,
size: resolved
? resolved?.fileDimensions
: { width: defaultPageCover.width, height: defaultPageCover.height },
},
light: resolved
? {
src: resolved.href,
size: resolved.fileDimensions,
}
: {
src: defaultPageCover.src,
size: {
width: defaultPageCover.width,
height: defaultPageCover.height,
},
},
}}
resize={
// When using the default cover, we don't want to resize as it's a SVG
@@ -59,13 +67,13 @@ export async function PageCover(props: {
]}
className={tcls(
'w-full',
'h-full',
'object-cover',
'object-center',
as === 'full'
? ['[mask-image:linear-gradient(rgba(0,0,0,1),_rgba(0,0,0,0.5))]']
: null,
)}
inlineStyle={{ aspectRatio: `${PAGE_COVER_SIZE.width}/${PAGE_COVER_SIZE.height}` }}
/>
</div>
);
+6 -1
View File
@@ -28,7 +28,12 @@ export function DateRelative(props: { value: string }) {
const date = new Date(value);
const diff = now - date.getTime();
return (
<time suppressHydrationWarning={true} dateTime={value} title={date.toLocaleString()}>
<time
data-visual-test="transparent"
suppressHydrationWarning={true}
dateTime={value}
title={date.toLocaleString()}
>
{formatDiff(language.locale, diff)}
</time>
);
+1 -1
View File
@@ -7,7 +7,7 @@ import { ClassValue, tcls } from '@/lib/tailwind';
import { PolymorphicComponentProp } from './types';
import { Zoom } from './Zoom';
type ImageSize = { width: number; height: number };
export type ImageSize = { width: number; height: number };
type ImageSource = {
src: string;