Skip to content

Commit 812b02e

Browse files
authored
Cache avatars (mne-tools#12077)
1 parent 566fa07 commit 812b02e

File tree

8 files changed

+48
-4
lines changed

8 files changed

+48
-4
lines changed

doc/_static/js/contrib-avatars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async function putAvatarsInPage() {
4747
}
4848
// finish
4949
outer.append(title, inner);
50-
document.getElementById("institution-logos").after(outer);
50+
document.body.append(outer);
5151
}
5252

5353
putAvatarsInPage();

doc/_templates/homepage.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@
4141
</div>
4242
{% endfor %}
4343
</div>
44+
<!-- contributors -->
45+
{% include 'avatars.html' %}
4446
</div>

doc/_templates/layout.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,4 @@
1717
{%- block scripts_end %}
1818
{{ super() }}
1919
<script src="https://mne.tools/versionwarning.js"></script>
20-
{% if pagename == 'index' %}
21-
<script src="{{ pathto('_static/js/contrib-avatars.js', 1) }}"></script>
22-
{% endif %}
2320
{%- endblock %}

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
"sphinxcontrib.bibtex",
104104
"sphinxcontrib.youtube",
105105
# homegrown
106+
"contrib_avatars",
106107
"gen_commands",
107108
"gen_names",
108109
"gh_substitutions",

doc/sphinxext/_avatar_template.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<head>
3+
<script src="../_static/js/contrib-avatars.js"></script>
4+
</head>
5+
<body>
6+
</body>
7+
</html>

doc/sphinxext/contrib_avatars.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from pathlib import Path
2+
3+
from selenium import webdriver
4+
from selenium.webdriver.common.by import By
5+
from selenium.webdriver.support.ui import WebDriverWait
6+
from selenium.common.exceptions import WebDriverException
7+
8+
9+
def generate_contrib_avatars(app, config):
10+
"""Render a template webpage with avatars generated by JS and a GitHub API call."""
11+
root = Path(app.srcdir)
12+
infile = root / "sphinxext" / "_avatar_template.html"
13+
outfile = root / "_templates" / "avatars.html"
14+
try:
15+
options = webdriver.ChromeOptions()
16+
options.add_argument("--headless=new")
17+
driver = webdriver.Chrome(options=options)
18+
except WebDriverException:
19+
options = webdriver.FirefoxOptions()
20+
options.add_argument("--headless=new")
21+
driver = webdriver.Firefox(options=options)
22+
driver.get(f"file://{infile}")
23+
wait = WebDriverWait(driver, 20)
24+
wait.until(lambda d: d.find_element(by=By.ID, value="contributor-avatars"))
25+
body = driver.find_element(by=By.TAG_NAME, value="body").get_attribute("innerHTML")
26+
with open(outfile, "w") as fid:
27+
fid.write(body)
28+
driver.quit()
29+
30+
31+
def setup(app):
32+
"""Set up the Sphinx app."""
33+
app.connect("config-inited", generate_contrib_avatars)
34+
return

requirements_doc.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ pytest
1919
graphviz
2020
pyzmq!=24.0.0
2121
ipython!=8.7.0
22+
selenium

tools/circleci_bash_env.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ set -o pipefail
55

66
./tools/setup_xvfb.sh
77
sudo apt install -qq graphviz optipng python3.10-venv python3-venv libxft2 ffmpeg
8+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
9+
sudo apt install ./google-chrome-stable_current_amd64.deb
810
python3.10 -m venv ~/python_env
911
echo "set -e" >> $BASH_ENV
1012
echo "set -o pipefail" >> $BASH_ENV

0 commit comments

Comments
 (0)