From 10b150112ea7b0e894419ce3351c17ac9e8e0cd7 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Mon, 10 Jul 2023 17:53:51 +0100 Subject: [PATCH] Improved error reporting in social plugin --- material/plugins/social/plugin.py | 16 ++++++++++++++++ src/plugins/social/plugin.py | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/material/plugins/social/plugin.py b/material/plugins/social/plugin.py index 565ab00a2ea..de16f609889 100644 --- a/material/plugins/social/plugin.py +++ b/material/plugins/social/plugin.py @@ -188,6 +188,22 @@ def on_page_markdown(self, markdown, page, config, files): if "description" in page.meta: description = page.meta["description"] + # Check type of meta title - see https://t.ly/m1Us + if not isinstance(title, str): + log.error( + f"Page meta title of page '{page.file.src_uri}' must be a " + f"string, but is of type \"{type(title)}\"." + ) + sys.exit(1) + + # Check type of meta description - see https://t.ly/m1Us + if not isinstance(description, str): + log.error( + f"Page meta description of '{page.file.src_uri}' must be a " + f"string, but is of type \"{type(description)}\"." + ) + sys.exit(1) + # Generate social card if not in cache - TODO: values from mkdocs.yml hash = md5("".join([ site_name, diff --git a/src/plugins/social/plugin.py b/src/plugins/social/plugin.py index 565ab00a2ea..de16f609889 100644 --- a/src/plugins/social/plugin.py +++ b/src/plugins/social/plugin.py @@ -188,6 +188,22 @@ def on_page_markdown(self, markdown, page, config, files): if "description" in page.meta: description = page.meta["description"] + # Check type of meta title - see https://t.ly/m1Us + if not isinstance(title, str): + log.error( + f"Page meta title of page '{page.file.src_uri}' must be a " + f"string, but is of type \"{type(title)}\"." + ) + sys.exit(1) + + # Check type of meta description - see https://t.ly/m1Us + if not isinstance(description, str): + log.error( + f"Page meta description of '{page.file.src_uri}' must be a " + f"string, but is of type \"{type(description)}\"." + ) + sys.exit(1) + # Generate social card if not in cache - TODO: values from mkdocs.yml hash = md5("".join([ site_name,