chiark / gitweb /
m.alias: remove useless dependency on m.htmlsanity.
authorVladimír Vondruš <mosra@centrum.cz>
Fri, 19 Apr 2019 17:51:09 +0000 (19:51 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Sat, 20 Apr 2019 15:28:30 +0000 (17:28 +0200)
doc/plugins/links.rst
plugins/m/alias.py
plugins/m/htmlsanity.py

index e350dc5d9ae55357150e95f0476e27438f6c8bed..6e334b54051a1d0149622df2b3017c9146243c75 100644 (file)
@@ -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::
 
index 5d5df96cda3e889badc2a964c202ff32df9d0c61..97d16dc096862f20d5de66f26c330ed11f8d960d 100644 (file)
@@ -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
index 391f09d2ca51dabcd82c6ad4e3864b392bc84c73..38dc42edc9dcdde0f3deea71d8645b28ca2e08b8 100644 (file)
@@ -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)