Skip to content

Commit 8eb2db3

Browse files
aobo-yfacebook-github-bot
authored andcommitted
refactor website building process (#892)
Summary: - group all sphinx build non-html static resources (js, css) into `website/static/_sphinx` to differentiate from other resources used by our website - gitignore `website/static/_sphinx` but not other `js` `css` - remove [unnecessary rewriting](https://github.com/pytorch/captum/blob/34387f564b40f63f7ffa0ae5ced3828321d9a92e/scripts/parse_sphinx.py#L60-L67) of `_static/searchtools.js` in script `parse_sphinx.py` since `searchtools.js` from modern sphinx does not have such content, e.g., https://github.com/pytorch/captum/blob/gh-pages/js/searchtools.js - remove `website/static/_sphinx-sources/` which are not used in our website https://github.com/pytorch/captum/tree/gh-pages/_sphinx-sources - remove comitted `pygments.css` from website since sphinx will generate the file during building - remove erroneous manual css imports because docusaurus will auto [marge all css files](https://v1.docusaurus.io/docs/en/api-pages#styles) and use the merged file ![Screen Shot 2022-03-09 at 1 05 32 AM](https://user-images.githubusercontent.com/5113450/157382207-a0abdafc-bfdc-4537-bd97-153781ffc032.png) Pull Request resolved: #892 Reviewed By: vivekmig Differential Revision: D34757334 Pulled By: aobo-y fbshipit-source-id: 8d3dda46088329884db1b4d0e19a528009d9a739
1 parent c9ea380 commit 8eb2db3

File tree

6 files changed

+42
-113
lines changed

6 files changed

+42
-113
lines changed

.gitignore

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ website/pages/tutorials/*
109109

110110
## Generated for Sphinx
111111
website/pages/api/
112-
website/static/js/*
113-
!website/static/js/mathjax.js
114-
!website/static/js/code_block_buttons.js
115-
website/static/_sphinx-sources/
116-
node_modules
112+
website/static/_sphinx/
113+
114+
# Insight
115+
captum/insights/attr_vis/frontend/node_modules/
117116
captum/insights/attr_vis/widget/static

scripts/build_docs.sh

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,43 +35,36 @@ cd sphinx || exit
3535
make html
3636
cd .. || exit
3737

38-
echo "-----------------------------------"
39-
echo "Building Captum Docusaurus site"
40-
echo "-----------------------------------"
41-
cd website || exit
42-
yarn
43-
4438
# run script to parse html generated by sphinx
4539
echo "--------------------------------------------"
46-
echo "Parsing Sphinx docs and moving to Docusaurus"
40+
echo "Parsing Sphinx docs and moving to Website"
4741
echo "--------------------------------------------"
48-
cd ..
4942
mkdir -p "website/pages/api/"
5043

5144
cwd=$(pwd)
5245
python scripts/parse_sphinx.py -i "${cwd}/sphinx/build/html/" -o "${cwd}/website/pages/api/"
5346

5447
SPHINX_STATIC_DIR='sphinx/build/html/_static/'
55-
DOCUSAURUS_JS_DIR='website/static/js/'
56-
DOCUSAURUS_CSS_DIR='website/static/css/'
48+
WEBSITE_SPHINX_DIR='website/static/_sphinx/'
5749

58-
mkdir -p $DOCUSAURUS_JS_DIR
50+
mkdir -p $WEBSITE_SPHINX_DIR
5951

6052
# move static files from /sphinx/build/html/_static/*:
61-
cp "${SPHINX_STATIC_DIR}documentation_options.js" "${DOCUSAURUS_JS_DIR}documentation_options.js"
62-
cp "${SPHINX_STATIC_DIR}jquery.js" "${DOCUSAURUS_JS_DIR}jquery.js"
63-
cp "${SPHINX_STATIC_DIR}underscore.js" "${DOCUSAURUS_JS_DIR}underscore.js"
64-
cp "${SPHINX_STATIC_DIR}doctools.js" "${DOCUSAURUS_JS_DIR}doctools.js"
65-
cp "${SPHINX_STATIC_DIR}language_data.js" "${DOCUSAURUS_JS_DIR}language_data.js"
66-
cp "${SPHINX_STATIC_DIR}searchtools.js" "${DOCUSAURUS_JS_DIR}searchtools.js"
67-
cp "${SPHINX_STATIC_DIR}katex_autorenderer.js" "${DOCUSAURUS_JS_DIR}katex_autorenderer.js"
68-
cp "${SPHINX_STATIC_DIR}katex-math.css" "${DOCUSAURUS_CSS_DIR}katex-math.css"
53+
for sphinx_static_file in 'documentation_options.js' \
54+
'jquery.js' \
55+
'underscore.js' \
56+
'doctools.js' \
57+
'language_data.js' \
58+
'searchtools.js' \
59+
'katex_autorenderer.js' \
60+
'pygments.css' \
61+
'katex-math.css'
62+
do
63+
cp "${SPHINX_STATIC_DIR}${sphinx_static_file}" "${WEBSITE_SPHINX_DIR}${sphinx_static_file}"
64+
done
6965

7066
# searchindex.js is not static util
71-
cp "sphinx/build/html/searchindex.js" "${DOCUSAURUS_JS_DIR}searchindex.js"
72-
73-
# copy module sources
74-
cp -r "sphinx/build/html/_sources/" "website/static/_sphinx-sources/"
67+
cp "sphinx/build/html/searchindex.js" "${WEBSITE_SPHINX_DIR}searchindex.js"
7568

7669
echo "-----------------------------------"
7770
echo "Generating tutorials"
@@ -80,7 +73,11 @@ mkdir -p "website/_tutorials"
8073
mkdir -p "website/static/files"
8174
python scripts/parse_tutorials.py -w "${cwd}"
8275

76+
echo "-----------------------------------"
77+
echo "Install Website dependencies"
78+
echo "-----------------------------------"
8379
cd website || exit
80+
yarn
8481

8582
if [[ $BUILD_STATIC == true ]]; then
8683
echo "-----------------------------------"

scripts/parse_sphinx.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55

66
from bs4 import BeautifulSoup
77

8+
# no need to import css from built path
9+
# coz docusaurus merge all css files within static folder automatically
10+
# https://v1.docusaurus.io/docs/en/api-pages#styles
811
base_scripts = """
912
<script type="text/javascript" id="documentation_options" data-url_root="./"
10-
src="/js/documentation_options.js"></script>
11-
<script type="text/javascript" src="/js/jquery.js"></script>
12-
<script type="text/javascript" src="/js/underscore.js"></script>
13-
<script type="text/javascript" src="/js/doctools.js"></script>
14-
<script type="text/javascript" src="/js/language_data.js"></script>
15-
<script type="text/javascript" src="/js/searchtools.js"></script>
13+
src="/_sphinx/documentation_options.js"></script>
14+
<script type="text/javascript" src="/_sphinx/jquery.js"></script>
15+
<script type="text/javascript" src="/_sphinx/underscore.js"></script>
16+
<script type="text/javascript" src="/_sphinx/doctools.js"></script>
17+
<script type="text/javascript" src="/_sphinx/language_data.js"></script>
18+
<script type="text/javascript" src="/_sphinx/searchtools.js"></script>
1619
""" # noqa: E501
1720

1821
search_js_scripts = """
1922
<script type="text/javascript">
20-
jQuery(function() { Search.loadIndex("/js/searchindex.js"); });
23+
jQuery(function() { Search.loadIndex("/_sphinx/searchindex.js"); });
2124
</script>
2225
2326
<script type="text/javascript" id="searchindexloader"></script>
@@ -26,9 +29,8 @@
2629
katex_scripts = """
2730
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js"></script>
2831
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js"></script>
29-
<script src="/js/katex_autorenderer.js"></script>
32+
<script src="/_sphinx/katex_autorenderer.js"></script>
3033
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" />
31-
<link rel="stylesheet" type="text/css" href="/css/katex-math.css" />
3234
""" # noqa: E501
3335

3436

@@ -57,15 +59,6 @@ def parse_sphinx(input_dir, output_dir):
5759
with open(os.path.join(output_path, fname), "w") as fout:
5860
fout.write(out)
5961

60-
# update reference in JS file
61-
with open(os.path.join(input_dir, "_static/searchtools.js"), "r") as js_file:
62-
js = js_file.read()
63-
js = js.replace(
64-
"DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/'", "'_sphinx-sources/'"
65-
)
66-
with open(os.path.join(input_dir, "_static/searchtools.js"), "w") as js_file:
67-
js_file.write(js)
68-
6962

7063
if __name__ == "__main__":
7164
parser = argparse.ArgumentParser(description="Strip HTML body from Sphinx docs.")
@@ -81,7 +74,7 @@ def parse_sphinx(input_dir, output_dir):
8174
"--output_dir",
8275
metavar="path",
8376
required=True,
84-
help="Output directory in Docusaurus.",
77+
help="Output directory in website.",
8578
)
8679
args = parser.parse_args()
8780
parse_sphinx(args.input_dir, args.output_dir)

sphinx/source/conf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@
115115
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
116116
html_show_copyright = False
117117

118+
# If true, the reST sources are included in the HTML build as _sources/name.
119+
# The default is True.
120+
# Uncomment the following line after sphinx 4.5.0 release
121+
# https://github.com/sphinx-doc/sphinx/issues/9456
122+
# html_copy_source = False
118123

119124
# -- Options for HTMLHelp output ---------------------------------------------
120125

website/siteConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const siteConfig = {
7373
],
7474

7575
// CSS sources to load
76-
stylesheets: [`${baseUrl}css/code_block_buttons.css`],
76+
stylesheets: [],
7777

7878
// enable on-page navigation for the current documentation page
7979
onPageNav: "separate",

website/static/pygments.css

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)