-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Image storage in Keystatic Cloud and custom docs image component (#274)
- Loading branch information
1 parent
4563e15
commit 9b7deda
Showing
9 changed files
with
7,751 additions
and
6,800 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,51 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
import { ProgressCircle } from '@voussoir/progress'; | ||
import { getDefaultSrcSet } from '../../utils'; | ||
import { CONTENT_MAX_WIDTH_DESKTOP } from '../../constants'; | ||
|
||
export function CloudImagePreview(props: any) { | ||
const src = props.fields.href.value; | ||
const alt = props.fields.alt.value; | ||
const sizes = props.fields.sizes.value; | ||
const srcSet = props.fields.srcSet.value; | ||
const height = props.fields.height.value; | ||
const width = props.fields.width.value; | ||
|
||
const [isLoading, setIsLoading] = useState(!!src); | ||
|
||
return ( | ||
<> | ||
<p>Href: {src}</p> | ||
<p>Alt text: {alt}</p> | ||
{height && | ||
(isNaN(Number(height)) ? ( | ||
<p style={{ color: 'red' }}> | ||
Invalid height, please enter an integer, e.g. 100 | ||
</p> | ||
) : ( | ||
<p>Height: {height}</p> | ||
))} | ||
{width && | ||
(isNaN(Number(width)) ? ( | ||
<p style={{ color: 'red' }}> | ||
Invalid width, please enter an integer, e.g. 100 | ||
</p> | ||
) : ( | ||
<p>Width: {width}</p> | ||
))} | ||
|
||
{isLoading && <ProgressCircle aria-label="Loading…" isIndeterminate />} | ||
<img | ||
alt={alt} | ||
src={src} | ||
height={height} | ||
width={width} | ||
srcSet={srcSet || getDefaultSrcSet({ src })} | ||
sizes={sizes || `${parseInt(CONTENT_MAX_WIDTH_DESKTOP) * 16}px`} | ||
onLoad={() => setIsLoading(false)} | ||
/> | ||
</> | ||
); | ||
} |
This file contains 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,17 @@ | ||
export const KS_CLOUD_STORAGE_URL = 'https://keystatic.io/'; | ||
export const DEFAULT_IMG_WIDTHS = [375, 960, 1280, 1920]; | ||
|
||
export const MAIN_EL_MAX_WIDTH = '76.5rem'; // 1200px + 24px gutter (`px-6`) as rems | ||
|
||
/** | ||
* This is a 'remainder' value set by 'auto' and is generated by: | ||
* - Content + Side Nav = `MAIN_EL_MAX_WIDTH` (tailwind `max-w-7xl`) | ||
* - padding left + right = 3rem (`px-6`) | ||
* - Side Nav = 15rem (`w-60`) | ||
* - ON THIS PAGE = 12rem | ||
* - gap = 1.5rem (`gap-6`) | ||
* - padding left = 3rem (`pl-12`) | ||
* ----------------------------------- | ||
* Total: 42rem | ||
*/ | ||
export const CONTENT_MAX_WIDTH_DESKTOP = '42rem'; |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
import { DEFAULT_IMG_WIDTHS } from '../constants'; | ||
|
||
export function cx(...classes: string[]) { | ||
return classes.filter(Boolean).join(' '); | ||
} | ||
|
||
export function getDefaultSrcSet({ src }: { src: string }) { | ||
const imgWidths = DEFAULT_IMG_WIDTHS; | ||
|
||
return imgWidths.map(width => `${src}?width=${width} ${width}w`).join(', '); | ||
} |
This file contains 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.
9b7deda
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.
Successfully deployed to the following URLs:
keystatic-site – ./docs
keystatic-site-git-docs-thinkmill-labs.vercel.app
keystatic-site.vercel.app
keystatic-site-thinkmill-labs.vercel.app