Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{{ .Summary }} includes unwanted text in certain circumstances #1503

Open
madranet opened this issue Oct 17, 2015 · 15 comments
Open

{{ .Summary }} includes unwanted text in certain circumstances #1503

madranet opened this issue Oct 17, 2015 · 15 comments

Comments

@madranet
Copy link

@madranet madranet commented Oct 17, 2015

When using {{ .Summary }} within a template, traditional markdown image tags [and their associated title and alt attributes] are ignored when the summary is created. So in a post beginning with:

![Beam me up Scotty!](/images/kirk.jpg "The Captain")

Lorem ipsum dolor sit amet, consectetur adipiscing elit...[etc]

The summary is correctly rendered as:

Lorem ipsum dolor sit amet, consectetur adipiscing elit...[etc]

However, if the {{% figure %}} shortcode is used to add images:

{{% figure src="/images/kirk.jpg" alt="Beam me up Scotty!" title="The Captain" %}}

Lorem ipsum dolor sit amet, consectetur adipiscing elit...[etc]

Then the title attribute is also included in the generated summary:

The Captain Lorem ipsum dolor sit amet, consectetur adipiscing elit...[etc]

This is also the case when caption is used:

{{% figure src="/images/kirk.jpg" alt="Beam me up Scotty!" caption="The Captain" %}}

Lorem ipsum dolor sit amet, consectetur adipiscing elit...[etc]

also produces:

The Captain Lorem ipsum dolor sit amet, consectetur adipiscing elit...[etc]

Interestingly, when both title and caption are used, only the content of the caption attribute is included in the generated summary.

Also, if a post begins with a list, this is included in the generated summary as well:

* Blah Blah
* Waffle Waffle
* Drone Drone

Lorem ipsum dolor sit amet, consectetur adipiscing elit...[etc]

Generates the following summary:

Blah Blah Waffle Waffle Drone Drone Lorem ipsum dolor sit amet, consectetur adipiscing elit.

The same happens when a post begins with ## mardown headers ##. The content of these is also included in the generated summary.

All of the above make summaries generated by {{ .Summary }} quite messy, when posts do not start with a paragraph of text.

SUGGESTION: {{ .Summary }} should begin summarising from the first encountered <p> tag and should strip out any content between non text-markup tags.

@mattwoolnough
Copy link

@mattwoolnough mattwoolnough commented Oct 27, 2015

+1. Code blocks turn out quite poorly also. Not formatted in any way. Strip the code blocks out as suggested, or just stop the summary at the start of the code.

@erichiller
Copy link

@erichiller erichiller commented Oct 31, 2015

+1 Agreed- this seems the perfect solutions -- @mattwoolnough "Strip the code blocks out as suggested, or just stop the summary at the start of the code."

@qw3ry
Copy link

@qw3ry qw3ry commented Sep 1, 2016

I have a similar issue: My page is starting with a header:
# some title
and this header is included in .Summary, but only if I use the <!--more--> somewhere in the text.

This problem makes the "<!--more-->-feature" quite useless for me as the resulting web page looks awful.

@madranet
Copy link
Author

@madranet madranet commented Jan 3, 2017

Disappointed to see this still hasn't been addressed as of version 0,18

$ hugo version
Hugo Static Site Generator v0.18.1 BuildDate: 2016-12-29T17:12:41Z

2017-01-03_14-05-19

@ghost
Copy link

@ghost ghost commented Feb 6, 2017

I for one appreciate the simplicity of the automatic summary split. Its constraints have moved me to improve my layouts by refactoring items from the content more aptly expressed in front matter.

@stale
Copy link

@stale stale bot commented Dec 6, 2017

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Dec 6, 2017
@stale stale bot closed this Dec 27, 2017
@kleinschmidt
Copy link

@kleinschmidt kleinschmidt commented Oct 12, 2018

This is still an issue: including a fenced code block in the summary is, IMHO, lunacy. Perhaps an option to only include the first <p> would help?

@ghost
Copy link

@ghost ghost commented Nov 26, 2019

Is this issue not a point of concern anymore? It's been more than 4 years since this issue was opened. The summary looks messed up no matter which theme I use if I start my blog post with a title or other elements other than <p>.

@jtooker
Copy link

@jtooker jtooker commented Apr 2, 2020

I agree with @pointfourone. The "automatic" summary works well at removing images and tables, but it leaves headers in. If it ignored headers too (or if there was a site configuration variable to omit them), I think it would work quite well for me. Without it, I'm forced to copy the first paragraph or so into my front matter.

@madranet
Copy link
Author

@madranet madranet commented Apr 3, 2020

I agree with @pointfourone. The "automatic" summary works well at removing images

Summary doesn't remove images in all circumstances. See my original issue posting at the top of the thread.

@khayyamsaleem
Copy link

@khayyamsaleem khayyamsaleem commented May 4, 2020

Could there be a solution where you could use something like a "summary-ignore" shortcode to mark off content that you want to exclude from a summary?

@khayyamsaleem
Copy link

@khayyamsaleem khayyamsaleem commented May 4, 2020

envisioning something like:

{{% summary-ignore %}}
{{% figure src="/images/kirk.jpg" alt="Beam me up Scotty!" caption="The Captain" %}}
{{% /summary-ignore %}}

Lorem ipsum dolor sit amet, consectetur adipiscing elit...[etc]
@musm
Copy link

@musm musm commented Aug 9, 2020

Encountering the same problem here

@AngelCrawford
Copy link

@AngelCrawford AngelCrawford commented Aug 23, 2020

Same Problem. Hoped I could do a workaround with the "replaceRE" Function and Regex, but it didn't worked >.<

@AngelCrawford
Copy link

@AngelCrawford AngelCrawford commented Dec 31, 2020

As a workaround, I now create my own Summary-Split with a comment.

{{ $summarySplits := split .Content "<!--start-summary-->" }}
{{ if ge (len $summarySplits) 2 }}
    <!-- If content has the comment "start-summary", start there -->
    {{ index $summarySplits 1 | plainify | truncate 270 }}
{{ else }}
    {{ .Summary| markdownify | truncate 270 " [...]" }}
{{ end }}

In my index.md, where the content is at, I add the comment at my first <p>-Tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
10 participants