Skip to content

Commit

Permalink
fix: pull in config for plausible
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Jul 24, 2024
1 parent 47d2481 commit fb16d16
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions jupyter_book/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A small sphinx extension to let you configure a site with YAML metadata."""

import json
import sys
from functools import lru_cache
Expand Down Expand Up @@ -189,20 +190,6 @@ def get_final_config(
if sphinx_config.get("use_multitoc_numbering"):
sphinx_config["extensions"].append("sphinx_multitoc_numbering")

# Fix for renamed field
google_analytics_id = sphinx_config.get("html", {}).get("google_analytics_id")
if google_analytics_id is not None:
_message_box(
(
"[Warning] The `html.google_analytics_id` configuration value has moved to `html.analytics.google_analytics_id`" # noqa: E501
),
color="orange",
print_func=print,
)
sphinx_config["html"].setdefault("analytics", {})[
"google_analytics_id"
] = google_analytics_id

# finally merge in CLI configuration
_recursive_update(sphinx_config, cli_config or {})

Expand Down Expand Up @@ -312,10 +299,29 @@ def yaml_to_sphinx(yaml: dict):
if yml_key in html:
theme_options[spx_key] = html[yml_key]

for spx_key, yml_key in [("google_analytics_id", "google_analytics_id")]:
if yml_key in html:
theme_options["analytics"] = {}
theme_options["analytics"][spx_key] = html[yml_key]
# Fix for renamed field
spx_analytics = theme_options["analytics"] = {}
google_analytics_id = html.get("google_analytics_id")
if google_analytics_id is not None:
_message_box(
(
"[Warning] The `html.google_analytics_id` configuration value has moved to `html.analytics.google_analytics_id`" # noqa: E501
),
color="orange",
print_func=print,
)
spx_analytics["google_analytics_id"] = google_analytics_id

# Analytics
yml_analytics = html.get("analytics", {})
for spx_key, yml_key in [
("google_analytics_id", "google_analytics_id"),
("plausible_analytics_domain", "plausible_analytics_domain"),
("plausible_analytics_url", "plausible_analytics_url"),
]:
if yml_key in yml_analytics:
spx_analytics[spx_key] = yml_analytics[yml_key]

# Pass through the buttons
btns = ["use_repository_button", "use_edit_page_button", "use_issues_button"]
use_buttons = {btn: html.get(btn) for btn in btns if btn in html}
Expand Down

0 comments on commit fb16d16

Please sign in to comment.