gpt4 book ai didi

go - 雨果相当于PHP的strpos()

转载 作者:行者123 更新时间:2023-12-01 22:26:19 27 4
gpt4 key购买 nike

因此,我想将.Content分解为适合不同的导航标签。如果有更好的模式可以完成,请告诉我。

因此,在我的/content/shop/product-name/index.md前面,问题包含:

# summary
summary: "This is the **product's** summary which will render markdown"
---
This is the first line of the full description of the product. This section of the ./index.md
page is referenced in the `single.html` file as `.Content`.|^^|This is the next part of the
.Content that I want to throw into a different nav-tab.

然后在 /layouts/shop/single.html中:
   <div class="row">
<div class="col-lg-12">
{{ .Params.summary }}
</div>
</div>
<div class="row">
<div class="col-lg-12">
<nav class="product-info-tabs wc-tabs mt-5 mb-5">
<div class="nav nav-tabs nav-fill" id="nav-tab" role="tablist">
<a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab"
aria-controls="nav-home" aria-selected="true">Description</a>
<a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab"
aria-controls="nav-profile" aria-selected="false">Additional Information</a>
<a class="nav-item nav-link" id="nav-contact-tab" data-toggle="tab" href="#nav-contact" role="tab"
aria-controls="nav-contact" aria-selected="false">Reviews</a>
</div>
</nav>

<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
{{ .Content }}
</div>
...

在过去的日子里,在PHP中,我可以使用 strpos(.Content, '|^^|')然后使用 substr(.Content, 0, (strpos(.Content, '|^^|'))来获取一段文本。您还可以使用用户配置的分隔符 split('|^^|', .Content)将字符串放入数组中。

因此,回到Hugo,在 .Content中,我可能会遇到类似以下情况:
This is the content. This is the last line before being split.|^^|This is the next line, that would be in array[1] or the next indexed substr.

我正在尝试将 .Content的这两部分放入 single.html页的不同选项卡中。每个产品的 .Content显然都将有所不同,因此使用Hugo的 substr()的数量我确实无法保持一致。

我看到的使用前件的问题是,尽管它是markdown呈现的,但它不能跨越多行。我知道我可以将 \n用于换行符,但是这抵消了markdown的好处。

谢谢。

最佳答案

听起来您可能可以这样做:

{{ replace .Content "|^^|" "</div><div class='tab-pane fade show'>" | safeHTML}}

哪个会变成
      <div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
This is the content. This is the last line before being split.|^^|This is the next line, that would be in array[1] or the next indexed substr.
</div>

进入
      <div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
This is the content. This is the last line before being split.
</div>
<div class='tab-pane fade show'>
This is the next line, that would be in array[1] or the next indexed substr.
</div>

关于go - 雨果相当于PHP的strpos(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59779326/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com