【发布时间】:2019-06-27 19:20:18
【问题描述】:
在 Jekyll 的帖子中,我看到了如何用 include.content | number_of_words 计算字数,但我想知道是否有办法计算内容中的图片?
我知道有一种方法可以获得特色图片,如果我将它添加到 frontmatter 中,例如:
feature-img: "img/foobar.png"
根据我的搜索,我确实看到了post.layout,但我无法找到是否有办法获取帖子内容中的图像数量。当我搜索以查看是否有人问过这个问题或有人在 Jekyll 问题中提出了这个问题时,我唯一没有得到任何结果,但我已经阅读:
- Is there a way to access rendered content in Jekyll?
- How to retrieve the current post index number in Jekyll?
- How to include all files in a folder in Jekyll?
我可以看看我是否要为帖子创建一个画廊,将图像添加到 frontmatter 中,例如:
---
layout: post
title: "This is a title"
images:
- url: "img/foo.png"
alt: "Enter the foo"
title: "apart of foo"
- url: "img/bar.png"
alt: "Enter the bar"
title: "apart of bar"
---
但图像分布在整个内容中。我想我可以将它硬编码到 frontmatter 中的每个帖子中,例如:
---
image-count: 4
---
但我认为这只会使前面的事情变得臃肿。在 Jekyll 中,有没有办法让帖子的图片动态计数?
【问题讨论】: