lektor - 在主页上显示最近的博客事件

标签 lektor

使用 Lektor,尝试确定如何在主登陆(根)页面上按发布日期列出最近的三个博客。我觉得我应该使用宏,但我不明白如何将博客传递到页面模板,或者这是否是流程 block 的示例?我已在 page.ini 中添加了如下所示的部分:

[children]
model = blog-post
order_by = -pub_date, title

但似乎无法在模板中循环它们(没有抛出错误但不迭代)。完全迷失了,但仍在消耗文档。

最佳答案

我最终使用了 site.query直接在布局模板中提供类功能(基于博客快速入门)。

{% for blogpost in site.query('/blog').order_by('pub_date').limit(3) %}
    <div class="post col-md-4">
        <div class="post-details">
          <div class="post-meta d-flex justify-content-between">
            <div class="date">{{ blogpost.pub_date }}</div>
          </div><a href="post.html"> <!-- fix this one shortly -->
            <h3 class="h4">{{ blogpost.title }}</h3></a>
          <p class="text-muted">{{ blogpost.teaser }}</p>
        </div>
    </div>
{% endfor %}

关于lektor - 在主页上显示最近的博客事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51092740/

相关文章:

lektor - 如何在第一页而不是在 "/blog"中显示我的帖子并保持其他子文件夹像 "/about"和 "/projects"一样工作

python - 在 Windows 上运行 "lektor server"命令时出现问题

lektor - 更改 lektor 的 URL 结构,使博客文章位于父目录中

travis-ci - 使用 Travis CI 将 Lektor 站点部署到 Github Pages 时出错

python - Lektor 分页 - TemplateSyntaxError : Encountered unknown tag 'endblock'

python - Lektor 中的本地化/翻译路径

python - 如何在 Docker 容器中运行 Lektor?