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

Different authors for different posts #662

Open keilw opened 3 years ago

keilw commented 3 years ago

At the moment every post has just one author based on the meta.author property. Would it be possible to also have an (optional) property on a post like author=<authorname> that is used where present and if not given, the default author from the metadata is used instead?

jonbullock commented 3 years ago

Yeah that's possible, you'll want to do something similar to this: https://github.com/jbake-org/jbake-example-project-freemarker/blob/master/templates/header.ftl#L5

manikmagar commented 3 years ago

Here is an example of doing that exact way -

https://github.com/manikmagar/jbake-future-imperfect-template/blob/master/templates/post/header.ftl#L21

 <span class="author"/><span class="name">${post.author!config.site_author}</span><img src="${content.rootpath}${post.author_avatar!config.site_author_avatar}" alt="${post.author!config.site_author}" /></span>
ge0ffrey commented 3 years ago

Freemarker has an elvis operator (AKA defaultIfNull operator), here's how I use it in my base.ftl:

<link content="${(content.canonical_url)!config.canonicalBaseUrl + "/" + content.uri}" rel="canonical">