Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refactor link rewriter into a separate function
  • Loading branch information
ralsina committed Aug 15, 2015
1 parent 52f0b8c commit 1a81901
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nikola/nikola.py
Expand Up @@ -1052,11 +1052,15 @@ def render_template(self, template_name, output_name, context):
utils.makedirs(os.path.dirname(output_name))
parser = lxml.html.HTMLParser(remove_blank_text=True)
doc = lxml.html.document_fromstring(data, parser)
doc.rewrite_links(lambda dst: self.url_replacer(src, dst, context['lang']), resolve_base_href=False)
self.rewrite_links(doc, src, context['lang'])
data = b'<!DOCTYPE html>\n' + lxml.html.tostring(doc, encoding='utf8', method='html', pretty_print=True)
with open(output_name, "wb+") as post_file:
post_file.write(data)

def rewrite_links(self, doc, src, lang):
"""Replace links in document to point to the right places."""
doc.rewrite_links(lambda dst: self.url_replacer(src, dst, lang), resolve_base_href=False)

def url_replacer(self, src, dst, lang=None, url_type=None):
"""Mangle URLs.
Expand Down

0 comments on commit 1a81901

Please sign in to comment.