Skip to content

Commit 8785681

Browse files
committedOct 23, 2016
Simplifying.
1 parent 0280de3 commit 8785681

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed
 

‎nikola/nikola.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -1341,25 +1341,21 @@ def render_template(self, template_name, output_name, context, url_type=None, is
13411341
doc = lxml.html.fragment_fromstring(data, parser)
13421342
else:
13431343
doc = lxml.html.document_fromstring(data, parser)
1344-
self.rewrite_links(doc, src, context['lang'], url_type, is_fragment=is_fragment)
1344+
self.rewrite_links(doc, src, context['lang'], url_type)
13451345
if is_fragment:
13461346
data = (doc.text or '').encode('utf-8') + ''.encode('utf-8').join([lxml.html.tostring(child, encoding='utf-8', method='html') for child in doc.iterchildren()])
13471347
else:
13481348
data = b'<!DOCTYPE html>\n' + lxml.html.tostring(doc, encoding='utf8', method='html', pretty_print=True)
13491349
with open(output_name, "wb+") as post_file:
13501350
post_file.write(data)
13511351

1352-
def rewrite_links(self, doc, src, lang, url_type=None, is_fragment=False):
1352+
def rewrite_links(self, doc, src, lang, url_type=None):
13531353
"""Replace links in document to point to the right places."""
13541354
# First let lxml replace most of them
13551355
doc.rewrite_links(lambda dst: self.url_replacer(src, dst, lang, url_type), resolve_base_href=False)
13561356

13571357
# lxml ignores srcset in img and source elements, so do that by hand
1358-
if is_fragment:
1359-
# With the asterisk, top-level <img> and <source> tags are not found
1360-
objs = list(doc.xpath('(//img|//source)'))
1361-
else:
1362-
objs = list(doc.xpath('(*//img|*//source)'))
1358+
objs = list(doc.xpath('(//img|//source)'))
13631359
for obj in objs:
13641360
if 'srcset' in obj.attrib:
13651361
urls = [u.strip() for u in obj.attrib['srcset'].split(',')]

0 commit comments

Comments
 (0)
Failed to load comments.