我使用gatsby-remark-interactive-gifs plugin 在我的 gatsby 博客上显示 gif。
- 安装
gatsby-remark-interactive-gifs
npm install --save gatsby-remark-interactive-gifs
添加 gatsby-remark-interactive-gifs
- 将此配置添加到
gatsby-config.js:
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
{
resolve: `gatsby-remark-interactive-gifs`,
options: {
root: `${__dirname}`,
src: `${__dirname}/content/gif`,
dest: `${__dirname}/public/static/gifs`,
play: `${__dirname}/src/img/play.gif`,
placeholder: `${__dirname}/src/img/play.gif`,
loading: `${__dirname}/src/img/play.gif`,
relativePath: `/static/gifs`,
},
},
],
},
},
From plugin document:
root - The root of your project.
src - Where all the gifs you want processed are stored. Absolute path.
dest - A path in public where your gifs are stored. Absolute path.
play - An image to indicate that the gif can be interacted with. Absolute path.
placeholder - An image to show when the gif is missing in action. Absolute path.
loading - An image which shows when the gif is downloading. Absolute path.
relativePath - The relative path served from public/.
!确保将其添加到 prismjs 配置之上。
- MD 文件中的示例代码,用于在您的 gatsby 博客上显示 gif:
<img src="/static/gifs/fileName.gif">