From: Vladimír Vondruš Date: Fri, 19 Apr 2019 17:51:09 +0000 (+0200) Subject: m.alias: remove useless dependency on m.htmlsanity. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=f305bb8c5460b86b061a1ba2f5dc0ab9310997b0;p=blog.git m.alias: remove useless dependency on m.htmlsanity. --- diff --git a/doc/plugins/links.rst b/doc/plugins/links.rst index e350dc5d..6e334b54 100644 --- a/doc/plugins/links.rst +++ b/doc/plugins/links.rst @@ -414,12 +414,11 @@ pages and articles. For Pelican, download the `m/alias.py <{filename}/plugins.rst>`_ file, put it including the ``m/`` directory into one of your :py:`PLUGIN_PATHS` and add -:py:`m.alias` package to your :py:`PLUGINS` in ``pelicanconf.py``. This plugin -assumes presence of `m.htmlsanity <{filename}/plugins/htmlsanity.rst>`_. +:py:`m.alias` package to your :py:`PLUGINS` in ``pelicanconf.py``. .. code:: python - PLUGINS += ['m.htmlsanity', 'm.alias'] + PLUGINS += ['m.alias'] .. note-success:: diff --git a/plugins/m/alias.py b/plugins/m/alias.py index 5d5df96c..97d16dc0 100644 --- a/plugins/m/alias.py +++ b/plugins/m/alias.py @@ -28,8 +28,7 @@ import os import logging from pelican import signals - -from m.htmlsanity import format_siteurl +from urllib.parse import urljoin logger = logging.getLogger(__name__) @@ -37,6 +36,11 @@ class AliasGenerator: def __init__(self, context, settings, path, theme, output_path, *args): self.output_path = output_path self.context = context + self.siteurl = settings['SITEURL'] + + # Keep consistent with m.htmlsanity + def format_siteurl(self, url): + return urljoin(self.siteurl + ('/' if not self.siteurl.endswith('/') else ''), url) def generate_output(self, writer): for page in self.context['pages'] + self.context['articles']: @@ -54,7 +58,7 @@ class AliasGenerator: if not filename: filename = 'index.html' alias_file = os.path.join(directory, filename) - alias_target = format_siteurl(page.url) + alias_target = self.format_siteurl(page.url) logger.info('m.alias: creating alias {} -> {}'.format(alias_file[len(self.output_path):], alias_target)) # Write the redirect file diff --git a/plugins/m/htmlsanity.py b/plugins/m/htmlsanity.py index 391f09d2..38dc42ed 100644 --- a/plugins/m/htmlsanity.py +++ b/plugins/m/htmlsanity.py @@ -721,7 +721,8 @@ def expand_links(text, content): return content._update_content(text, content.get_siteurl()) # To be consistent with both what Pelican does now with '/'.join(SITEURL, url) -# and with https://github.com/getpelican/pelican/pull/2196 +# and with https://github.com/getpelican/pelican/pull/2196. Keep consistent +# with m.alias. def format_siteurl(url): return urljoin(pelican_settings['SITEURL'] + ('/' if not pelican_settings['SITEURL'].endswith('/') else ''), url)