Help requested for Excerpts

I’ve tried some to get Excerpts work. I’d prefer a begin and an end tag. I use the minima theme and in the _config.yaml I’ve added:

excerpt_separator: “<!–more–>”

but excerpts do not show up as I expected them underneath the blog link (https://warbe-maker.github.io/.

Thanks for any help

Looking at the blog source, I don’t see any <!--more--> separators in the blog posts. You’ll need to add a separator to each post.

I took them away because I couldn’t find the correct way using the separator. Sound stupid but that’s it.

Maybe I should be more precise.

I add for example after the front matter

.----

Excerpt 1

First header

And “Excerpt 1” appears in the blog after the toc.

And because this is not the intended place I’ve removed both lines. I think the html is the problem. But I am too insecure to touch it. Now I am trying with an explicit

excerpt_separator: <!--more-->

in the front matter. But this didn’t help either.

The excerpt is usually for displaying a small snippet of the page or post to display it elsewhere. By default, Jekyll uses the first paragraph (the first character of text, then the last character of text before a carriage return).

For example, let’s say you have two blog posts that look like this:

---
title: My bike ride today
layout: blogpost
date: 2021-04-25
---
Today I managed to get on a new biking trail and wanted to share that with you. You know the one I'm talking about, that winds its way to the ocean.

As you know, I mostly ride along this other trail, but today...
---
title: How to cook crispy french fries
layout: blogpost
excerpt_separator: <!--more-->
date: 2021-04-26
---
During a pandemic, you may not have a chance to get to that restaurant you really like that makes super crispy french fries. 

When you order fries for delivery, they are soggy and no good. In this post, I am going to explain how to do it yourself! <!--more-->

First, you will need some peanut oil...

Now let’s say you have a web page that lists the excerpts from your posts. Let’s say you created a page called allposts.html. The code might look something like this:

---
title: All blog posts
layout: default
---

<h2>All my blog posts with their excerpts</h2>
{%- for post in site.posts  -%}
  <p>Title: {{ post.title }}</p>
  <p>Excerpt: {{ post.excerpt }}</p>
  <p></p>
{%- endfor- %}

The output will look something like this:

Title: My bike ride today
Excerpt: Today I managed to get on a new biking trail and wanted to share that with you. You know the one I’m talking about, that winds its way to the ocean.

Title: How to cook crispy french fries
Excerpt: During a pandemic, you may not have a chance to get to that restaurant you really like that makes super crispy french fries.

When you order fries for delivery, they are soggy and no good. In this post, I am going to explain how to do it yourself!

Assuming your _config.yml file does not contain a default excerpt setting, Jekyll defaults to setting the excerpt as the first paragraph. When you define a separator in your page or post like we did the second one, the excerpt continues until it sees the separator you defined, which in this case is the text <!--more-->.

I highly recommend you decide what you want to use for a separator and put it in your _config.yml file unless you really want to set a separator for each and every page or post. I actually use a period, so it just gives the first sentence, rather than the first paragraph, but you decide what works best for your situation.

For example, you can edit your _config.yml file and place a line anywhere in the code that reads:

excerpt_ separator: <!--more-->

Since you modified the config file, you will need to stop and build Jekyll for this change to take effect.

Using the previous examples, here is what your new blog posts might look like:

---
title: My bike ride today
layout: blogpost
date: 2021-04-25
---
Today I managed to get on a new biking trail and wanted to share that with you. <!--more-->You know the one I'm talking about, that winds its way to the ocean.

As you know, I mostly ride along this other trail, but today...
---
title: How to cook crispy french fries
layout: blogpost
date: 2021-04-26
---
During a pandemic, you may not have a chance to get to that restaurant you really like that makes super crispy french fries.<!--more-->

When you order fries for delivery, they are soggy and no good. In this post, I am going to explain how to do it yourself! 

First, you will need some peanut oil...

Notice I removed excerpt_separator: <!--more--> from the YAML front matter of the first post. I don’t need it there since I have a default set in the _config.yml file now (although I can add one for one-off purposes). Notice both posts use in-line text to determine where the excerpt ends.

The new output will look something like this:

Title: My bike ride today
Excerpt: Today I managed to get on a new biking trail and wanted to share that with you.

Title: How to cook crispy french fries
Excerpt: During a pandemic, you may not have a chance to get to that restaurant you really like that makes super crispy french fries.

Notice how the first biking post no longer shows the whole paragraph. That is because the <!--more--> code displays at the end of the first sentence. Notice also that the second french fries post shows the first paragraph, because I moved the <!--more--> text to end there.

Hope this helps.

Also, in the future, please put all your code in reverse apostrophes. When you are doing multiple lines, select the code and press the </> button in the code editor, or just start and finish the code with three reverse apostrophes (```) and the code will format nicely.

Thanks!

1 Like

In the Minima theme, the display of excepts is controlled by the site.show_excerpts variable, so the first step is to define it in _config.yml:

show_excerpts: true

After that change, the home page will display each post’s default excerpt (the first paragraph of the post). If the first paragraph is not enough, you can use the excerpt_separator to include more/less in the excerpt.

1 Like

Does it help? Yes an no. I’ve found in my
post.html:

{% if post.excerpt %}
   {{ post.excerpt }}
{% endif %}

It is not under the title paragraph (there isn’t even one like the one in your example) but I guess it’s in the right place. Now the question is, what does this if mean? Does it mean I have to write in the front matter something like excerpt: true ???
Should I remove the if?

Regarding the “stop and restart” which is often mentioned I have to say that is nothing I could do since I am not running a local version of my blog. I edit in my repo clone either on my mobile using PockeGit or on my PC using Github-Windows. So I edit, commit and push. That’s it. And after a couple of minutes I can see the result.

I leave the separator as default of "\n\n".

Which means when there is an empty line after my first paragraph (or image), then the excerpt ends.

I haven’t had to override it.

You can use something like the more bit. Or a span. But only if you artificially wanted an excerpt to say be only a portion of the first paragraph (its simpler just to make that it’s own line and keep the default).
Or if you want to stretch your excerpt to two paragraphs, which is not a good idea for length.


The advice above for setting a config level override is good.

You might need to quote the value to avoid any funny YAML evaluation

excerpt_separator: "<!--more-->"

Another idea is you can set up a description text field on the frontmatter. Which might be the first sentence of your body content or maybe you write a summary instead.

Then use that instead of an ex excerpt.

---
title: Bike riding on sunny days
description: This sums up my post, about fun in the sun.
---

Then use a for loop going over posts.

{{ p.title }}
{{ p.description }}

I would not call the field “excerpt” in case it breaks things but summary or description are apt.

As a general practice, I assume people are running Jekyll locally and give you a reminder to stop and rebuild if I’m recommending a to _config.yml. You are doing that in your own way by modifying the code and having GitHub rebuild it for you.

In the future, if I say to stop and rebuild/restart, you can just ignore it for your specific process :slight_smile:

Try removing the if statement and just check, I suppose.

I loved the idea with the description: … in the front matter and went for it. Because all html statements (guess it’s liquid) use page. prefix I did this as well. My post.html in the layouts folder no looks

<header class="post-header">
    <h1 class="post-title p-name" itemprop="name headline">{{ page.title | escape }}</h1>
    <p class="post-meta">
      {%- assign date_format = site.minima.date_format | default: "%b %-d, %Y" -%}
      <time class="dt-published" datetime="{{ page.date | date_to_xmlschema }}" itemprop="datePublished">
        {{ page.date | date: date_format }}
      </time>
      {%- if page.modified_date -%}
        ~ 
        {%- assign mdate = page.modified_date | date_to_xmlschema -%}
        <time class="dt-modified" datetime="{{ mdate }}" itemprop="dateModified">
          {{ mdate | date: date_format }}
        </time>
      {%- endif -%}
      {%- if page.author -%}
        • {% for author in page.author %}
          <span itemprop="author" itemscope itemtype="http://schema.org/Person">
            <span class="p-author h-card" itemprop="name">{{ author }}</span></span>
            {%- if forloop.last == false %}, {% endif -%}
        {% endfor %}
      {%- endif -%}</p>
       <p>{{ page.description }}</p>
  </header>

But believe it or not: Not successful. To me it looks as it should work but it doesn’t. I am open for any suggestions whether they directly lead to the final solution or not. So thanks a lot for all helping me out.

That was obviously wrong because the description shows up in the post. Click! Got something! The html I need to modify is yet not in my directory. I will have to copy it from the jekyll repo. It definitely requires a long breath when one knows as little as me.
There are default.html, home.html, and page.html. For me a challenge to figure out which one is now the one to copy and modify. No one yet told me that the html to modify is not in my repo :frowning:

home.html seems to be the one I require! Now I have to figure out how to copy it from the jekyll minima repo into my repo (never managed this before).
Then the game will start again.

I had a few minutes this morning to download your site and see what is going on. You are almost there! Here is what I did so you can try it on your own site. I did this for one file, since you are using the <!--more--> option there.

  1. Edit to the following post: 2021-01-16-Common-VBA-Error-Services.markdown
  2. Remove the excerpt: true yaml front matter and save
  3. At the root of your site, create a new file (just so we don’t have any other code getting in the way). Call the new file posts-and-excerpts.html
  4. In the new file, add the following code:
---
layout: default
title: Posts and excerpts
---

<h2>This is a list of posts with excerpts</h2>
{% assign posts = site.posts | where: "title", "Common VBA Error Services" %}
{% for post in posts %}
    <p>Title: {{post.title}}</p>
    <p>Excerpt: {{post.excerpt}}</p>
{% endfor %}
  1. Save the file
  2. Commit and push your changes

The output will look like this:

This is a list of posts with excerpts

Title: Common VBA Error Services

Excerpt:

A comprehensive error services approach inspired by the best of the web. Not a tutorial but a complete description of the services and how to use them.

Does that solve the problem?

The point is that I"ve found the responsible code part in the home.html which I copied from the minima repo (minima is the theme I use. The snippet there is

{%- if site.show_excerpts -%}
          {{ post.excerpt }}
 {%- endif -%}

I would prefer using what is already prepared with the minima theme by default.
So the only remaining question now is: How do I fullfil the site show_excerpts condition ?

See my reply from yesterday where I provided a link to the documentation and sample code:

1 Like

Done!!! Problem solved! I had to add the <!–more–> tag to each post, including those without an excerpt paragraph because the show_excerpt is a site global setting. Thanks to all who contributed.