forked from github/pelican
Merge pull request #1366 from Scheirle/paginated_relative_urls_fix2
Fixes wrongly generated relative urls for pagination.
This commit is contained in:
commit
fbc65e0d7b
1 changed files with 18 additions and 11 deletions
|
|
@ -153,6 +153,9 @@ class Writer(object):
|
||||||
|
|
||||||
def _write_file(template, localcontext, output_path, name, override):
|
def _write_file(template, localcontext, output_path, name, override):
|
||||||
"""Render the template write the file."""
|
"""Render the template write the file."""
|
||||||
|
# set localsiteurl for context so that Contents can adjust links
|
||||||
|
if localcontext['localsiteurl']:
|
||||||
|
context['localsiteurl'] = localcontext['localsiteurl']
|
||||||
output = template.render(localcontext)
|
output = template.render(localcontext)
|
||||||
path = os.path.join(output_path, name)
|
path = os.path.join(output_path, name)
|
||||||
try:
|
try:
|
||||||
|
|
@ -168,14 +171,16 @@ class Writer(object):
|
||||||
# local context.
|
# local context.
|
||||||
signals.content_written.send(path, context=localcontext)
|
signals.content_written.send(path, context=localcontext)
|
||||||
|
|
||||||
localcontext = context.copy()
|
def _get_localcontext(context, name, kwargs, relative_urls):
|
||||||
if relative_urls:
|
localcontext = context.copy()
|
||||||
relative_url = path_to_url(get_relative_path(name))
|
localcontext['localsiteurl'] = localcontext.get('localsiteurl', None)
|
||||||
context['localsiteurl'] = relative_url
|
if relative_urls:
|
||||||
localcontext['SITEURL'] = relative_url
|
relative_url = path_to_url(get_relative_path(name))
|
||||||
|
localcontext['SITEURL'] = relative_url
|
||||||
localcontext['output_file'] = name
|
localcontext['localsiteurl'] = relative_url
|
||||||
localcontext.update(kwargs)
|
localcontext['output_file'] = name
|
||||||
|
localcontext.update(kwargs)
|
||||||
|
return localcontext
|
||||||
|
|
||||||
# pagination
|
# pagination
|
||||||
if paginated:
|
if paginated:
|
||||||
|
|
@ -186,7 +191,7 @@ class Writer(object):
|
||||||
|
|
||||||
# generated pages, and write
|
# generated pages, and write
|
||||||
for page_num in range(list(paginators.values())[0].num_pages):
|
for page_num in range(list(paginators.values())[0].num_pages):
|
||||||
paginated_localcontext = localcontext.copy()
|
paginated_kwargs = kwargs.copy()
|
||||||
for key in paginators.keys():
|
for key in paginators.keys():
|
||||||
paginator = paginators[key]
|
paginator = paginators[key]
|
||||||
previous_page = paginator.page(page_num) \
|
previous_page = paginator.page(page_num) \
|
||||||
|
|
@ -194,15 +199,17 @@ class Writer(object):
|
||||||
page = paginator.page(page_num + 1)
|
page = paginator.page(page_num + 1)
|
||||||
next_page = paginator.page(page_num + 2) \
|
next_page = paginator.page(page_num + 2) \
|
||||||
if page_num + 1 < paginator.num_pages else None
|
if page_num + 1 < paginator.num_pages else None
|
||||||
paginated_localcontext.update(
|
paginated_kwargs.update(
|
||||||
{'%s_paginator' % key: paginator,
|
{'%s_paginator' % key: paginator,
|
||||||
'%s_page' % key: page,
|
'%s_page' % key: page,
|
||||||
'%s_previous_page' % key: previous_page,
|
'%s_previous_page' % key: previous_page,
|
||||||
'%s_next_page' % key: next_page})
|
'%s_next_page' % key: next_page})
|
||||||
|
|
||||||
_write_file(template, paginated_localcontext, self.output_path,
|
localcontext = _get_localcontext(context, page.save_as, paginated_kwargs, relative_urls)
|
||||||
|
_write_file(template, localcontext, self.output_path,
|
||||||
page.save_as, override_output)
|
page.save_as, override_output)
|
||||||
else:
|
else:
|
||||||
# no pagination
|
# no pagination
|
||||||
|
localcontext = _get_localcontext(context, name, kwargs, relative_urls)
|
||||||
_write_file(template, localcontext, self.output_path, name,
|
_write_file(template, localcontext, self.output_path, name,
|
||||||
override_output)
|
override_output)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue