Skip to content

Commit 118d292

Browse files
authored
Comply language codes with RSS Spec (#178)
Resolves #176
2 parents 769744e + 592956a commit 118d292

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

mkdocs_rss_plugin/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ def guess_locale(mkdocs_config: Config) -> str or None:
560560

561561
# Some themes implement a locale or a language setting
562562
if "theme" in mkdocs_config and "locale" in mkdocs_config.get("theme"):
563-
return mkdocs_config.get("theme")._vars.get("locale")
563+
locale = mkdocs_config.get("theme")._vars.get("locale")
564+
return f"{locale.language}-{locale.territory}"
564565
elif "theme" in mkdocs_config and "language" in mkdocs_config.get("theme"):
565566
return mkdocs_config.get("theme")._vars.get("language")
566567
else:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
site_name: Test RSS Plugin
2+
site_description: Test a language code with territory
3+
site_url: https://guts.github.io/mkdocs-rss-plugin
4+
5+
use_directory_urls: true
6+
7+
plugins:
8+
- rss
9+
10+
theme:
11+
name: mkdocs
12+
locale: en_US

tests/test_build.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,32 @@ def test_simple_build_item_length_unlimited(self):
330330
len(feed_item.description), 150, feed_item.title
331331
)
332332

333+
def test_simple_build_lang_with_territory(self):
334+
with tempfile.TemporaryDirectory() as tmpdirname:
335+
cli_result = self.build_docs_setup(
336+
testproject_path="docs",
337+
mkdocs_yml_filepath=Path(
338+
"tests/fixtures/mkdocs_lang_with_territory.yml"
339+
),
340+
output_path=tmpdirname,
341+
strict=True,
342+
)
343+
344+
if cli_result.exception is not None:
345+
e = cli_result.exception
346+
logger.debug(format_exception(type(e), e, e.__traceback__))
347+
348+
self.assertEqual(cli_result.exit_code, 0)
349+
self.assertIsNone(cli_result.exception)
350+
351+
# created items
352+
feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_created.xml")
353+
self.assertEqual(feed_parsed.feed.get("language"), "en-US")
354+
355+
# updated items
356+
feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_updated.xml")
357+
self.assertEqual(feed_parsed.feed.get("language"), "en-US")
358+
333359
def test_simple_build_pretty_print_enabled(self):
334360
with tempfile.TemporaryDirectory() as tmpdirname:
335361
cli_result = self.build_docs_setup(

0 commit comments

Comments
 (0)