Jekyll has replace
and replace_first
but doesn’t have replace_last
.
I’m trying to add a backlinking feature to show which posts have linked to the current post, and I want to show the sentence in which that link appears as an excerpt. I came up with this:
{%- for post in site.posts -%}
{%- if post.url != page.url -%}
{%- if post.content contains page.url -%}
{%- assign precerpt = post.content | split: page.url | first | replace_last: ". ", "~~~" | split: "~~~" | last -%}
{%- assign postcerpt = post.content | split: page.url | last | replace_first: ".", ".~~~" | split: "~~~" | first -%}
<p>{{ precerpt | append: postcerpt }}<p>
postcerpt
is behaving how I would like it to, but precerpt
doesn’t because of the replace_last
filter. The output might have some remnants of the anchor element but I can deal with that when I get there.
I tried looking into the Jekyll files to see if I could find a file with the liquid filters defined so that I could simply paste in the Shopify replace-last
definition but I couldn’t find it.
Any ideas? Thanks!