Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: mobify/pelican
...
head fork: mobify/pelican
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 1 file changed
  • 0 commit comments
  • 2 contributors
Showing with 31 additions and 0 deletions.
  1. +31 −0 pelican/plugins/absolutizer.py
View
31 pelican/plugins/absolutizer.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+'''
+Absolutize relative URLs in Articles.
+
+Useful to ensure RSS feeds include absolute URLs.
+
+'''
+from pelican import signals
+from pelican.contents import Article
+
+from lxml.html import fromstring, tostring
+
+
+def _update_content(self, content, siteurl):
+ '''
+ Monkey-patch `article.content` to absolutize links relative to `siteurl`.
+
+ '''
+ content = super(Article, self)._update_content(content, siteurl)
+ document = fromstring(content)
+ document.make_links_absolute(siteurl)
+ content = tostring(document)
+ return content
+
+
+def absolutize(sender):
+ Article._update_content = _update_content
+
+
+def register():
+ signals.initialized.connect(absolutize)

No commit comments for this range

Something went wrong with that request. Please try again.