From bc548627e68ef6926031118986544b63a2e638b8 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Mon, 11 Dec 2023 22:00:35 -0700 Subject: [PATCH 1/3] If it fails to write a tag/catetory/author page, tell us which one we failed on --- pelican/generators.py | 90 ++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/pelican/generators.py b/pelican/generators.py index 3b5ca9e4b..2bc2b13ef 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -560,57 +560,69 @@ def generate_tags(self, write): tag_template = self.get_template("tag") for tag, articles in self.tags.items(): dates = [article for article in self.dates if article in articles] - write( - tag.save_as, - tag_template, - self.context, - tag=tag, - url=tag.url, - articles=articles, - dates=dates, - template_name="tag", - blog=True, - page_name=tag.page_name, - all_articles=self.articles, - ) + try: + write( + tag.save_as, + tag_template, + self.context, + tag=tag, + url=tag.url, + articles=articles, + dates=dates, + template_name="tag", + blog=True, + page_name=tag.page_name, + all_articles=self.articles, + ) + except RuntimeError as e: + logger.error('Trying to write Tag page for "%s".' % (tag)) + raise e def generate_categories(self, write): """Generate category pages.""" category_template = self.get_template("category") for cat, articles in self.categories: dates = [article for article in self.dates if article in articles] - write( - cat.save_as, - category_template, - self.context, - url=cat.url, - category=cat, - articles=articles, - dates=dates, - template_name="category", - blog=True, - page_name=cat.page_name, - all_articles=self.articles, - ) + try: + write( + cat.save_as, + category_template, + self.context, + url=cat.url, + category=cat, + articles=articles, + dates=dates, + template_name="category", + blog=True, + page_name=cat.page_name, + all_articles=self.articles, + ) + except RuntimeError as e: + logger.error('Trying to write Category page for "%s".' % (cat)) + raise e def generate_authors(self, write): """Generate Author pages.""" author_template = self.get_template("author") for aut, articles in self.authors: dates = [article for article in self.dates if article in articles] - write( - aut.save_as, - author_template, - self.context, - url=aut.url, - author=aut, - articles=articles, - dates=dates, - template_name="author", - blog=True, - page_name=aut.page_name, - all_articles=self.articles, - ) + try: + write( + aut.save_as, + author_template, + self.context, + url=aut.url, + author=aut, + articles=articles, + dates=dates, + template_name="author", + blog=True, + page_name=aut.page_name, + all_articles=self.articles, + ) + except RuntimeError as e: + logger.error('Trying to write Author page for "%s".' % (aut)) + raise e def generate_drafts(self, write): """Generate drafts pages.""" From 902640ee99d4dd53c972f41ae46b29f4d1f88782 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 12 Dec 2023 20:02:27 -0700 Subject: [PATCH 2/3] Better error message on bad slug --- pelican/generators.py | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/pelican/generators.py b/pelican/generators.py index 2bc2b13ef..c4c9300cb 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -574,9 +574,16 @@ def generate_tags(self, write): page_name=tag.page_name, all_articles=self.articles, ) - except RuntimeError as e: - logger.error('Trying to write Tag page for "%s".' % (tag)) - raise e + except RuntimeError: + if not tag.slug: + logger.warning( + 'Tag "%s" has an invalid slug; skipping writing tag page...', + tag, + ) + continue + else: + logger.error('Failed to write Tag page for "%s".', tag) + raise def generate_categories(self, write): """Generate category pages.""" @@ -597,9 +604,16 @@ def generate_categories(self, write): page_name=cat.page_name, all_articles=self.articles, ) - except RuntimeError as e: - logger.error('Trying to write Category page for "%s".' % (cat)) - raise e + except RuntimeError: + if not cat.slug: + logger.warning( + 'Category "%s" has an invalid slug; skipping writing category page...', + cat, + ) + continue + else: + logger.error('Failed to write Category page for "%s".', cat) + raise def generate_authors(self, write): """Generate Author pages.""" @@ -620,9 +634,16 @@ def generate_authors(self, write): page_name=aut.page_name, all_articles=self.articles, ) - except RuntimeError as e: - logger.error('Trying to write Author page for "%s".' % (aut)) - raise e + except RuntimeError: + if not aut.slug: + logger.warning( + 'Author "%s" has an invalid slug; skipping writing author page...', + aut, + ) + continue + else: + logger.error('Failed to write Author page for "%s".', aut) + raise def generate_drafts(self, write): """Generate drafts pages.""" From 49096578ef09b65f1cbf79113a25108489aaf33e Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Wed, 27 Dec 2023 15:39:51 -0700 Subject: [PATCH 3/3] Log warnings on creating (tag) slugs directly --- pelican/generators.py | 9 ++++++--- pelican/urlwrappers.py | 9 ++++++++- pelican/utils.py | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pelican/generators.py b/pelican/generators.py index c4c9300cb..ee1054505 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -576,9 +576,10 @@ def generate_tags(self, write): ) except RuntimeError: if not tag.slug: - logger.warning( + logger.info( 'Tag "%s" has an invalid slug; skipping writing tag page...', tag, + extra={"limit_msg": "Further tags with invalid slugs."}, ) continue else: @@ -606,9 +607,10 @@ def generate_categories(self, write): ) except RuntimeError: if not cat.slug: - logger.warning( + logger.info( 'Category "%s" has an invalid slug; skipping writing category page...', cat, + extra={"limit_msg": "Further categories with invalid slugs."}, ) continue else: @@ -636,9 +638,10 @@ def generate_authors(self, write): ) except RuntimeError: if not aut.slug: - logger.warning( + logger.info( 'Author "%s" has an invalid slug; skipping writing author page...', aut, + extra={"limit_msg": "Further authors with invalid slugs."}, ) continue else: diff --git a/pelican/urlwrappers.py b/pelican/urlwrappers.py index 6d705d4c1..7d823961c 100644 --- a/pelican/urlwrappers.py +++ b/pelican/urlwrappers.py @@ -42,11 +42,18 @@ def slug(self): preserve_case=preserve_case, use_unicode=self.settings.get("SLUGIFY_USE_UNICODE", False), ) + if not self._slug: + logger.warning( + 'Unable to generate valid slug for %s "%s".', + self.__class__.__name__, + self.name, + extra={"limit_msg": "Other invalid slugs."}, + ) return self._slug @slug.setter def slug(self, slug): - # if slug is expliticly set, changing name won't alter slug + # if slug is explicitly set, changing name won't alter slug self._slug_from_name = False self._slug = slug diff --git a/pelican/utils.py b/pelican/utils.py index eda53d3f5..73c197c1e 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -226,7 +226,7 @@ def slugify(value, regex_subs=(), preserve_case=False, use_unicode=False): Normalizes string, converts to lowercase, removes non-alpha characters, and converts spaces to hyphens. - Took from Django sources. + Taken from Django sources. For a set of sensible default regex substitutions to pass to regex_subs look into pelican.settings.DEFAULT_CONFIG['SLUG_REGEX_SUBSTITUTIONS'].