Skip to content

Commit

Permalink
Merge branch 'main' into doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts authored Mar 23, 2023
2 parents 9b81eb1 + 118d292 commit e38ab72
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mkdocs_rss_plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ def guess_locale(mkdocs_config: Config) -> str or None:

# Some themes implement a locale or a language setting
if "theme" in mkdocs_config and "locale" in mkdocs_config.get("theme"):
return mkdocs_config.get("theme")._vars.get("locale")
locale = mkdocs_config.get("theme")._vars.get("locale")
return f"{locale.language}-{locale.territory}"
elif "theme" in mkdocs_config and "language" in mkdocs_config.get("theme"):
return mkdocs_config.get("theme")._vars.get("language")
else:
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/mkdocs_lang_with_territory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
site_name: Test RSS Plugin
site_description: Test a language code with territory
site_url: https://guts.github.io/mkdocs-rss-plugin

use_directory_urls: true

plugins:
- rss

theme:
name: mkdocs
locale: en_US
26 changes: 26 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,32 @@ def test_simple_build_item_length_unlimited(self):
len(feed_item.description), 150, feed_item.title
)

def test_simple_build_lang_with_territory(self):
with tempfile.TemporaryDirectory() as tmpdirname:
cli_result = self.build_docs_setup(
testproject_path="docs",
mkdocs_yml_filepath=Path(
"tests/fixtures/mkdocs_lang_with_territory.yml"
),
output_path=tmpdirname,
strict=True,
)

if cli_result.exception is not None:
e = cli_result.exception
logger.debug(format_exception(type(e), e, e.__traceback__))

self.assertEqual(cli_result.exit_code, 0)
self.assertIsNone(cli_result.exception)

# created items
feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_created.xml")
self.assertEqual(feed_parsed.feed.get("language"), "en-US")

# updated items
feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_updated.xml")
self.assertEqual(feed_parsed.feed.get("language"), "en-US")

def test_simple_build_pretty_print_enabled(self):
with tempfile.TemporaryDirectory() as tmpdirname:
cli_result = self.build_docs_setup(
Expand Down

0 comments on commit e38ab72

Please sign in to comment.