How to replace the last <p> tag in Jekyll

On my index.html page, I want to add "..." after post.excerpt. An idealized way is to use code {{ post.excerpt |replace_last:'</p>', '……</p>' }}, but the filter replace_lastis undefined. So how can I do this in jekyll? thanks.

+4
source share
2 answers

In my opinion, the best way is CSS:

.excerpt p:last-child::after {
    content: '..';
}

This adds a ".." to the last paragraph of the afterpsuedo-element inside the excerpt div.

<div class="excerpt">
    <p>Normal paragraph.</p>
    <p>Paragraph with trailing ellipsis.</p>
</div>

If you need to do this with Jekyll, you can use a filter sliceto disable the end </p>and a filter appendto add '...</p>'to the end. This will not work if your passage does not end with a paragraph.

+5

p post.excerpt, "...". , " " p.

<p>
  {{ post.excerpt | strip_html | append: "..." }}

  {% if post.excerpt != post.content %}
    <a href="{{ post.url | prepend: site.baseurl }}"> >></a>
  {% endif %}
</p>
0

Source: https://habr.com/ru/post/1612216/


All Articles