3

I am using the ablog sphinx extension for generating a blog website. I opened issue 66 that I have now discovered an answer for. Since the issue/answer has broader applicability to sphinx in general, I thought I would ask (and answer) here on SO.

How can I get pages that have the same content as the html_sidebars tagcloud.html, categories.html, and archives.html? I know that each one has their corresponding generated page, but what I would like is a page that has the same summary content as is placed in the sidebar. I believe that doing so would be a simple exercise with sphinx customization and templating, which is a big reason why I like ablog--skills I learn for the blogging engine will equally apply for my core sphinx usage.

Phil
  • 5,822
  • 2
  • 31
  • 60

1 Answers1

2

A Page with the Contents of an ABlog Sidebar

I wanted to use the sphinx RTD Theme (demo) for my ablog based website. This was fairly easy to do. One problem that I had with using a theme different than the default alabaster theme was getting the sidebar contents to look good or to be present at all. When I used the bootstrap theme (demo), there are some differences between it and the alabaster theme that made my blog look not quite right. When I used the RTD theme, the pages looked good but the RTD theme dedicates the sidebar to the non-customizable RTD table of contents. So I was down to three choices:

1) live with the alabaster theme, which has all of the right ablog contents, but I really dislike the italic looking font for all of the body content 2) use the bootstrap theme, which overall looks good but the sidebar was not quite right 3) use the RTD theme, which looks great but does not have a sidebar with conventional blog content such as a tag cloud, list of categories, or archive list by year, all of which are available in the html sidebar.

I posted issue 66 with the ablog project. Before it was answered, I came across a stack overflow question/answer: Override html page template for a specific sphinx document. The approach provided in the answer to this question seems to satisfy my needs.

I use a custom _templates/page.html that applies special logic with contents from _templates/sidebar_page.html when it is used for the page named pages/sidebar_page. Below are the contents of the three files:

_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.

These changes seem to fully address the issue. I am now able to use the RTD theme and still have a custom page that has the normal blog overview information.

Community
  • 1
  • 1
Phil
  • 5,822
  • 2
  • 31
  • 60