Skip to content

Commit 478d1a9

Browse files
authored
Merge pull request #150 from Guts/improve/handle-missing-site-url
Improve: handle missing site url
2 parents d94a2a4 + 60b5a5f commit 478d1a9

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

mkdocs_rss_plugin/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def on_config(self, config: config_options.Config) -> dict:
172172
base_feed.get("html_url") + OUTPUT_FEED_UPDATED
173173
)
174174
else:
175-
logging.warning(
175+
logger.error(
176176
"[rss-plugin] The variable `site_url` is not set in the MkDocs "
177177
"configuration file whereas a URL is mandatory to publish. "
178178
"See: https://validator.w3.org/feed/docs/rss2.html#requiredChannelElements"

mkdocs_rss_plugin/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ def build_url(self, base_url: str, path: str, args_dict: dict = None) -> str:
8787
:return: complete and valid URL
8888
:rtype: str
8989
"""
90+
if not base_url:
91+
logger.error(
92+
"[rss-plugin] Base url not set, probably because 'site_url' is not set "
93+
"in Mkdocs configuration file. Using an empty string instead."
94+
)
95+
base_url = ""
96+
9097
# Returns a list in the structure of urlparse.ParseResult
9198
url_parts = list(urlparse(base_url))
9299
url_parts[2] += path

tests/fixtures/mkdocs_pretty_print_disabled.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
site_name: Test RSS Plugin
22
site_description: Test RSS Plugin
3-
3+
site_url: https://guts.github.io/mkdocs-rss-plugin
44
use_directory_urls: true
55

66
plugins:

tests/fixtures/mkdocs_pretty_print_enabled.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
site_name: Test RSS Plugin
22
site_description: Test RSS Plugin
3+
site_url: https://guts.github.io/mkdocs-rss-plugin
34

45
use_directory_urls: true
56

0 commit comments

Comments
 (0)