【问题标题】:How to not display images in Pelican article summaries?如何不在 Pelican 文章摘要中显示图像?
【发布时间】:2017-08-30 04:47:07
【问题描述】:
如果一篇文章的元数据部分没有明确的“摘要”,则在使用 {{ article.summary }} 时,Pelican 将默认输出 50 个单词 (SUMMARY_MAX_LENGTH = 50)。如果一篇文章的开头包含一张大图(就尺寸而言),那么该大图将包含在文章摘要中。
当使用{{ article.summary }} 的目的是防止文章占用过多空间时,此行为可能会出现问题,尤其是在列出所有文章的站点索引页面上使用时。
有没有办法防止在文章摘要中输出图片?
我正在使用 Pelican 3.7.1。
【问题讨论】:
标签:
python
python-3.x
pelican
【解决方案1】:
使用我的 Pelican 版本(带有 Pelican-bootstrap3 主题的 Pelicant 4.0.1),您可以简单地将图像在您的降价文章模板中使用 script 标签向下推:
title: title
slug: sluggy
category: stuff
date: 2019-02-12
modified: 2019-02-12
Just some article text with some **markdown** styling.
<script>
<!--
// This is pure filler that pelican wont execute but does consider when
// determining the size of the article in the homepage/index overview.
//-->
</script>
<img src="path/to/my/image.png">
More _markdown_ article text.
如果填充足够,图像将不会显示在索引/摘要中。
如果您想防止图像在您的摘要概览中间弹出,并且您不想使用“摘要”选项( 不太干燥),您可以执行以下操作:
title: title
slug: sluggy
category: stuff
date: 2019-02-12
modified: 2019-02-12
This is my article text about how I once altered an image, the result
was:
<span class="img_point_of_reference"></span>
and I write more text over here.
<script>
var my_image = document.createElement('IMG')
my_image.src = "./images/stuff/example_image.png"
var ref_point = document.getElementsByClassName("img_point_of_reference")[0]
ref_point.parentNode.insertBefore(my_image, ref_point)
</script>
最后的 Javascript 只会在文章完全加载时执行。