首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gatsby.js站点上的图像不会显示在GitHub页面上

Gatsby.js站点上的图像不会显示在GitHub页面上
EN

Stack Overflow用户
提问于 2020-10-27 01:10:43
回答 1查看 434关注 0票数 1

我有困难获得图像显示在github页面上。我正在使用一个基于存储库的页面。我在JSX中添加了一个简单的img标记,并尝试使用Gatsby文档中描述的方法。我觉得我漏掉了一些显而易见的东西。

这是代码

代码语言:javascript
复制
import React, { useContext } from 'react';
import AnchorLink from 'react-anchor-link-smooth-scroll';
import { ThemeContext } from 'providers/ThemeProvider';
import { Header } from 'components/theme';
import { Container, Button } from 'components/common';
import dev from 'assets/illustrations/dev.svg';
import { Wrapper, IntroWrapper, Details, Thumbnail } from './styles';
import { withPrefix } from 'gatsby'

import HeadShotPlaceHolder from 'assets/images/HeadShotPlaceHolder.jpeg'

export const Intro = () => {
  const { theme } = useContext(ThemeContext);

  console.log(HeadShotPlaceHolder)

  return (
    <Wrapper>
      <Header />
      <IntroWrapper as={Container}>
        <Details theme={theme}>
          {/* <h1>Hi There!</h1> */}
          <h1>Pamela Welch</h1>
          {/* <h4>I’m John and I’m a JAMStack engineer!</h4> */}
          <h4>A proven professional with extensive experience in all facets of communication and marketing.</h4>
          <Button as={AnchorLink} href="#contact">
            Hire me
          </Button>
        </Details>
        <Thumbnail>
          
          {/* This is where the image tag giving me the problem is */}
          <img src={ withPrefix(HeadShotPlaceHolder) } alt="I’m John and I’m a JAMStack engineer!" />

        </Thumbnail>
      </IntroWrapper>
    </Wrapper>
  );
};

这是结果

图像链路断裂

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-27 05:45:06

您的代码看起来很好,您的图像有其路径前缀。但是,要使其有效,您需要在部署命令中运行以下代码段:

代码语言:javascript
复制
{
  "scripts": {
    "deploy": "gatsby build --prefix-paths && gh-pages -d public"
  }
}

注意--prefix-paths标志。

盖茨比如何在GitHub页面中工作。中的更多信息

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64547040

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档