Skip to content

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

@madranet

Description

@madranet

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions