jbake-org / jbake

Java based open source static site/blog generator for developers & designers.
http://jbake.org
MIT License
1.12k stars 326 forks source link

Add a way to get the abstract instead of the full post. #344

Open pilhuhn opened 7 years ago

pilhuhn commented 7 years ago

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)

jonbullock commented 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.

SiddheshRane commented 7 years ago

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

jonbullock commented 7 years ago

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.

manikmagar commented 7 years ago

I usually add a summary metadata attribute that is then rendered inside the template.

moaxcp commented 6 years ago

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.