-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from storyofams/feat/docs
Feat/docs
- Loading branch information
Showing
36 changed files
with
790 additions
and
375 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
NEXT_PUBLIC_STORYBLOK_TOKEN= | ||
STORYBLOK_PREVIEW_TOKEN= | ||
PREVIEW_TOKEN= |
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ query articleItem($slug: ID!) { | |
filename | ||
} | ||
intro | ||
_editable | ||
} | ||
uuid | ||
} | ||
|
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ query galleryItem($slug: ID!) { | |
images { | ||
filename | ||
} | ||
_editable | ||
} | ||
uuid | ||
} | ||
|
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
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
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,6 +1,25 @@ | ||
import { Richtext } from '../story'; | ||
|
||
import { getPlainText } from './getPlainText'; | ||
import { getPlainText, GetPlainTextOptions } from './getPlainText'; | ||
|
||
export const getExcerpt = (richtext: Richtext, maxLength = 320) => | ||
getPlainText(richtext, { addNewlines: false, maxLength }); | ||
interface GetExcerptOptions extends GetPlainTextOptions { | ||
/** | ||
* After how many characters the text should be cut off. | ||
* | ||
* @default 320 | ||
*/ | ||
maxLength?: number; | ||
} | ||
|
||
export const getExcerpt = ( | ||
richtext: Richtext, | ||
{ maxLength, ...options }: GetExcerptOptions = { maxLength: 320 }, | ||
) => { | ||
const text = getPlainText(richtext, { addNewlines: false, ...options }); | ||
|
||
if (!text || !maxLength || text?.length < maxLength) { | ||
return text; | ||
} | ||
|
||
return `${text?.substring(0, maxLength)}…`; | ||
}; |
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,86 @@ | ||
--- | ||
id: Image | ||
title: Image | ||
sidebar_label: Image | ||
hide_title: true | ||
--- | ||
|
||
# `Image` | ||
|
||
A component that renders optimized and responsive images using Storyblok's image service. With support for lazy loading and LQIP (Low-Quality Image Placeholders). | ||
|
||
The component will automatically try to load a WebP version of the image if the browser supports it. | ||
|
||
Lazy loading uses the native browser implementation if available, otherwise an IntersectionObserver (polyfilled if needed) is used as fallback. | ||
|
||
The low-quality image placeholder is a small (max 32 pixels wide), blurred version of the image that is loaded as fast as possible and presented while the full image is loading. As soon as the full image loads, the placeholder is faded out. | ||
|
||
## Parameters | ||
|
||
`Image` accepts the normal HTML `img` attributes, but the `src` is expected to be a Storyblok asset URL. | ||
|
||
There are two important parameters that make sure the images are responsive: `fixed` and `fluid`. You should use one or the other. | ||
- `fixed`: use if you know the exact size the image will be. | ||
- `fluid`: is made for images that stretch a container of variable size (different size based on screen size). Use if you don't know the exact size the image will be. | ||
|
||
```ts no-transpile | ||
interface GetImagePropsOptions { | ||
/** | ||
* Optimize the image sizes for a fixed size. Use if you know the exact size | ||
* the image will be. | ||
* Format: `[width, height]`. | ||
*/ | ||
fixed?: [number, number]; | ||
/** | ||
* Optimize the image sizes for a fluid size. Fluid is for images that stretch | ||
* a container of variable size (different size based on screen size). | ||
* Use if you don't know the exact size the image will be. | ||
* Format: `width` or `[width, height]`. | ||
*/ | ||
fluid?: number | [number, number]; | ||
/** | ||
* Apply the `smart` filter. | ||
* @see https://www.storyblok.com/docs/image-service#facial-detection-and-smart-cropping | ||
* | ||
* @default true | ||
*/ | ||
smart?: boolean; | ||
} | ||
|
||
interface ImageProps | ||
extends React.DetailedHTMLProps< | ||
React.ImgHTMLAttributes<HTMLImageElement>, | ||
HTMLImageElement | ||
>, | ||
GetImagePropsOptions { | ||
/** | ||
* It's recommended to put lazy=false on images that are already in viewport | ||
* on load. If false, the image is loaded eagerly. | ||
* | ||
* @default true | ||
*/ | ||
lazy?: boolean; | ||
/** | ||
* The media attribute specifies a media condition (similar to a media query) | ||
* that the user agent will evaluate for each <source> element. | ||
* | ||
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture#the_media_attribute | ||
*/ | ||
media?: string; | ||
} | ||
|
||
const Image: (props: ImageProps) => JSX.Element | ||
``` | ||
## Usage | ||
### Basic example | ||
```ts | ||
<Image | ||
src={storyblok_image?.filename} | ||
fluid={696} | ||
alt={storyblok_image?.alt} | ||
width="100%" | ||
/> | ||
``` |
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,41 @@ | ||
--- | ||
id: StoryProvider | ||
title: StoryProvider | ||
sidebar_label: StoryProvider | ||
hide_title: true | ||
--- | ||
|
||
# `StoryProvider` | ||
|
||
A global provider that provides the context to make `withStory` work, holding the current story. Also makes sure the Storyblok JS Bridge gets loaded when needed. | ||
|
||
## Parameters | ||
|
||
`StoryProvider` accepts the following properties: | ||
|
||
```ts no-transpile | ||
interface ProviderProps { | ||
children: ReactNode; | ||
/** | ||
* Relations that need to be resolved in preview mode, for example: | ||
* `['Post.author']` | ||
*/ | ||
resolveRelations?: string[]; | ||
} | ||
|
||
const StoryProvider: (props: ProviderProps) => JSX.Element | ||
``` | ||
## Usage | ||
### Basic example | ||
Wrap your entire app in the provider. For example in Next.js, in the render function of `_app`: | ||
```ts | ||
// Other providers | ||
<StoryProvider> | ||
// The rest of your app | ||
<Component {...pageProps} /> | ||
</StoryProvider> | ||
``` |
Oops, something went wrong.