Open spsharman opened 6 years ago
I got it working after following this tutorial.
Put the following in index.html instead of {{ post.content }}
:
{{ post.excerpt }}
<!-- Whether or not to display the "read more" button -->
{% capture content_words %}{{ post.content | number_of_words }}{% endcapture %}
{% capture excerpt_words %}{{ post.excerpt | number_of_words }}{% endcapture %}
{% if excerpt_words != content_words %}
<a href="{{ post.url }}#read-more" class="btn btn-info">Read More</a>
{% endif %}
Then, instead of just {{ content }}
in your _layouts/post.html you should put:
{{ content | replace: '{{ site.excerpt_separator }}', '<a class="anchor" id="read-more"></a>' }}
Then add this to _sass/elements.html:
a.anchor{
display: block;
position: relative;
top: -99px;
visibility: hidden;
}
Finally, all you need to do is specify in _config.yml what you'll use to separate the excerpt from the rest of the content. Personally, this is what I use.
excerpt_separator: "<!--break-->"
If you want to override the excerpt entirely, specify the excerpt
option in a post's YAML front matter and it will be used instead.
@Purpzie Thanks for the solution, That works fine !!!!!
@Purpzie Thanks for sharing. I don't believe the post.html and sass changes are necessary -- what was the intention with those?
Only making the change to index.html and _config.yml will do the trick for this.
How do I stop the index displaying the entire post? I just want to show an excerpt - for example the first paragraph - thanks