Skip to content
Browse files

MW-173: Added a plugin that hooks into article feed creation process …

…and absolutizes URLs for links and images
  • Loading branch information...
1 parent 03bf414 commit 6f51c10c523f1b255748b27643c434672b040528 @donnielrt donnielrt committed Mar 27, 2013
Showing with 29 additions and 0 deletions.
  1. +29 −0 pelican/plugins/absolutizer.py
View
29 pelican/plugins/absolutizer.py
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+"""
+ Convert relative urls and paths into absolute urls and paths
+"""
+
+from pelican import signals
+from lxml.html import fromstring, tostring
+from pelican.contents import Article
+
+
+def _update_content(self, content, siteurl):
+ """
+ `Article.content` is an immutable property, so we have to monkey-patch
+ the method that generates the content.
+
+ """
+ content = super(Article, self)._update_content(content, siteurl)
+ content = fromstring(content)
+ content.make_links_absolute(siteurl)
+
+ return tostring(content)
+
+
+def absolutize(sender):
+ Article._update_content = _update_content
+
+
+def register():
+ signals.initialized.connect(absolutize)

0 comments on commit 6f51c10

Please sign in to comment.
Something went wrong with that request. Please try again.