雨果:第一段中断时结束内容摘要
我正在尝试从Jekyll迁移博客,我想将摘录/内容摘要保持不变。也就是说,我想在第一段中断时自动结束摘要。
I should be included in the content summary.
Still in summary.
This is no longer part of summary
文档似乎表明Hugo仅支持自动摘要按长度 。
是否有某种方法可以自动打破第一段中断的内容摘要?
I'm trying to migrate a blog from Jekyll, and I'd like to keep my excerpts/content summaries the same. That is, I'd like to automatically end the summary at the first paragraph break.
I should be included in the content summary.
Still in summary.
This is no longer part of summary
The docs seem to indicate that Hugo only supports automatic summaries by length.
Is there some way to automatically break the content summary on the first paragraph break?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是我的工作方式,基于Rogelio的答案:
上面的代码通过关闭
p
标记将整个文章的内容分配,检索结果数组的第一个元素,然后将其存储在<<代码> $摘要变量。该解决方案的关键在于:
&lt;/p&gt;
和不是打开&lt; p&gt;
标签来分裂内容。此时,
$汇总
包含以下代码:之后,我们可以输出摘要。只需确保使用
plainify
删除HTML,以摆脱未闭合的&lt; p&gt;
标签。This is how I got it working, based on Rogelio's answer:
The code above splits the content of the whole article by closing
p
tag, retrieves the first element of the resulting array, and stores it in the$summary
variable.The key to this solution resides in:
</p>
and not the opening<p>
tag.At this point,
$summary
contains this code:After that, we can output the summary. Just make sure to remove HTML using with
plainify
, to get rid of the unclosed<p>
tag.做一个短代码或部分 - 取决于您使用的位置。
使用.summary变量
使用拆分功能。
PSUEDO代码:
它将为您提供一个映射/切片/阵列的值。
因此,更多的psuedo代码:
等等。
Make a shortcode or partial - depending on where you are using it.
Use the .Summary variable
Use the Split function.
Psuedo-code:
Which will give you a map/slice/array of values.
So more psuedo code:
etc.
不,雨果比总结摘要更多。
可以通过多种方式指定摘要,并且在决定要返回的文本时,请理解选择雨果的顺序是有用的。如下:
文章中的变量, 。因此,例如,如果您的文章在其前提方面具有摘要变量,并且摘要分隔线将使用手动摘要方法。
确保两者之间没有空白。
或者
No, Hugo supports more than summaries by length.
There are multiple ways in which a summary can be specified and it is useful to understand the order of selection Hugo follows when deciding on the text to be returned by .Summary. It is as follows:
Hugo uses the first of the above steps that returns text. So if, for example, your article has both summary variable in its front matter and a summary divider Hugo will use the manual summary split method.
Make sure there are no blanks in between.
or