Support themes generically
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- python
- Domain
- documentation
Research direction
Start with the prototype in PR #324, ablog's src/ablog/templates/page.html, and the theme-related settings in conf.py. Read Sphinx's jinja2glue.py and compare the page.html inheritance and content/body blocks in alabaster, furo, shibuya, and pydata-sphinx-theme. Done means a generic theme approach preserves ablog features across these inheritance patterns without theme-specific case-by-case support.
Written by the indexing model from the issue text.
Description
Describe the feature
Hi ablog developers,
This issue is a bit long, so please feel free to read it when you have time ☕ .
Related: #310, #108
Goal
Discuss a generic approach for supporting Sphinx themes in ablog, instead of adding theme-specific support on a case-by-case basis.
Current situation and key points
- ablog provides its own
page.htmltemplate, but it does not coexist well withpage.htmlprovided by external themes. - By default, ablog’s
page.htmltakes precedence over the theme’s template. - When
skip_injecting_base_ablog_templateis enabled inconf.py, ablog’spage.htmlis not used. - When the theme option
ablog_inject_templates_after_themeis enabled, the theme’s templates take precedence. - Using the theme’s templates usually resolves layout issues, but some features provided by ablog are no longer rendered as HTML (this is a trade-off):
- Links to RSS/Atom feeds
- Link to Font Awesome CSS
- Previous/next post navigation
- Disqus comment section
Possible approach
To avoid this trade-off, one possible approach is to extend the theme’s templates from ablog’s templates, and inject ablog-specific elements there.
This approach is already used in the Pull Request #310:
Regarding the use of a theme name as a prefix:
Sphinx adds both the theme directory and its parent directory to the template search paths, which allows templates to be referenced with a theme-name prefix.
Although I have not fully traced the original motivation, this mechanism likely exists to avoid infinite loops when using extends "page.html" inside page.html itself.
Relevant code in Sphinx:
One important caveat is that themes can have inheritance relationships.
Even if a_theme/page.html does not exist, parent_theme/page.html may exist and be used for rendering.
Therefore, when deciding which template ablog’s page.html should extend, it may be necessary to traverse the theme inheritance chain.
Another challenge: content blocks
Another challenge for generalization is that the Jinja2 block that contains the main content (the HTML converted from reST or Markdown, stored in the body variable) differs between themes.
For ablog’s previous/next post navigation and the Disqus comment section, these elements need to be placed after the article content. However, the appropriate block differs depending on the theme.
alabaster (basic)
{{ body }}is placed inside the{% block body %}- The
{% block content %}wraps the{% block body %}
furo
{{ body }}is placed inside the{% block content %}- The
{% block body %}wraps the{% block content %}
shibuya
{{ body }}is placed inside the{% block content %}- The
{% block body %}wraps the{% block content %}
pydata-sphinx-theme
{{ body }}is placed inside the{% block body %}- This theme does not provide
page.html, sobasic/page.htmlis used via inheritance
- This theme does not provide
- As with
basic, the{% block content %}wraps the{% block body %}
Proposed solution
Prototype implementation
At least for the themes listed above, it seems sufficient to control whether the comment section is inserted into the content block or the body block.
As a prototype, I implemented an approach that adds a theme-specific setting theme_content_block in conf.py to select one of the two.
The code diff is available here:
PR: https://github.com/sunpy/ablog/pull/324
And the ablog documentation built with different themes can be found below:
- furo: https://ykrods.github.io/ablog/furo/
- shibuya: https://ykrods.github.io/ablog/shibuya/
- pydata-sphinx-theme: https://ykrods.github.io/ablog/pydata-sphinx-theme/
- Dominant language
- Python
- Stars
- 196
- Forks
- 64
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sunpy/ablog
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100