No TOC in Summary (with more comment marker)
tags: export-option toc summary endtoc more
Description/Summary
By default, Hugo will dump everything at the beginning of a post into
its .Summary (See Hugo content summaries). As TOC enabled using the
export option like toc:t is inserted at the beginning of a post, TOC
will be shown in that summary too!
In this example, the special comment more is used.
Content
By default, Hugo will dump everything at the beginning of a post into
its .Summary (See Hugo content summaries). As TOC enabled using the
export option like toc:t is inserted at the beginning of a post, TOC
will be shown in that summary too!
In this example, the special comment more is used.
ox-hugo’s Solution
#
ox-hugo helps prevent that with a workaround.. it inserts a special
HTML comment <!--endtoc--> after the TOC.
Snippet #
As the more comment is present, the summary_minus_toc.html partial
used for this test site ensures that only the content between
<!--endtoc--> and <!--more--> is considered as summary.
This partial needs to be used wherever the summary text is needed
(example: the Opengraph og:description meta tag).
Page (Debug)
| Page Variable | Value | |
|---|---|---|
| Name | "No TOC in Summary (with more comment marker)" | |
| Title | "No TOC in Summary (with more comment marker)" | |
| ResourceType | "page" | |
| Kind | "page" | |
| Section | "posts" | |
| Draft | false | |
| Type | "posts" | |
| Layout | "" | |
| Permalink | "https://ox-hugo.scripter.co/test/posts/no-toc-in-summary-with-more/" | |
| RelPermalink | "/posts/no-toc-in-summary-with-more/" | |
| Data |
| |
| NextPage | No TOC as toc set to nil | |
| PrevPage | No TOC in Summary (without more comment marker) | |
| NextInSection | No TOC as toc set to nil | |
| PrevInSection | No TOC in Summary (without more comment marker) |
Page Params (Debug)
| Key | Type | Value |
|---|---|---|
| draft | bool | false |
| iscjklanguage | bool | false |
| lastmod | time.Time | 2022-01-16 11:59:06 -0500 -0500 |
| tags | []string | "export-option" "toc" "summary" "endtoc" "more" |
| title | string | "No TOC in Summary (with more comment marker)" |
File Object (Debug)
| FileInfo Variable | Value |
|---|---|
| UniqueID | "42d4ff9ed643e9c143bef4e0cdd095b0" |
| BaseFileName | "no-toc-in-summary-with-more" |
| TranslationBaseName | "no-toc-in-summary-with-more" |
| Lang | "en" |
| Section | "posts" |
| LogicalName | "no-toc-in-summary-with-more.md" |
| Dir | "posts/" |
| Ext | "md" |
| Path | "posts/no-toc-in-summary-with-more.md" |