cryogen-project / cryogen-core

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

Add ability to compile random html #138

Closed danplisetsky closed 2 years ago

danplisetsky commented 4 years ago

While migrating my blog from Jekyll to Cryogen, I've encountered a few scenarios I wanted Cryogen to support. If they could be useful to others, I'd love to push them upstream.

Scenario

I'd like to have my 404 page, for example, to retain all the usual navigation elements from my base.html. See examples here, here and here

Changes

This pull request adds the ability to compile (i.e., to run through selmer's render-file) random html files as specified by the user.

Breaking change?

No, since the additional keys are optional and the default value of :copy-html replicates old behaviour.

Docs

Docs will require updating. Specifically, the configuration page and the directory structure page that shows the diagram with 404.html not extending base.html

Note

I'm new to Clojure, so any notes on how to make this pull request better are appreciated!

@lacarmen What do you think?

lacarmen commented 4 years ago

Sorry for taking so long to get back to you.

This feature might not be necessary to achieve what you want. I've done this before by doing the following: 1) Create the html page in your themes/<theme>/html directory. Include the usual {% extends "/html/base.html" %} stuff. 2) Create a file under content/{md|asc}/pages with the same name. (eg. 404.html for step 1 and 404.md for step 2) 3) Set the layout of this new page to the name of your newly added html page.

Examples:

404.html

{% extends "/html/base.html" %}
{% block content %}
<div>This is my special 404 page </div> 
{% endblock %}

404.md

{:title "404"
 :layout :404}

This page content will never be seen!

If you don't include {{page.content|safe}} somewhere in your 404.html then the contents from the .md file won't show up.

As for :copy-html, I'd rather not add another key as we already have theme-resources. The html/404.html could be removed from the concat in copy-theme-resources and theme-resources can default to ["html/404.html"].

danplisetsky commented 4 years ago

Hey, no worries.

I think the problem with the approach that you're suggesting is that it's not going to work if you set :clean-urls to :trailing-slash, which is what I'm using. (It's going to emit a 404 folder, which is not what we want.)

As for :copy-html, you're right, I missed that we can use it instead of adding another key.

I still think :compile-html is preferable as it allows us to add html files we want to run through selmer without polluting the content folder.

lacarmen commented 4 years ago

It's going to emit a 404 folder, which is not what we want.

without polluting the content folder.

Good points 😄 I'm fine with adding :compile-html - just wanted to see if we could achieve what you wanted without more features.

Can you update your PR when you find the time?

danplisetsky commented 4 years ago

👍 Will probably get to it before end of week. I'll submit a PR for the docs, too.

lacarmen commented 4 years ago

I'll submit a PR for the docs, too.

Excellent! I love it when contributors update the docs too 🥰

holyjak commented 3 years ago

@danplisetsky ping :-)

holyjak commented 3 years ago

Actually the problem with :trailing-slash can now be bypassed by leveraging :update-article-fn. So in the 404.md you would have something like

{:title "Awesome!" :my/uri "404.html"}

and would use like this:

(cryogen-core.compiler/compile-assets-timed
  {:update-article-fn
   (fn update-article [{:my/keys [uri] :as article} config]
       (if uri
         (assoc article :uri uri)
         article))})
holyjak commented 2 years ago

Hi @danplisetsky! Do you want to get this PR in or not anymore? If not then I will close it soon.

danplisetsky commented 2 years ago

Hi @danplisetsky! Do you want to get this PR in or not anymore? If not then I will close it soon.

Hey @holyjak, I think it makes sense to close this one