如何在主页的Hugo中添加图片?

问题描述 投票:0回答:1

我正在尝试在 _index.md 文件中的主页上显示照片

---
title: Home
---
**Title**  
Text is here

![flutter image](/images/home_flutter.png)

我在baseof.html文件中添加了hugo文档中的代码

<!doctype html>
<html>
<head>
    {{ partial "meta.html" . }}
    {{ $image := resources.Get "images/home_flutter.png" }}
</head>

<body>
    <header>{{partial "nav.html" . }}</header>
 {{ block "main" . }}
 
 {{ end }}
 {{ partial "footer.html" . }}
<footer>
</html>

照片位于 asset/images 文件夹中。

网页上的logo.svg 文件有效。在这段代码中:

<nav>
    <ul>
      <li><a href="/"><img src={{  (resources.GetMatch "images/logo.svg" | resources.ExecuteAsTemplate "logo.svg" "nothing").Permalink }} alt="logo", height="80em"></a></li>
      <li><a href="/">Home</a></li>
      <li><a href="/what_we_offer/">What We Offer</a></li>
      <li><a href="/who_we_are/">Who We Are</a></li>
      <li><a href="/contact/">Contact</a></li>
      <li><a href="/careers/">Careers</a></li>
    </ul>
   </nav>

我认为如果 logo.svg 以这种方式工作,那么 home_flutter.png 也应该可以工作。为了进行测试,我将其更改如下:

<li><a href="/"><img src={{  (resources.GetMatch "images/home_flutter.png" | resources.ExecuteAsTemplate "home_flutter.png" "nothing").Permalink }} alt="logo", height="80em"></a></li>

但它显示我错误:

Error: error building site: EXECUTE-AS-TEMPLATE: failed to transform "images/photo.png" (image/png): failed to parse Resource "images/home_flutter.png" as Template:: template: images/home_flutter.png:177: unrecognized character in action: U+FFFD '�'

如何解决这个问题?这段代码在baseof.html中的位置正确吗?

{{ $image := resources.Get "images/home_flutter.png" }}

提前致谢

go hugo
1个回答
0
投票

将图像放入静态文件夹而不是资产文件夹中,然后删除此:

{{ $image := resources.Get "images/home_flutter.png" }}
© www.soinside.com 2019 - 2024. All rights reserved.