cryogen-project / cryogen-core

Cryogen's core
Eclipse Public License 1.0
69 stars 62 forks source link

Parse page and post content via selmer #139

Closed danplisetsky closed 3 years ago

danplisetsky commented 4 years ago

(cont. from #138)

Another feature that I wanted to see (which actually exists in Jekyll) is being able to template not only html but md content, too.

Scenario

I have my email in config.edn. I want to show it on my Contact page.

Changes

This pull request adds the ability to use Selmer templating engine in content files. The scenario above is now doable:

contact.md

 <i class="fas fa-envelope"></i> {{ email|email }}

Breaking change?

Potentially, but it's unlikely that many have been using Selmer's syntax verbatim in their content files. Still, it's a breaking change.

Docs

Docs will require updating to reflect this new change.

lacarmen commented 4 years ago

Potentially, but it's unlikely that many have been using Selmer's syntax verbatim in their content files. Still, it's a breaking change.

Let's put this behind a config flag and default to false then 😄

danplisetsky commented 4 years ago

Good point. Don't have a good name for the flag, though. 😄 Something like :parse-content?, maybe?

lacarmen commented 4 years ago

:parse-content-with-selmer?? it's a bit wordy but being more descriptive is always better

danplisetsky commented 4 years ago

Yep, that works. I'll update the PR later this week

danplisetsky commented 4 years ago

updated the PR and the docs: https://github.com/cryogen-project/cryogen-docs/pull/31

I'll get to the other PR once we've dealt with this one (:

holyjak commented 4 years ago

A feature flag is good as people that have lot of code samples could very easily end up with selmer syntax in their posts.

holyjak commented 3 years ago

@danplisetsky I got this idea, what about replacing this very concrete case of parsing with selmer with a more general and flexible solution that would allow any custom pre-processing of the content? In the same way that :extend-params-fn and :update-article-fn already allow some customization.

Then you could write something like

(core-compiler/compile-assets-timed
     {:postprocess-article-html-fn
      (fn postprocess [article params]
        (update article :content selmer.parser/render params))})

And we would call it perhaps from htmlize-content, extracting the :post or :page and passing it in as the article (and then putting it back). For :posts we would map it over the posts.

What do you think?

danplisetsky commented 3 years ago

@holyjak sounds good to me. I don't have much time to work on this right now, unfortunately.

If the change you've suggested works for @lacarmen, feel free to amend this PR if you get the chance.

ieugen commented 3 years ago

This feature looks interesting. Would this be usable in asciidoc or other template engines as well?

holyjak commented 3 years ago

This runs after the raw markup is processed to html, before the html is written to a file. So it works for any markup. The only template engine supported by Cryogen is Selmer, I believe.

holyjak commented 3 years ago

Replaced by #152

holyjak commented 3 years ago

@danplisetsky could you perhaps try whether https://github.com/cryogen-project/cryogen-core/pull/152 (see also the example code in cryogen-project/cryogen-docs#39) satisfies your needs?