DOC Switch to Plausible analytics in the docs (#3004)

This commit is contained in:
Roman Yurchak 2022-08-23 09:15:11 +02:00 committed by GitHub
parent f864eee8b5
commit 4cdc054cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

7
docs/_templates/layout.html vendored Normal file
View File

@ -0,0 +1,7 @@
{% extends '!layout.html' %} {%- block extrahead %} {{ super() }}
<script
defer
data-domain="pyodide.org"
src="https://plausible.io/js/plausible.js"
></script>
{%- endblock %}

View File

@ -146,6 +146,21 @@ if IN_READTHEDOCS:
encoding="utf-8",
)
print(res)
# insert the Plausible analytics script to console.html
console_path = Path("_build/html/console.html")
console_html = console_path.read_text().splitlines(keepends=True)
for idx, line in enumerate(list(console_html)):
if 'pyodide.js">' in line:
# insert the analytics script after the `pyodide.js` script
console_html.insert(
idx,
'<script defer data-domain="pyodide.org" src="https://plausible.io/js/plausible.js"></script>\n',
)
break
else:
raise ValueError("Could not find pyodide.js in the <head> section")
console_path.write_text("".join(console_html))
if IN_SPHINX:
# Compatibility shims. sphinx-js and sphinxcontrib-napoleon have not been updated for Python 3.10