Skip to content

Commit

Permalink
Merge pull request #150 from Guts/improve/handle-missing-site-url
Browse files Browse the repository at this point in the history
Improve: handle missing site url
  • Loading branch information
Guts authored Oct 13, 2022
2 parents d94a2a4 + 60b5a5f commit 478d1a9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mkdocs_rss_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def on_config(self, config: config_options.Config) -> dict:
base_feed.get("html_url") + OUTPUT_FEED_UPDATED
)
else:
logging.warning(
logger.error(
"[rss-plugin] The variable `site_url` is not set in the MkDocs "
"configuration file whereas a URL is mandatory to publish. "
"See: https://validator.w3.org/feed/docs/rss2.html#requiredChannelElements"
Expand Down
7 changes: 7 additions & 0 deletions mkdocs_rss_plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ def build_url(self, base_url: str, path: str, args_dict: dict = None) -> str:
:return: complete and valid URL
:rtype: str
"""
if not base_url:
logger.error(
"[rss-plugin] Base url not set, probably because 'site_url' is not set "
"in Mkdocs configuration file. Using an empty string instead."
)
base_url = ""

# Returns a list in the structure of urlparse.ParseResult
url_parts = list(urlparse(base_url))
url_parts[2] += path
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/mkdocs_pretty_print_disabled.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
site_name: Test RSS Plugin
site_description: Test RSS Plugin

site_url: https://guts.github.io/mkdocs-rss-plugin
use_directory_urls: true

plugins:
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/mkdocs_pretty_print_enabled.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
site_name: Test RSS Plugin
site_description: Test RSS Plugin
site_url: https://guts.github.io/mkdocs-rss-plugin

use_directory_urls: true

Expand Down

0 comments on commit 478d1a9

Please sign in to comment.