plugins icon indicating copy to clipboard operation
plugins copied to clipboard

[static_comments] rel=nofollow

Open schlatterbeck opened this issue 6 years ago • 3 comments

Static comments currently render links without a 'rel="nofollow"' stanza in the generated tag. Wordpress by default uses rel="external nofollow" which I wanted to keep after converting to nikola. Especially if the commenter specifies an URL we don't want search machines to index those. I've modified the comment template (see patch below) for the author URL. But for URLs in the text there doesn't seem to be a way to specify nofollow for the generated link. This is probably a shortcoming of the REST compiler or is there a way to specify nofollow for a link that I didn't find yet?

Patch:

--- templates/jinja/static_comments_helper.tmpl.old     2019-04-14 13:57:43.755064023 +0200
+++ templates/jinja/static_comments_helper.tmpl 2019-04-14 13:58:39.754962650 +0200
@@ -13,7 +13,7 @@
           <a name="comment-{{ comment.id }}"></a>
           {%if comment.author is not none %}
             {{ messages("{0} wrote on {1}:", lang).format(
-              '<span class="author">' ~ ('<a href="{0}">{1}</a>'.format(comment.author_url|e, comment.author|e) if comment.author_url is not none else (comment.author|e)) ~ '</span>',
+              '<span class="author">' ~ ('<a href="{0}" rel="external nofollow">{1}</a>'.format(comment.author_url|e, comment.author|e) if comment.author_url is not none else (comment.author|e)) ~ '</span>',
               '<span class="date">' + comment.formatted_date(date_format) + '</span>'
             ) }}
           {% endif %}

schlatterbeck avatar Apr 14 '19 12:04 schlatterbeck

I guess one has to parse the HTML for this and add rel=nofollow manually. This can probably be done similarly to link rewriting (absolute -> relative) in Nikola itself.

felixfontein avatar Apr 14 '19 13:04 felixfontein

Can you point me to the relevant code in Nikola? Then I would try to come up with a patch. That said: Wouldn't it be better to add additional annotations to the link specification in REST, e.g we have the image tag:

.. image:: magnetic-balls.jpg :width: 40pt

similar to this we could add properties to a link

Nikola_ is linked here

.. _Nikola: https://getnikola.com/ :rel: external nofollow

I don't know if this is syntactically possible. It seems that Sphinx has added support for nofollow in some recent release according to the release announcement, I've not looked into the code, though. So maybe it's possible to reuse the syntax they use, provided it makes sense in other contexts?

schlatterbeck avatar Apr 15 '19 07:04 schlatterbeck

Adding something in ReST won't solve the problem for other compilers, and you still have to modify all comments manually. It's better to let the plugin do this automatically.

For how to modify HTML, see https://github.com/getnikola/nikola/blob/master/nikola/nikola.py#L1387-L1399 (the is_fragment branch is the relevant part). You can probably iterate over all links similar to here: https://github.com/getnikola/nikola/blob/master/nikola/nikola.py#L1409-L1414

felixfontein avatar Apr 15 '19 18:04 felixfontein