mmistakes / jekyll-theme-hpstr

A Jekyll theme with some tumble-log tendencies.
https://mmistakes.github.io/jekyll-theme-hpstr/
MIT License
980 stars 1.44k forks source link

index shows full posts not except #194

Open spsharman opened 6 years ago

spsharman commented 6 years ago

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

Purpzie commented 6 years ago

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 %}
  2. 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>' }}
  3. Then add this to _sass/elements.html:

    a.anchor{
    display: block;
    position: relative;
    top: -99px;
    visibility: hidden;
    }
  4. 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 commented 6 years ago

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

justin-vanwinkle commented 6 years ago

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