diff --git a/pelican/generators.py b/pelican/generators.py index 3b5ca9e4b..ee1054505 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -560,57 +560,93 @@ 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: + if not tag.slug: + logger.info( + 'Tag "%s" has an invalid slug; skipping writing tag page...', + tag, + extra={"limit_msg": "Further tags with invalid slugs."}, + ) + continue + else: + logger.error('Failed to write Tag page for "%s".', tag) + raise 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: + if not cat.slug: + logger.info( + 'Category "%s" has an invalid slug; skipping writing category page...', + cat, + extra={"limit_msg": "Further categories with invalid slugs."}, + ) + continue + else: + logger.error('Failed to write Category page for "%s".', cat) + raise 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: + if not aut.slug: + logger.info( + 'Author "%s" has an invalid slug; skipping writing author page...', + aut, + extra={"limit_msg": "Further authors with invalid slugs."}, + ) + continue + else: + logger.error('Failed to write Author page for "%s".', aut) + raise def generate_drafts(self, write): """Generate drafts pages.""" 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'].