Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #2 from mobify/absolutizer

Absolutizer plugin
  • Loading branch information...
commit 9d9997e045a114acf45f7003a2f8fbe73e33af5c 2 parents 03bf414 + b0fac70
@johnboxall johnboxall authored
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)
Please sign in to comment.
Something went wrong with that request. Please try again.