Skip to content

Commit 16f0baf

Browse files
author
Marcy Sutton
authored
fix(docs): improve image docs from workflow evaluation (#14697)
* add API doc for Gatsby Image, improve API titles * improve content in image docs * add doc on working with GIFs * chore: format * update GIFs page with an animated GIF, for reasons * a few copy tweaks to Gatsby Image API doc * code block tweaks and moving links * add markdown + a11y note to GIFs page * pr feedback from Jason * change warning to a note per feedback * Update docs/docs/using-gatsby-image.md Co-Authored-By: gillkyle <kylerobertgill@gmail.com> * Update docs/docs/gatsby-image.md Co-Authored-By: gillkyle <kylerobertgill@gmail.com> * chore: add example images demonstrating duotone and grayscale in image api * add install code blocks for copy/paste
1 parent 37759db commit 16f0baf

File tree

12 files changed

+460
-13
lines changed

12 files changed

+460
-13
lines changed

docs/docs/gatsby-config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Gatsby Config
2+
title: Gatsby Config API
33
---
44

55
Site configuration options for a Gatsby site are placed in a file at the root of the project folder called `gatsby-config.js`.

docs/docs/gatsby-image.md

Lines changed: 392 additions & 0 deletions
Large diffs are not rendered by default.

docs/docs/gatsby-link.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Gatsby Link
2+
title: Gatsby Link API
33
---
44

55
For internal navigation, Gatsby includes a built-in `<Link>` component as well as a `navigate` function which is used for programmatic navigation.

docs/docs/images-and-files.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
2-
title: Images, Files, and Video
3-
overview: true
2+
title: Images, Files, and Video in Gatsby
43
---
54

6-
Gatsby provides multiple solutions for adding images, video, and files into your projects. This section will walk you through several common patterns for handling media with Gatsby.
5+
Gatsby provides multiple solutions for adding images, video, and files to your projects. And a pro tip: you don't necessarily have to use GraphQL! From [imports](/docs/importing-assets-into-files/) and use of the [static folder](/docs/static-folder/) to dynamic queries with [Gatsby Image](/docs/using-gatsby-image/) to prevent image bloat, you've got options.
6+
7+
This section will walk you through several common patterns for handling media with Gatsby, where you can learn about the pros and cons of each method.
78

89
<GuideList slug={props.slug} />

docs/docs/images/dancing-otter.gif

175 KB
Loading
785 KB
Loading
706 KB
Loading

docs/docs/using-gatsby-image.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
---
2-
title: Using Gatsby Image
2+
title: Using Gatsby Image to Prevent Image Bloat
33
---
44

5-
# Using gatsby-image to prevent image bloat
6-
75
`gatsby-image` is a React component designed to work seamlessly with Gatsby’s GraphQL queries ([`gatsby-image` plugin README](/packages/gatsby-image/)). It combines [Gatsby’s native image processing](https://image-processing.gatsbyjs.org/) capabilities with advanced image loading techniques to easily and completely optimize image loading for your sites. `gatsby-image` uses [gatsby-plugin-sharp](/packages/gatsby-plugin-sharp/) to power its image transformations.
86

97
> _Warning: gatsby-image is **not** a drop-in replacement for `<img />`. It’s optimized for fixed width/height images and images that stretch the full-width of a container. Some ways you can use `<img />` won’t work with gatsby-image._
@@ -16,6 +14,8 @@ title: Using Gatsby Image
1614
- holds an image’s position so your page doesn’t jump around as images load
1715
- makes it easy to add a placeholder—either a gray background or a blurry version of the image.
1816

17+
_For more complete API information, check out the [Gatsby Image API](/docs/gatsby-image/) docs._
18+
1919
## Problem
2020

2121
Large, unoptimized images dramatically slow down your site.
@@ -105,11 +105,12 @@ export default ({ data }) => (
105105

106106
This GraphQL query creates multiple sizes of the image and when the page is rendered the image that is appropriate for the current screen resolution (e.g. desktop, mobile, and everything in between) is used. The `gatsby-image` component automatically enables a blur-up effect as well as lazy loading images that are not currently on screen.
107107

108-
So this is all very nice and it’s far better to be able to use this from NPM vs. implementing it yourself or cobbling together several standalone libraries.
108+
So this is all very nice and it’s far better to be able to use this from npm vs. implementing it yourself or cobbling together several standalone libraries.
109109

110-
### References:
110+
### Additional resources
111111

112-
- [Gatsby image plugin README file](/packages/gatsby-image/)
112+
- [Gatsby Image API docs](/docs/gatsby-image/)
113+
- [gatsby-image plugin README file](/packages/gatsby-image/)
113114
- [Source code for an example site using gatsby-image](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-gatsby-image)
114115
- [Blog articles about gatsby-image](/blog/tags/gatsby-image/)
115116
- [Starters that use gatsby-image](/starters/?d=gatsby-image&v=2)

docs/docs/working-with-gifs.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: Working With GIFs
3+
---
4+
5+
If you're building a blog with Gatsby, chances are you'll want to include some animated GIFs: who wouldn't want to include a dancing otter or cat GIF?
6+
7+
## Including GIFs in components
8+
9+
In Gatsby components and pages, you'll want to import animated GIFs instead of using Gatsby Image because of the way it optimizes image data for the responsive picture element.
10+
11+
Here's an example:
12+
13+
```jsx:title=pages/about.js
14+
import React from 'react'
15+
16+
import Layout from '../components/layout'
17+
import otterGIF from '../gifs/otter.gif'
18+
19+
const AboutPage = () => (
20+
return (
21+
<Layout>
22+
<img src={otterGIF} alt="Otter dancing with a fish" />
23+
</Layout>
24+
)
25+
)
26+
27+
export default AboutPage;
28+
```
29+
30+
## Including GIFs in Markdown
31+
32+
In Markdown posts and pages, including an animated GIF is the same as a static image:
33+
34+
```markdown
35+
![otter dancing with a fish](./images/dancing-ofter.gif)
36+
```
37+
38+
![otter dancing with a fish](./images/dancing-otter.gif)
39+
40+
Animated GIFs can be quite large in size, however, so be careful not to sabotage your webpages' performance with extremely large files. You could reduce file size by [optimizing the frames](https://skylilies.livejournal.com/244378.html) or converting them to video.
41+
42+
> Note: beware that flashing and autoplaying GIFs can cause accessibility problems. One technique would be to add controls, such as using a package like [react-gif-player](https://www.npmjs.com/package/react-gif-player).

docs/docs/working-with-images.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,10 @@ export const query = graphql`
9090
}
9191
`
9292
```
93+
94+
### Additional resources
95+
96+
- [Gatsby Image API docs](/docs/gatsby-image/)
97+
- [gatsby-image plugin README file](/packages/gatsby-image/)
98+
- [gatsby-plugin-sharp README file](/packages/gatsby-plugin-sharp/)
99+
- [gatsby-transformer-sharp README file](/packages/gatsby-transformer-sharp/)

0 commit comments

Comments
 (0)