From d53acbb3f8557583a1a03e92ec7626ccc63f5264 Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Fri, 23 Feb 2018 09:24:54 -0500 Subject: [PATCH] Document the special comment after Org-generated TOC --- doc/ox-hugo-manual.org | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/doc/ox-hugo-manual.org b/doc/ox-hugo-manual.org index 8958e614..7dc62119 100644 --- a/doc/ox-hugo-manual.org +++ b/doc/ox-hugo-manual.org @@ -1407,6 +1407,39 @@ See Org manual [[https://orgmode.org/manual/Table-of-contents.html][Table of Con /Note that =ox-hugo= does not support =#+toc: listings= and =#+toc: tables=./ +**** Excluding Org-generated TOC from Hugo summaries +As mentioned above, if you use Hugo-generated TOC, the advantage is +that the TOC is not inserted physically in the content Markdown +file. + +But with the Org-generated TOC, it *will* be. The disadvantage of that +is that the =.Summary= in Hugo will consider the TOC! So your TOC will +show up in places you don't expect.. like summaries in post lists, in +twitter cards, etc. + +But.. there's a way to fix that, because =ox-hugo= inserts a special +comment ~~ at the end of the inserted TOC. + +Using that and, the Go Template function [[https://gohugo.io/functions/split/][=split=]], you can remove the +TOC from the summaries. [[https://github.com/kaushalmodi/hugo-bare-min-theme/blob/2c7a2ef3c0c72e83036b9d029d1e7fb1604f278c/layouts/_default/summary.html#L26-L33][Here's an example]] of how I remove the TOC in +the =summary.html= layout for the =ox-hugo= test site. I have pasted +the same below: +#+begin_src html +{{ $summary_splits := split .Summary "" }} +{{ if eq (len $summary_splits) 2 }} + + {{ index $summary_splits 1 | safeHTML }} +{{ else }} + + {{ .Summary }} +{{ end }} +#+end_src + +/Note that you would need this snippet in all the layout files where +you do not intend to have TOC included in the summary. It might even +be worthwhile saving this snippet as a Hugo [[https://gohugo.io/templates/partials/][=partial=]], and using that +everywhere./ *** Table Styling :PROPERTIES: :EXPORT_FILE_NAME: table-styling