jbake-org / jbake

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

Export header properties as asciidoc attributes #348

Open romain-grecourt opened 7 years ago

romain-grecourt commented 7 years ago

I would like to use an asciidoctorj extension and drive it with properties in the jbake content header. When using asciidoctor.attributes.export=true, only jbake properties are exported.

I came across the following code snippet from org.jbake.parser.AsciidoctorEngine:

 final AttributesBuilder attributes = attributes(config.getStringArray(Keys.ASCIIDOCTOR_ATTRIBUTES));
    if (config.getBoolean(Keys.ASCIIDOCTOR_ATTRIBUTES_EXPORT, false)) {
        final String prefix = config.getString(  Keys.ASCIIDOCTOR_ATTRIBUTES_EXPORT_PREFIX, "");
        for (final Iterator<String> it = config.getKeys(); it.hasNext();) {
            final String key = it.next();
            if (!key.startsWith("asciidoctor")) {
                attributes.attribute(prefix + key.replace(".", "_"), config.getProperty(key));
            }
        }
    }

Would it be possible to consider exporting context.getContents() ?

jonbullock commented 7 years ago

Hi Romain

If you're using AsciiDoc formatted content then you don't need to define the properties in a JBake specific metadata header and export them so Asciidoctor is aware of them. You can define the required properties as attributes in the AsciiDoc content itself.

When it comes to using an AsciidoctorJ extension, you'll have to manually add it to the classpath for the time being. Making this easier is something we plan on addressing in 2.6.0.

romain-grecourt commented 7 years ago

Thanks for the prompt response ! I quickly realized that I could use asciidoc content to drive my extension.

I'm actually using the jbake maven plugin, and putting the extension as a plugin dependency works.

jonbullock commented 7 years ago

Ah OK, be interested to see your POM if it's public somewhere? As I'd like to include details on how to do this in the docs.