Skip to content
This repository has been archived by the owner on Aug 28, 2019. It is now read-only.

index shows full posts not except #194

Open
spsharman opened this issue Apr 7, 2018 · 3 comments
Open

index shows full posts not except #194

spsharman opened this issue Apr 7, 2018 · 3 comments

Comments

@spsharman
Copy link

How do I stop the index displaying the entire post? I just want to show an excerpt - for example the first paragraph - thanks

@Purpzie
Copy link

Purpzie commented May 11, 2018

I got it working after following this tutorial.

  1. 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 %}
  1. 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>' }}
  1. Then add this to _sass/elements.html:
 a.anchor{
    display: block;
    position: relative;
    top: -99px;
    visibility: hidden;
 }
  1. 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.

@mikaelkrief
Copy link

@Purpzie Thanks for the solution, That works fine !!!!!

@justin-vanwinkle
Copy link

@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.

warningmonster added a commit to warningmonster/warningmonster.github.io that referenced this issue Oct 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants