Skip to content
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

Include item description in the "pretty feed" XSL #29

Open
philgyford opened this issue Oct 23, 2021 · 3 comments
Open

Include item description in the "pretty feed" XSL #29

philgyford opened this issue Oct 23, 2021 · 3 comments

Comments

@philgyford
Copy link

philgyford commented Oct 23, 2021

My RSS feeds include a short plain text description of each post in the <description> element within each <item>.

These aren't rendered by the current pretty-feed-v3.xsl file.

I've added something like this, between the item title and Published date:

<p class="mb-0">
  <xsl:choose>
    <xsl:when test="string-length(description) &gt; 200">
      <xsl:value-of select="substring(description, 0, 200)" />…
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="description" />
    </xsl:otherwise>
  </xsl:choose>
</p>

This displays the entire <description> if it's 200 characters or fewer, otherwise displays the first 200 characters followed by an ellipsis. (200 is just arbitrary.) e.g.:

Screenshot 2021-10-23 at 16 22 01

But I think some people have the entire HTML blog post within <description>, between <![CDATA[ and ]]>. This might be problematic if it's truncated mid-tag, or between opening and closing tags? Or maybe the HTML itself would be visible?

AFAIK there isn't a way to detect if the description starts with ![CDATA[ or not, so I'm not sure if this idea can be reliably generalised.

But, given I know my feeds only have a brief plaintext description, I've gone with the above.

@CanRau
Copy link

CanRau commented Dec 18, 2021

Can't get HTML working

tried

<xsl:value-of select="description" disable-output-escaping="yes" />
<xsl:copy-of select="description" disable-output-escaping="yes" />

bot with and without disable-output-escaping="yes"

also tried using

const escapeHTML = (str: string) =>
  str.replace(
    /[&<>'"]/g,
    (tag) =>
      ({
        "&": "&amp;",
        "<": "&lt;",
        ">": "&gt;",
        "'": "&#39;",
        '"': "&quot;",
      }[tag]),
  );

found on SO

also tried with and without CDATA <description><![CDATA[${html}]]></description>

what am I doing wrong?

@philgyford
Copy link
Author

I'm not much of an expert, but happy to have a look. Can you post your feed? Either a link to it or the XML (maybe just include a single item in it).

@CanRau
Copy link

CanRau commented Jan 1, 2022

Sorry for the late reply, I actually stopped using pretty feed at all, thanks for your offer tho 🙏 much appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants