mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Support for params and fragments in intrasite links. Adresses #1063.
This commit is contained in:
parent
e5c0a54c57
commit
7d43c4fa00
1 changed files with 18 additions and 11 deletions
|
|
@ -5,6 +5,7 @@ import six
|
||||||
import copy
|
import copy
|
||||||
import locale
|
import locale
|
||||||
import logging
|
import logging
|
||||||
|
import urlparse
|
||||||
import functools
|
import functools
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
@ -194,30 +195,36 @@ class Content(object):
|
||||||
|
|
||||||
def replacer(m):
|
def replacer(m):
|
||||||
what = m.group('what')
|
what = m.group('what')
|
||||||
value = m.group('value')
|
value = urlparse.urlparse(m.group('value'))
|
||||||
|
path = value.path
|
||||||
origin = m.group('path')
|
origin = m.group('path')
|
||||||
|
|
||||||
# XXX Put this in a different location.
|
# XXX Put this in a different location.
|
||||||
if what == 'filename':
|
if what == 'filename':
|
||||||
if value.startswith('/'):
|
if path.startswith('/'):
|
||||||
value = value[1:]
|
path = path[1:]
|
||||||
else:
|
else:
|
||||||
# relative to the source path of this content
|
# relative to the source path of this content
|
||||||
value = self.get_relative_source_path(
|
path = self.get_relative_source_path(
|
||||||
os.path.join(self.relative_dir, value)
|
os.path.join(self.relative_dir, path)
|
||||||
)
|
)
|
||||||
|
|
||||||
if value in self._context['filenames']:
|
if path in self._context['filenames']:
|
||||||
origin = '/'.join((siteurl,
|
origin = '/'.join((siteurl,
|
||||||
self._context['filenames'][value].url))
|
self._context['filenames'][path].url))
|
||||||
origin = origin.replace('\\', '/') # Fow windows paths.
|
origin = origin.replace('\\', '/') # for Windows paths.
|
||||||
else:
|
else:
|
||||||
logger.warning("Unable to find {fn}, skipping url"
|
logger.warning("Unable to find {fn}, skipping url"
|
||||||
" replacement".format(fn=value))
|
" replacement".format(fn=path))
|
||||||
elif what == 'category':
|
elif what == 'category':
|
||||||
origin = Category(value, self.settings).url
|
origin = Category(path, self.settings).url
|
||||||
elif what == 'tag':
|
elif what == 'tag':
|
||||||
origin = Tag(value, self.settings).url
|
origin = Tag(path, self.settings).url
|
||||||
|
|
||||||
|
# keep all other parts, such as query, fragment, etc.
|
||||||
|
parts = list(value)
|
||||||
|
parts[2] = origin
|
||||||
|
origin = urlparse.urlunparse(parts)
|
||||||
|
|
||||||
return ''.join((m.group('markup'), m.group('quote'), origin,
|
return ''.join((m.group('markup'), m.group('quote'), origin,
|
||||||
m.group('quote')))
|
m.group('quote')))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue