Skip to content

Commit

Permalink
Log warnings on creating (tag) slugs directly
Browse files Browse the repository at this point in the history
  • Loading branch information
MinchinWeb committed Oct 1, 2024
1 parent 81f3d25 commit cb4ec16
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 6 additions & 3 deletions pelican/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,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:
Expand Down Expand Up @@ -616,9 +617,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:
Expand Down Expand Up @@ -646,9 +648,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:
Expand Down
9 changes: 8 additions & 1 deletion pelican/urlwrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pelican/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def slugify(
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'].
Expand Down

0 comments on commit cb4ec16

Please sign in to comment.