Open pilhuhn opened 7 years ago
It should be possible to extract the preamble from the Asciidoctor AST classes... need to think how this can be exposed via the data model in a way that works regardless of the content type though.
Hi, I have already done this using my thymeleaf based template. For a preview visit my blog. The source code snippet which does this is available here.
The basic idea is to just search for the first <p>
and get a substring between the first <p>
and </p>
. This method works for a large class of content types, whether asciidoc with or without a preamble, markdown or raw html. The thymeleaf snippet itself is portable and doesnt depend on the rest of my theme. And the method can be used in freemarker and groovy too, though I havent tried it
Thanks for sharing that alternative approach @SiddheshRane
You can also define an additional metadata value in the header that you can then reference in the template files. But that's because I don't tend to summarise my post in the first paragraph though.
I usually add a summary
metadata attribute that is then rendered inside the template.
I did something similar to @SiddheshRane in index.ftl
<p>${post.body?keep_before("<h")}</p>
Get everything before the first header. Not sure if this is the best though. It depends on how you write posts. If you don't use headers then the entire post will show up.
JBake (at least with AsciiDoctor) treats the first paragraph(*) of a blog post differently than the reminder of the body. With AsciiDoctor/Freemarker those end up in a
<div id="preamble"/>
It would be good to expose that part to templates, so that the main blog page could only feature abstracts and then link to the details. Right now with
context.body
the full text from the rendering engine is returned.*) (That is the text until the first == header)