Gathering detailed insights and metrics for gatsby-remark-images-anywhere
Gathering detailed insights and metrics for gatsby-remark-images-anywhere
Gathering detailed insights and metrics for gatsby-remark-images-anywhere
Gathering detailed insights and metrics for gatsby-remark-images-anywhere
Handle images with relative, absolute & remote path for gatsby-transformer-remark & gatsby-plugin-mdx
npm install gatsby-remark-images-anywhere
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
22 Stars
51 Commits
8 Forks
3 Watchers
20 Branches
5 Contributors
Updated on May 12, 2023
Latest Version
1.3.1
Package Id
gatsby-remark-images-anywhere@1.3.1
Unpacked Size
19.30 kB
Size
6.89 kB
File Count
9
NPM Version
6.14.8
Node Version
14.10.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
3
Get image from anywhere in your markdown:
---
title: Hello World
---
# Regular relative path

# NetlifyCMS path

# Remote path

# Protocol relative path*

# Any of the above also works with <img />
<img src="./image.png" alt="hey" title="hello" />
gatsby-remark-images
is awesome. But if you use a CMS that paste remote url, or path that's not relative to the markdown file itself, it won't work. Originally this plugin was meant to find a way to feed remote images to gatsby-remark-images
, but that didn't work out. This is a simpler & more flexible image plugin supports.
loading
html attribute.sharp
fix
, fluid
, resize
)If you don't use remote images or CMS, just use gatsby-remark-images
If you're using vanilla NetlifyCMS, just use gatsby-remark-relative-images
.
If you need remote image, try this one out!
If you don't need remote images or CMS, but want more flexibility, try this one out.
See the whitelisted list here
1yarn add gatsby-remark-images-anywhere 2# or 3npm install gatsby-remark-images-anywhere
1//gatsby-config.js 2{ 3 resolve: `gatsby-transformer-remark`, 4 options: { 5 plugins: [ 6 `gatsby-remark-images-anywhere` 7 ], 8 }, 9}, 10
Your projects need to have...
1{ 2 resolve: `gatsby-remark-images-anywhere`, 3 options: { 4 /** 5 * @param {string} staticDir 6 * Root folder for images. For example, 7 * if your image path is `/assets/image.png`, 8 * your image is located in `static/assets/image.png`, 9 * then the staticDir is `static`. 10 * You can also point it to whichever else folder you have locally. 11 */ 12 staticDir: 'static', 13 14 /** 15 * @param {Function} createMarkup 16 * A function that return string template for image 17 * All sharp result will be passed in as arguments 18 */ 19 createMarkup: ({ src, srcSet }) => `<img src="${src}" srcSet="${srcSet}" class="hey" />` 20 21 /** 22 * @param {'lazy' | 'eager' | 'auto'} loading 23 * Set the output markup's 'loading' attribute. Default: 'lazy' 24 */ 25 loading: 'lazy', 26 27 /** 28 * @param {string} backgroundColor 29 * Background color. Default: '#fff' 30 */ 31 backgroundColor: '#fff', 32 33 /** 34 * @param {boolean} linkImagesToOriginal 35 * If enabled, wraps the default markup with an <a> tag pointing to the original image. 36 * Default: false 37 */ 38 linkImagesToOriginal: true, 39 40 /** 41 * @param {string | Function} wrapperStyle 42 * Inject styles to the image wrapper. 43 * Also accept a function that receives all image data as arguments, i.e 44 * ({ aspectRatio, width, height }) => `padding-bottom: ${height/2}px;` 45 * Alternatively you can also attach additional class to `.gria-image-wrapper` 46 */ 47 wrapperStyle: 'padding-bottom: 0.5rem;', 48 49 /** 50 * @param {'fluid' | 'fixed' | 'resize'} sharpMethod 51 * Default: 'fluid'. 52 */ 53 sharpMethod: 'fluid', 54 55 /** 56 * ...imageOptions 57 * and any sharp image arguments (quality, maxWidth, etc.) 58 */ 59 maxWidth: 650, 60 quality: 50, 61 } 62}
Here's the createMarkup
signature:
1type CreateMarkup = (args: CreateMarkupArgs, options?: MarkupOptions) => string; 2 3interface CreateMarkupArgs { 4 sharpMethod: SharpMethod; 5 originSrc: string; 6 title?: string; 7 alt?: string; 8 9 aspectRatio: number; 10 src: string; 11 srcSet?: string; 12 srcWebp?: string; 13 srcSetWebp?: string; 14 base64?: string; 15 tracedSVG?: string; 16 17 // fixed, resize 18 width?: number; 19 height?: number; 20 21 // fluid 22 presentationHeight?: number; 23 presentationWidth?: number; 24 sizes?: string; 25 originalImg?: string; 26} 27 28interface MarkupOptions { 29 loading: 'lazy' | 'eager' | 'auto'; 30 linkImagesToOriginal: boolean; 31 showCaptions: boolean; 32 wrapperStyle: string | Function; 33 backgroundColor: string; 34 tracedSVG: boolean | Object; 35 blurUp: boolean; 36}
gatsby-transformer-remark
custom component to achieve gatsby-image
-like benefits (blur up, lazy loading, aspect-ratio).No vulnerabilities found.
No security vulnerabilities found.