2024-07-19 08:20:48 +01:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
from sphinx.util.fileutil import copy_asset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _copy_asset_overwrite_hook(app):
|
|
|
|
|
css = app.outdir / '_static' / 'custom-styles.css'
|
|
|
|
|
# html_static_path is copied by default
|
2024-07-20 15:31:53 +02:00
|
|
|
assert css.read_text() == '/* html_static_path */\n', 'invalid default text'
|
2024-07-19 08:20:48 +01:00
|
|
|
# warning generated by here
|
|
|
|
|
copy_asset(
|
|
|
|
|
Path(__file__).parent.joinpath('myext_static', 'custom-styles.css'),
|
|
|
|
|
app.outdir / '_static',
|
|
|
|
|
)
|
2024-07-22 16:00:16 +01:00
|
|
|
# This demonstrates that no overwriting occurs
|
|
|
|
|
assert css.read_text() == '/* html_static_path */\n', 'file overwritten!'
|
2024-07-19 08:20:48 +01:00
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setup(app):
|
|
|
|
|
app.connect('html-collect-pages', _copy_asset_overwrite_hook)
|
|
|
|
|
app.add_css_file('custom-styles.css')
|