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::
import os
import logging
from pelican import signals
-
-from m.htmlsanity import format_siteurl
+from urllib.parse import urljoin
logger = logging.getLogger(__name__)
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']:
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
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)