如何获得带有侧边栏内容的博客 sphinx 页面

How to get an ablog sphinx page with sidebar contents

我正在使用 ablog sphinx 扩展来生成博客网站。我打开了 issue 66,我现在已经找到了答案。由于 issue/answer 通常对狮身人面像具有更广泛的适用性,我想我会在这里问(并回答)SO。

如何获取与 html_sidebars、tagcloud.htmlcategories.htmlarchives.html 具有相同内容的页面?我知道每个都有相应的生成页面,但我想要的是一个与侧边栏中的摘要内容相同的页面。我相信这样做将是一个简单的 sphinx 自定义和模板练习,这是我喜欢 ablog 的一个重要原因——我为博客引擎学习的技能同样适用于我的核心 sphinx 使用。

包含 ABlog 边栏内容的页面

我想使用 sphinx RTD 主题 (demo) 我的 ablog 基于网站。这很容易 去做。我在使用不同于 默认 alabaster theme 是 使侧边栏内容看起来不错或完全存在。什么时候 我用了 bootstrap 主题 (demo), 它与制作的雪花石膏主题之间存在一些差异 我的博客看起来不太对劲。当我使用 RTD 主题时,页面 看起来不错,但 RTD 主题将边栏专用于 不可自定义的 RTD table 内容。所以我只有三个选择:

1) 使用雪花石膏主题,它拥有所有正确的博客 内容,但我真的不喜欢所有内容的斜体字体 正文内容 2) 使用 bootstrap 主题,整体看起来不错,但侧边栏 不太对 3)使用RTD主题,看起来不错但是没有侧边栏 与传统的博客内容,如标签云,列表 类别,或按年份归档的列表,所有这些都可以在 html 边栏。

我发布了 issue 66 博客项目。在回答之前,我遇到了堆栈溢出 question/answer: 覆盖特定 sphinx 的 html 页面模板 文档。 中提供的方法 answer 这个问题 好像能满足我的需求。

我使用自定义 _templates/page.html 应用特殊逻辑 来自 _templates/sidebar_page.html 的内容用于 名为 pages/sidebar_page 的页面。下面是三篇的内容 文件:

_templates/page.html

{% extends "layout.html" %}
{% block body %}
    {% if pagename == 'pages/sidebar_page' %}
        {% include 'sidebar_page.html' %}
    {% else %}
        {{ body }}
        <hr></hr>
        {% include 'postcard.html' %}
        <p></p>
    {% endif %}
{% endblock %}

_templates/sidebar_page.html

{% block body %}
<!-- {% include 'searchbox.html' %} -->
{% include 'about.html' %}
{{ body }}
{% include 'tagcloud.html' %}
    <p></p>
{% include 'recentposts.html' %}
    <p></p>
{% include 'categories.html' %}
    <p></p>
{% include 'archives.html' %}
    <p></p>
{% include 'authors.html' %}
{% endblock %}

pages/sidebar_page.rst

.. _sidebar_page:

********************
 Blog Overview |rss|
********************

This is my overview of the blog.

这些更改似乎完全解决了这个问题。我现在可以使用 RTD 主题,并且仍然有一个包含正常博客概述的自定义页面 信息。