Index: cms/converters.py |
=================================================================== |
--- a/cms/converters.py |
+++ b/cms/converters.py |
@@ -304,19 +304,19 @@ |
# Links to an external resource |
return target |
return relpath(target, base_url.rsplit('/', 1)[0]) |
def process_link(match): |
pre, attr, url, post = match.groups() |
url = jinja2.Markup(url).unescape() |
- locale, new_url = ( |
- self._params['source'] |
- .resolve_link(url, self._params['locale'])) |
+ locale, new_url = self._params['source'].resolve_link( |
+ url, self._params['locale'], self._params['page'], |
+ ) |
if new_url is not None: |
url = new_url |
if attr == 'href': |
post += ' hreflang="{}"'\ |
.format(jinja2.Markup.escape(locale)) |
if self._params['relative']: |
@@ -511,17 +511,18 @@ |
if locale is None: |
locale = self._params['locale'] |
return utils.get_page_params(self._params['source'], locale, page) |
def linkify(self, page, locale=None, **attrs): |
if locale is None: |
locale = self._params['locale'] |
- locale, url = self._params['source'].resolve_link(page, locale) |
+ locale, url = self._params['source'].resolve_link(page, locale, |
+ self._params['page']) |
return jinja2.Markup('<a{}>'.format(''.join( |
' {}="{}"'.format(name, jinja2.escape(value)) for name, value in [ |
('href', url), |
('hreflang', locale), |
] + attrs.items() |
))) |
def get_pages_metadata(self, filters=None): |
@@ -558,17 +559,17 @@ |
"""Return canonical URL for the page (without locale code)""" |
try: |
base_url = self._params['site_url'] |
except KeyError: |
raise Exception('You must configure `siteurl` to use' |
'`get_canonical_url()`') |
locale, page_url = self._params['source'].resolve_link( |
- page, self._params['locale'], |
+ page, self._params['locale'], self._params['page'], |
) |
# Remove the locale component that `resolve_link` adds at the |
# beginning. |
page_url = page_url[len(locale) + 1:] |
return urlparse.urljoin(base_url, page_url) |
def toclist(self, content): |
toc_re = r'<h(\d)\s[^<>]*\bid="([^<>"]+)"[^<>]*>(.*?)</h\1>' |
@@ -592,17 +593,18 @@ |
def page_has_locale(self, page, locale): |
return self._params['source'].has_locale(locale, page) |
def get_page_url(self, page, locale=None, redirect=False): |
if not locale: |
locale = self._params['locale'] |
if self.page_has_locale(page, locale) or redirect: |
- return self._params['source'].resolve_link(page, locale)[1] |
+ return self._params['source'].resolve_link(page, locale, |
+ self._params['page'])[1] |
raise Exception('{} does not exist in {}'.format(page, locale)) |
converters = { |
'html': RawConverter, |
'md': MarkdownConverter, |
'tmpl': TemplateConverter, |
} |