-
-
Notifications
You must be signed in to change notification settings - Fork 10k
feat(v2): @docusaurus/plugin-ideal-image #1665
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eeaaa15
chore(v2): tweak image opt before moving to docusaurus-plugin-image
endiliey c872021
lint
endiliey 35a743e
feat(v2): convert to docusaurus-plugin-ideal-image
endiliey a2f8b6b
tweak
endiliey 5870e2f
dont need many img
endiliey 55ff1f0
fix dev err
endiliey 47f1a53
tweak
endiliey 8278ea8
opt png
endiliey 2c2c5c6
lower qual
endiliey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,46 @@ | ||
| # `@docusaurus/plugin-ideal-image` | ||
|
|
||
| Docusaurus Plugin to generate an almost ideal image (responsive, lazy-loading, and low quality placeholder) | ||
|
|
||
| ## Installation | ||
|
|
||
| ```sh | ||
| yarn add @docusaurus/plugin-ideal-image | ||
| ``` | ||
|
|
||
| Modify your `docusaurus.config.js` | ||
|
|
||
| ```diff | ||
| module.exports = { | ||
| ... | ||
| + plugins: ['@docusaurus/plugin-ideal-image'], | ||
| ... | ||
| } | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| Support png, gif and jpg only | ||
|
|
||
| ```jsx | ||
| import Image from '@theme/IdealImage'; | ||
| import thumbnail from './path/to/img.png'; | ||
|
|
||
| // your react code | ||
| <Image img={thumbnail} /> | ||
|
|
||
| // or | ||
| <Image img={require('./path/to/img.png')} /> | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| | Option | Type | Default | Description | | ||
| |--------|------|---------|-------------| | ||
| | `name` | `string` | `ideal-img/[name].[hash:hex:7].[width].[ext]` | Filename template for output files. | | ||
| | `sizes` | `array` | *original size* | Specify all widths you want to use; if a specified size exceeds the original image's width, the latter will be used (i.e. images won't be scaled up). You may also declare a default `sizes` array in the loader options in your `webpack.config.js`. | | ||
| | `size` | `integer` | *original size* | Specify one width you want to use; if the specified size exceeds the original image's width, the latter will be used (i.e. images won't be scaled up) | | ||
| | `min` | `integer` | | As an alternative to manually specifying `sizes`, you can specify `min`, `max` and `steps`, and the sizes will be generated for you. | | ||
| | `max` | `integer` | | See `min` above | | ||
| | `steps` | `integer` |`4` | Configure the number of images generated between `min` and `max` (inclusive) | | ||
| | `quality` | `integer` | `85` | JPEG compression quality | |
This file contains hidden or 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,22 @@ | ||
| { | ||
| "name": "@docusaurus/plugin-ideal-image", | ||
| "version": "2.0.0-alpha.21", | ||
| "description": "Docusaurus Plugin to generate an almost ideal image (responsive, lazy-loading, and low quality placeholder)", | ||
| "main": "src/index.js", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "license": "MIT", | ||
| "dependencies": { | ||
| "react-waypoint": "8.1.0", | ||
| "@endiliey/responsive-loader": "^1.3.1", | ||
| "lqip-loader": "^2.2.0", | ||
| "sharp": "^0.22.1", | ||
| "react-ideal-image": "^0.0.5" | ||
| }, | ||
| "peerDependencies": { | ||
| "@docusaurus/core": "^2.0.0", | ||
| "react": "^16.8.4", | ||
| "react-dom": "^16.8.4" | ||
| } | ||
| } |
This file contains hidden or 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,45 @@ | ||
| /** | ||
| * Copyright (c) 2017-present, Facebook, Inc. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| const path = require('path'); | ||
|
|
||
| module.exports = function(context, options) { | ||
| const isProd = process.env.NODE_ENV === 'production'; | ||
| return { | ||
| name: 'docusaurus-plugin-ideal-image', | ||
|
|
||
| getThemePath() { | ||
| return path.resolve(__dirname, './theme'); | ||
| }, | ||
|
|
||
| configureWebpack(config, isServer) { | ||
| return { | ||
| module: { | ||
| rules: [ | ||
| { | ||
| test: /\.(png|jpe?g|gif)$/, | ||
| use: [ | ||
| 'lqip-loader', | ||
| { | ||
| loader: '@endiliey/responsive-loader', | ||
| options: { | ||
| emitFile: !isServer, // don't emit for server-side rendering | ||
| disable: !isProd, | ||
| // eslint-disable-next-line | ||
| adapter: require('@endiliey/responsive-loader/sharp'), | ||
| name: 'ideal-img/[name].[hash:hex:7].[width].[ext]', | ||
| ...options, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
| }, | ||
| }; | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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,7 +6,8 @@ | |
| */ | ||
|
|
||
| import React, {useEffect} from 'react'; | ||
| import Image from '@docusaurus/Image'; | ||
|
|
||
| import Image from '@theme/IdealImage'; | ||
| import Layout from '@theme/Layout'; | ||
|
|
||
| import classnames from 'classnames'; | ||
|
|
@@ -37,27 +38,27 @@ function Showcase() { | |
| <h1>{TITLE}</h1> | ||
| <p>{DESCRIPTION}</p> | ||
| </div> | ||
| {chunkArray(users, ITEMS_PER_ROW).map(row => ( | ||
| <div className="row margin-vert--lg"> | ||
| {chunkArray(users, ITEMS_PER_ROW).map((row, i) => ( | ||
| <div key={`row${i}`} className="row margin-vert--lg"> | ||
| {row.map(user => ( | ||
| <div className="col col--4"> | ||
| <div key={user.title} className="col col--4"> | ||
| <div className={classnames('card', styles.showcaseUser)}> | ||
| <div className="card__image"> | ||
| <Image img={user.preview} alt={user.title} /> | ||
| </div> | ||
| <div className="card__body"> | ||
| <div class="avatar"> | ||
| <div class="avatar__intro margin-left--none"> | ||
| <h4 class="avatar__name">{user.title}</h4> | ||
| <small class="avatar__subtitle"> | ||
| <div className="avatar"> | ||
|
Contributor
Author
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. fix class -> className |
||
| <div className="avatar__intro margin-left--none"> | ||
| <h4 className="avatar__name">{user.title}</h4> | ||
| <small className="avatar__subtitle"> | ||
| {user.description} | ||
| </small> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {(user.website || user.source) && ( | ||
| <div className="card__footer"> | ||
| <div class="button-group button-group--block"> | ||
| <div className="button-group button-group--block"> | ||
| {user.website && ( | ||
| <a | ||
| className="button button--small button--secondary button--block" | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
in case someone wonders the hardcoded 100 value.
This is just to not throw error in dev because height and weight is a required field for react-ideal-image
see https://github.com/endiliey/responsive-loader#options