Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #2 from mobify/absolutizer

Absolutizer plugin
  • Loading branch information...
commit 9d9997e045a114acf45f7003a2f8fbe73e33af5c 2 parents 03bf414 + b0fac70
John Boxall johnboxall authored

Showing 1 changed file with 31 additions and 0 deletions. Show diff stats Hide diff stats

  1. +31 0 pelican/plugins/absolutizer.py
31 pelican/plugins/absolutizer.py
... ... @@ -0,0 +1,31 @@
  1 +# -*- coding: utf-8 -*-
  2 +'''
  3 +Absolutize relative URLs in Articles.
  4 +
  5 +Useful to ensure RSS feeds include absolute URLs.
  6 +
  7 +'''
  8 +from pelican import signals
  9 +from pelican.contents import Article
  10 +
  11 +from lxml.html import fromstring, tostring
  12 +
  13 +
  14 +def _update_content(self, content, siteurl):
  15 + '''
  16 + Monkey-patch `article.content` to absolutize links relative to `siteurl`.
  17 +
  18 + '''
  19 + content = super(Article, self)._update_content(content, siteurl)
  20 + document = fromstring(content)
  21 + document.make_links_absolute(siteurl)
  22 + content = tostring(document)
  23 + return content
  24 +
  25 +
  26 +def absolutize(sender):
  27 + Article._update_content = _update_content
  28 +
  29 +
  30 +def register():
  31 + signals.initialized.connect(absolutize)

0 comments on commit 9d9997e

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