mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge 49096578ef into b7408cbfe9
This commit is contained in:
commit
5428d24636
3 changed files with 84 additions and 41 deletions
|
|
@ -571,57 +571,93 @@ class ArticlesGenerator(CachingGenerator):
|
|||
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."""
|
||||
|
|
|
|||
|
|
@ -42,11 +42,18 @@ class URLWrapper:
|
|||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -253,7 +253,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'].
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue