-
Notifications
You must be signed in to change notification settings - Fork 13
[Update] Support Page Sections & Sphinx Domains #19
Changes from 1 commit
e24214d
8b56cee
3cdedc7
a477e9c
eecb619
03f1808
2173fc4
66d8861
31f142f
abf809c
c115c52
24c84f5
156a8b9
d533cfc
73f3b4b
2d9763b
1e39d47
e4796a7
6e869e2
a789e81
604204b
4a48c8a
7ed4096
84fc171
5119812
85d082d
8dce55e
c735b75
047a438
d8c9d46
40fef13
ab1dbbb
2957f9a
7c1dfcf
dbddbd4
bf7dfec
ed8764e
75a0cd9
46a383b
2746b35
b164cb2
ffa8bc3
a79e44d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
prune common | ||
include LICENSE | ||
include sphinx_search/_static/js/rtd_sphinx_search.js | ||
include sphinx_search/_static/js/rtd_sphinx_search.min.js | ||
include sphinx_search/_static/css/rtd_sphinx_search.css | ||
include sphinx_search/_static/css/rtd_sphinx_search.min.css |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,43 @@ | ||
import os | ||
|
||
from sphinx.util.fileutil import copy_asset | ||
|
||
|
||
CUSTOM_ASSETS_FILES = [ | ||
os.path.join('js', 'rtd_sphinx_search.min.js'), | ||
os.path.join('css', 'rtd_sphinx_search.min.css'), | ||
] | ||
CUSTOM_ASSETS_FILES = { | ||
'MINIFIED': [ | ||
os.path.join('js', 'rtd_sphinx_search.min.js'), | ||
os.path.join('css', 'rtd_sphinx_search.min.css'), | ||
], | ||
'UN_MINIFIED': [ | ||
os.path.join('js', 'rtd_sphinx_search.js'), | ||
os.path.join('css', 'rtd_sphinx_search.css'), | ||
] | ||
} | ||
|
||
|
||
def copy_asset_files(app, exception): | ||
if exception is None: # build succeeded | ||
for f in CUSTOM_ASSETS_FILES: | ||
path = os.path.join(os.path.dirname(__file__), '_static', f) | ||
copy_asset(path, os.path.join(app.outdir, '_static', f.split('.')[-1])) | ||
files = CUSTOM_ASSETS_FILES['MINIFIED'] + CUSTOM_ASSETS_FILES['UN_MINIFIED'] | ||
for file in files: | ||
path = os.path.join(os.path.dirname(__file__), '_static', file) | ||
copy_asset(path, os.path.join(app.outdir, '_static', file.split('.')[-1])) | ||
|
||
|
||
def setup(app): | ||
def inject_static_files(app): | ||
"""Inject correct CSS and JS files based on the value of ``RTD_SPHINX_SEARCH_FILE_TYPE``.""" | ||
file_type = app.config.RTD_SPHINX_SEARCH_FILE_TYPE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should check the incoming value for being one of the two we expect, and give users a good error if not. |
||
files = CUSTOM_ASSETS_FILES[file_type] | ||
|
||
app.connect('build-finished', copy_asset_files) | ||
|
||
for file in CUSTOM_ASSETS_FILES: | ||
if file.endswith('.min.js'): | ||
for file in files: | ||
if file.endswith('.js'): | ||
app.add_js_file(file) | ||
if file.endswith('.min.css'): | ||
elif file.endswith('.css'): | ||
app.add_css_file(file) | ||
|
||
|
||
def setup(app): | ||
|
||
app.add_config_value('RTD_SPHINX_SEARCH_FILE_TYPE', 'UN_MINIFIED', 'html') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe Sphinx uses lower-case config values by convention. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also should be documented. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the documentation changes be done in another PR (the one with the API reference)? |
||
|
||
app.connect('builder-inited', inject_static_files) | ||
app.connect('build-finished', copy_asset_files) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should also be lowercase.