CSS files in _static not updated consistently

307 views
Skip to first unread message

KDMortimer

unread,
Feb 4, 2019, 9:27:00 AM2/4/19
to sphinx-users
Hi there,

I am using Sphinx 1.8.2 within a Canopy environment (running Python 3.5.2) and the readthedocs theme. I am trying to add custom styling using CSS to my HTML output using a file custom.css inside a _static folder and the make html command. I am able to get custom styles, but when I make changes to the CSS, they do not get propagated through to the output _build folder. (Seemingly related to known Sphinx issue 2090).

In my attempt to fix this problem, I have tried multiple variations on importing CSS which I found through various sources (e.g., StackExchange)... I have added the following to my conf.py, which combines two methods of importing CSS:

html_static_path = ['_static']
html_context
= {
   
'css_files': ['custom.css'],
}
def setup(app):
    app
.add_stylesheet('custom.css')

I have also added two _templates files, page.html:

{% extends "!page.html" %}
{% set css_files = css_files + ["_static/custom.css"] %}

as well as layout.html:

{# layout.html #}
{# Import the theme's layout. #}
{% extends "!layout.html" %}
{% set css_files = css_files + ['_static/style.css'] %}

However, custom.css only seems to be updated to the output folder when I make changes to conf.py (or presumably the .rst file - I'm not editing my rst at this time, so I am unsure about this) - as tested by making large obvious colour changes to certain elements and comparing custom.css files.

Obviously a workaround is to update the output CSS manually, but it would be nice to understand why this is not working.

Jonathan Gossage

unread,
Feb 4, 2019, 11:13:52 AM2/4/19
to sphinx...@googlegroups.com
What I do is to make a reversible change to one of the .rst documents. This makes the project seem to be dirty. The CSS comes along for the ride when Sphinx Build constructs new output. To my mind this is a definite bug in the Sphinx Build utility.

--
You received this message because you are subscribed to the Google Groups "sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
To post to this group, send email to sphinx...@googlegroups.com.
Visit this group at https://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/d/optout.

Komiya Takeshi

unread,
Feb 6, 2019, 9:55:48 AM2/6/19
to sphinx...@googlegroups.com
Hi,

I'm sorry. I misunderstood your comment on the issue. This is same as #2090.
At present, Sphinx does not check the timestamp of asset files. So
updating CSS file does not cause rebuild.
As a workaround, you need to update timestamp of .rst file or conf.py
to let Sphinx know the document updates.

Note:
* `html_context['css_files'] is overrided by HTML builder. So it's
meaningless setting.
* Using template variable `css_files` is not recommended. Please
insert `<script>` tag manually into your template.

Thanks,
Takeshi KOMIYA

2019年2月4日(月) 23:27 KDMortimer <kimdmo...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages