Skip to content

Theme support for partial overwriting Ablog templates is maybe broken #294

@liborjelinek

Description

@liborjelinek

Describe the bug

I am trying to use recent template rework for overwriting ablog/postcard.html only but keep the rest of Ablog templates. However, I can't find out the way to manage it. Is there some known theme which ships their Ablog templates? Maybe it would help me.

To Reproduce

However, I suspect that this template rework is broken.

  1. Because I want to "hide" only some Ablog templates, I don't set skip_injecting_base_ablog_templates = True.
  2. Under my theme folder, I created ablog/postcard.html
  3. In my theme.toml I added
    [ablog]
    inject_templates_after_theme = true
    
  4. My theme's ablog/postcard.html is never used.

There is at least one reason why not. Consider the relevant excerpt from Ablog:

    try:
        after_theme = theme.get_config("ablog", "inject_templates_after_theme", False)
    except ThemeError:
        after_theme = False
    if after_theme:
        loaders.append(SphinxFileSystemLoader(get_html_templates_path()))
    else:
        loaders.insert(templatepathlen, SphinxFileSystemLoader(get_html_templates_path()))

The theme.get_config("ablog", "inject_templates_after_theme", False) call raises ThemeError exception with message Theme configuration sections other than [theme] and [options] are not supported.

This exception is incorrectly interpreted as missing default value and code flow went to else block.

But as the message said, the Sphinx's Theme.get_config() doesn't allow reading custom sections like [ablog] from theme.toml files. Unfortunately in such case, it raises ThemeError too.

(Excerpt from Theme.get_config():)

           msg = __(
                'Theme configuration sections other than [theme] and [options] '
                'are not supported (tried to get a value from %r).'
            )
            raise ThemeError(msg)

Screenshots

No response

System Details

Sphinx==8.1.2
ablog==0.11.11

Installation method

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions