Skip to content

Commit

Permalink
Fix #3450 — don’t break slugs with slashes in doc directive
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwpolska committed Sep 5, 2020
1 parent b2e370d commit ac79132
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Features
Bugfixes
--------

* Don’t break slugs with slashes in ``doc`` directive (Issue #3450)
* Avoid warnings from type annotations in ``auto`` caused by missing
``aiohttp`` (Issue #3451)
* Ensure query strings and fragments are kept with ``URL_TYPE =
Expand Down
29 changes: 19 additions & 10 deletions nikola/plugins/compile/rest/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,8 @@ def set_site(self, site):
return super().set_site(site)


def _doc_link(rawtext, text, options={}, content=[]):
"""Handle the doc role."""
# split link's text and post's slug in role content
has_explicit_title, title, slug = split_explicit_title(text)
if '#' in slug:
slug, fragment = slug.split('#', 1)
else:
fragment = None
slug = slugify(slug)
# check if the slug given is part of our blog posts/pages
def _find_post(slug):
"""Find a post with the given slug in posts or pages."""
twin_slugs = False
post = None
for p in doc_role.site.timeline:
Expand All @@ -66,6 +58,23 @@ def _doc_link(rawtext, text, options={}, content=[]):
else:
twin_slugs = True
break
return post, twin_slugs


def _doc_link(rawtext, text, options={}, content=[]):
"""Handle the doc role."""
# split link's text and post's slug in role content
has_explicit_title, title, slug = split_explicit_title(text)
if '#' in slug:
slug, fragment = slug.split('#', 1)
else:
fragment = None

# Look for the unslugified input first, then try to slugify (Issue #3450)
post, twin_slugs = _find_post(slug)
if post is None:
slug = slugify(slug)
post, twin_slugs = _find_post(slug)

try:
if post is None:
Expand Down

0 comments on commit ac79132

Please sign in to comment.