-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(docs): improve Gatsby Image docs #13170
Changes from 3 commits
e592d83
1cb4767
925243a
1441fc0
1f16fdb
fd6c405
b823da5
9c086a4
00f2ee0
9c5f727
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
--- | ||
title: Images, Video, and Files | ||
title: Images, Files, and Video | ||
overview: true | ||
--- | ||
|
||
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 in Gatsby projects. | ||
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. | ||
|
||
[[guidelist]] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,25 +17,14 @@ You can create a folder named `static` at the root of your project. Every file y | |
|
||
### Referencing your static asset | ||
|
||
In order to reference assets from the `static` folder in your code, you'll need to [import the `withPrefix` helper function from `gatsby`](/docs/gatsby-link/#prefixed-paths-helper): | ||
You can reference assets from the `static` folder in your code without anything special required: | ||
|
||
```js | ||
import { withPrefix } from 'gatsby' | ||
|
||
render() { | ||
// Note: this is an escape hatch and should be used sparingly! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ist this note still valid? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or why we describing an escape hatch instead of an "normal import" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The language here is subjective, I chose to keep it in to describe it as something you should try to avoid rather than painting imports as "more normal" (normal usually isn't the correct word, as it means something different to everyone) |
||
// Normally we recommend using `import` for getting asset URLs | ||
// as described in the “Adding Images, Fonts, and Files” page. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember this page removed by this pull request? Should we add an link to an replacing page in normal text There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return <img src={withPrefix('/img/logo.png')} alt="Logo" />; | ||
} | ||
``` | ||
|
||
And make sure you [set `pathPrefix` in your gatsby-config.js](/docs/path-prefix/): | ||
|
||
```javascript:title=gatsby-config.js | ||
module.exports = { | ||
// Note: it must *not* have a trailing slash. | ||
pathPrefix: `/img`, | ||
return <img src={'logo.png'} alt="Logo" />; | ||
} | ||
``` | ||
|
||
|
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.
maybe add a link to package gatsby-source-filesystem in the following paragraph...