使用 Gatsby,我的网站图片未从 Github 页面上的正确 link 加载
My website images are not loading from the correct link on Github Pages with Gatsby
该站点是在 Github 页面上部署 Gastby 构建的。我的图像 link 应该像 https://eoja82.github.io/lakeside-demo/img/employees/jake.jpg
。但是,link 类似于 https://eoja82.github.io/img/employees/jake.jpg
,省略了 /lakeside-demo 部分。
我在我的 gastby-config.js 文件中使用 pathPrefix
:
module.exports = {
pathPrefix: "/lakeside-demo",
plugins: [
`gatsby-plugin-react-helmet`,
`gatsby-transformer-json`,
{
resolve: `gatsby-source-filesystem`,
options: {
path: `./src/components/products/data/`
}
},
]
}
我的 package.json 文件中有以下脚本:
"deploy": "gatsby build --prefix-paths && gh-pages -d public"
我试过使用 Gatsby 的 withPrefix
和 assetPrefix
但无法想出任何可行的解决方案。
Github: https://github.com/eoja82/lakeside-demo
网站:https://eoja82.github.io/lakeside-demo/
如有任何建议,我们将不胜感激!
withPrefix
像这样使用应该有效:
<img className={styles.moreInfoImg} src={withPrefix("/img/loadedTruck.jpg")} alt="delivery truck" />
该站点是在 Github 页面上部署 Gastby 构建的。我的图像 link 应该像 https://eoja82.github.io/lakeside-demo/img/employees/jake.jpg
。但是,link 类似于 https://eoja82.github.io/img/employees/jake.jpg
,省略了 /lakeside-demo 部分。
我在我的 gastby-config.js 文件中使用 pathPrefix
:
module.exports = {
pathPrefix: "/lakeside-demo",
plugins: [
`gatsby-plugin-react-helmet`,
`gatsby-transformer-json`,
{
resolve: `gatsby-source-filesystem`,
options: {
path: `./src/components/products/data/`
}
},
]
}
我的 package.json 文件中有以下脚本:
"deploy": "gatsby build --prefix-paths && gh-pages -d public"
我试过使用 Gatsby 的 withPrefix
和 assetPrefix
但无法想出任何可行的解决方案。
Github: https://github.com/eoja82/lakeside-demo
网站:https://eoja82.github.io/lakeside-demo/
如有任何建议,我们将不胜感激!
withPrefix
像这样使用应该有效:
<img className={styles.moreInfoImg} src={withPrefix("/img/loadedTruck.jpg")} alt="delivery truck" />