New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow overriding URL_TYPE via meta #2544
Conversation
Useful for HTML fragments inserted via JavaScript that contain links. Use case: nikola-plugins-v2 and its side menu that can be changed without rebuilding all pages.
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM from a technical point of view.
I'm wondering how you're using this to create HTML fragments. To me it seems hard to get Nikola to not create whole HTML pages but only fragments. Wouldn't it make more sense to write a plugin to create such HTML fragments? |
I’m creating fragments for some value of fragments. Our current rendering pipeline (lxml) will add a DOCTYPE, And if I really wanted fragments, I could make a micro-plugin to copy /cache/pages/sidemenu.html to /output/real_sidemenu.html as-is. |
Wouldn't it still be nice if it would be possible to instruct |
That’s going to be slightly tricky, but we could skip the lxml part. This would have side effects (like the possibility of broken HTML in output or URL_TYPE effectively being completely ineffective, and I don’t want any new not server root bugs) Unless we could tell lxml to output fragments, if that’s possible. |
From here: http://stackoverflow.com/questions/3443831/python-and-elementtree-return-inner-xml-excluding-parent-element it looks it can be done like this: parser = lxml.html.HTMLParser(remove_blank_text=True)
doc = lxml.html.fragment_fromstring(data, parser)
doc.rewrite_links(lambda url: rewrite(url))
for obj in list(doc.xpath('(//img|//source)')):
if 'srcset' in obj.attrib:
...
data = (body.text or '').encode('utf-8') + ''.encode('utf-8').join([lxml.html.tostring(child, encoding='utf-8', method='html') for child in body.iterchildren()]) So essentially parsing the document is changed a little ( |
That |
That was the only thing I noticed in a very limited minimal test. So it could be that worse things happen :) |
It actually seems to always add a |
(So |
Useful for HTML fragments inserted via JavaScript that contain links.
Use case: nikola-plugins-v2 and its side menu that can be changed
without rebuilding all pages.