|
3 | 3 | import os
|
4 | 4 | from pathlib import Path
|
5 | 5 | from typing import TYPE_CHECKING
|
6 |
| -from urllib.parse import urljoin, urlparse, urlsplit, urlunparse |
| 6 | +from urllib.parse import urljoin, urlparse, urlsplit, urlunsplit |
7 | 7 |
|
8 | 8 | import docutils.nodes as nodes
|
9 | 9 |
|
@@ -100,27 +100,7 @@ def get_tags(
|
100 | 100 | tags["og:type"] = config.ogp_type
|
101 | 101 |
|
102 | 102 | if not config.ogp_site_url and os.getenv("READTHEDOCS"):
|
103 |
| - if config.html_baseurl is not None: |
104 |
| - # readthedocs uses ``html_baseurl`` for Sphinx > 1.8 |
105 |
| - parse_result = urlsplit(config.html_baseurl) |
106 |
| - else: |
107 |
| - # readthedocs addons no longer configures ``html_baseurl`` |
108 |
| - if rtd_canonical_url := os.getenv("READTHEDOCS_CANONICAL_URL"): |
109 |
| - parse_result = urlsplit(rtd_canonical_url) |
110 |
| - else: |
111 |
| - raise OSError("ReadTheDocs did not provide a valid canonical URL!") |
112 |
| - |
113 |
| - # Grab root url from canonical url |
114 |
| - config.ogp_site_url = urlunparse( |
115 |
| - ( |
116 |
| - parse_result.scheme, |
117 |
| - parse_result.netloc, |
118 |
| - parse_result.path, |
119 |
| - "", |
120 |
| - "", |
121 |
| - "", |
122 |
| - ) |
123 |
| - ) |
| 103 | + config.ogp_site_url = read_the_docs_site_url(config.html_baseurl) |
124 | 104 |
|
125 | 105 | # url tag
|
126 | 106 | # Get the URL of the specific page
|
@@ -248,6 +228,29 @@ def get_tags(
|
248 | 228 | )
|
249 | 229 |
|
250 | 230 |
|
| 231 | +def read_the_docs_site_url(html_baseurl: str | None) -> str: |
| 232 | + if html_baseurl is not None: |
| 233 | + # readthedocs uses ``html_baseurl`` for Sphinx > 1.8 |
| 234 | + parse_result = urlsplit(html_baseurl) |
| 235 | + else: |
| 236 | + # readthedocs addons no longer configures ``html_baseurl`` |
| 237 | + if rtd_canonical_url := os.getenv("READTHEDOCS_CANONICAL_URL"): |
| 238 | + parse_result = urlsplit(rtd_canonical_url) |
| 239 | + else: |
| 240 | + raise OSError("ReadTheDocs did not provide a valid canonical URL!") |
| 241 | + |
| 242 | + # Grab root url from canonical url |
| 243 | + return urlunsplit( |
| 244 | + ( |
| 245 | + parse_result.scheme, |
| 246 | + parse_result.netloc, |
| 247 | + parse_result.path, |
| 248 | + "", |
| 249 | + "", |
| 250 | + ) |
| 251 | + ) |
| 252 | + |
| 253 | + |
251 | 254 | def social_card_for_page(
|
252 | 255 | config_social: dict[str, bool | str],
|
253 | 256 | site_name: str,
|
|
0 commit comments