cryogen-project / cryogen-core

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

Adding `:posts` and `:pages` to params via :extend-params-fn does not behave as expected #156

Closed ieugen closed 3 years ago

ieugen commented 3 years ago

I was trying to make a page that displays articles and used compile-assets-timed {:extend-params-fn extend-params} . I found out that did not work as expected and I spent a few hours trying to figure it out.

Most changes are in this changeset https://github.com/ieugen/ieugen.ro/commit/2ced76497244a7ddac17ec10ddf8db6b87a314ce .

You can check out that commit and when doing lein ring server you should see that articles are not visible.

Sometimes, when the articles list is visible, no content is in the pages and posts.

(defn extend-params [params {:keys [pages posts] :as other-pages}]
  (let [tag-count (->> (:posts-by-tag other-pages)
                       (map (fn [[k v]] [k (count v)]))
                       (into {}))
        tags-with-count (update
                         params :tags
                         #(map (fn [t] (assoc t :count (tag-count (:name t)))) %))
        new-site-data (assoc tags-with-count :all-my-posts posts :all-my-pages pages)]
    new-site-data))

I found out that the code does not work if I pass :posts and or :pages keys. The content disappears.

I fixed it by passing other names, like :all-my-posts. It was not obvious and it behaved very strange.

holyjak commented 3 years ago

(deleted my previous comment since it was wrong)

Adding posts/pages via :extend-params-fn is possible and simple, see https://github.com/holyjak/tmp-demo-cryogen-posts-everywhere/commit/0d7654f816f669b88b313c37aaeecb90d9798437

BUT as you said, the body of the blog posts dissappears when I do this.

holyjak commented 3 years ago

Ok, it is some interesting timing issues. Sometimes the :post only has :content-dom instead of the stringified :content - when I compile the same thing repeatedly, it is random which one I get (content-dom->html converts the former into the latter, called from render-file via htmlize-content)

holyjak commented 3 years ago

This is the cause https://github.com/cryogen-project/cryogen-core/blob/0.4.0/src/cryogen_core/compiler.clj#L328 - if there is posts than we htmlize that and not post. (This is for the tags and previews pages)

I need to explore whether we can safely change the ordering.