getnikola / nikola

A static website and blog generator
https://getnikola.com/
MIT License
2.6k stars 445 forks source link

Ampersand in first paragraph → og:description: garbage on the page top #3655

Closed eudoxos closed 1 year ago

eudoxos commented 1 year ago

Environment

Python Version: 3.10.6

Nikola Version: 8.2.3

Operating System: Ubuntu 22.04 LTS

Description:

First paragraph of the .rst page is used as og:description if description field is not provided in metadata. Presence of certain characters in the first paragraph (ampersand, in my case), leads to the field containing garbage.

Beginning of the .rst file without ampersands

.. title: Visualization

Woo has a built-in 3d view made for detailed inspection of simulations and seeing what matters. It supports displacement rotation scaling, selecting inspecting objects and many other things.

Raytracing
~~~~~~~~~~

image

Now the same text with ampersands:

.. title: Visualization

Woo has a built-in 3d view made for detailed inspection of simulations and seeing what matters. It supports displacement & rotation scaling, selecting & inspecting objects and many other things.

Raytracing
~~~~~~~~~~

image

This is a part of the HTML source:

<meta property="og:description" content="Woo has a built-in 3d view made for detailed inspection of simulations
and seeing what matters. It supports displacement rotation &lt;span class=" amp><script>document.write('<script src="http://'
            + (location.host || 'localhost').split(':')[0]
            + ':8000/livereload.js?snipver=1"></'
            + 'script>')</script>
        </head><body><p>&amp; scaling,
selecting <span class="amp">&amp;</span> inspecting objects and many other things.

Rayt”&gt;
<meta property="og:type" content="article">
<meta property="article:published_time" content="2022-12-30T13:20:40+01:00">

A workaround is to explicitly write .. description: ... field in the page metadata.

Kwpolska commented 1 year ago

I cannot reproduce with a clean Nikola install and the default theme:

<meta property="og:site_name" content="Demo Site">
<meta property="og:title" content="Welcome to Nikola">
<meta property="og:url" content="https://example.com/posts/welcome-to-nikola/">
<meta property="og:description" content="Woo has a built-in 3d view made for detailed inspection of simulations and seeing what matters. It supports displacement &amp; rotation scaling, selecting &amp; inspecting objects and many other things.

Rayt">
<meta property="og:type" content="article">
<meta property="article:published_time" content="2012-03-30T23:00:00-03:00">
<meta property="article:tag" content="blog">
<meta property="article:tag" content="demo">
<meta property="article:tag" content="nikola">
<meta property="article:tag" content="python">

Are you using any non-standard themes/plugins/filters?

eudoxos commented 1 year ago

Ah, okay, it was filters.typogrify... Without it, everything is rendered fine.

Kwpolska commented 1 year ago

If you want to keep using typogrify and don’t want to manually write descriptions wihout &, you can use typogrify_custom without the typo.amp plugin (that introduces the breakage).