Fork me on GitHub
#cryogen
<
2020-12-23
>
Eugen09:12:28

thanks, but there is something very wrong with my build: • I get either no list of articles in the articles page • or no content in pages or posts I've spent more time on this than I would have liked to and I still have no idea why this happens

Jakub Holý (HolyJak)09:12:16

if your code is online then we can have a look. Is it possible your :extend-params-fn screws up the data?

Eugen09:12:39

I do believe it has something to do with the server/init function: The watcher did not run with the extend-params-fn . I've tried the bellow version but still no luck 😞 . However lein run should produce the proper output. I am a bit lost ...

(defn init []
  (load-plugins)  
  (let [ignored-files (-> (resolve-config) :ignored-files)
        public-dest (-> (resolve-config) :public-dest)
        do-compile (fn [] (compile-assets-timed {:extend-params-fn custom/extend-params}))]
    (do-compile)
    (start-watcher! "content" ignored-files do-compile)
    (start-watcher! "themes" ignored-files do-compile)
    (println (str "Start Live Reload " public-dest))
    (live-reload/start! {:paths [public-dest]
                         :debug? true}))
  )

Eugen09:12:11

I'm going through commits to see what changed. commit 9a0f6998b01d583898c353cb610fc20dca45dade works ok

Eugen09:12:40

i think I found the issue. It was when I moved the extend-fn function in another ns

Eugen09:12:03

... I still have no idea ..

Jakub Holý (HolyJak)12:12:44

Do you pass the extend params fn also from your do-compile?

Eugen12:12:04

?? do-compile is defined in the let, all the code is above

👍 3
Eugen12:12:15

I don't understant

Jakub Holý (HolyJak)12:12:04

Can I git clone your blog?

Eugen12:12:32

lein ring server gets you to the issue

Jakub Holý (HolyJak)12:12:08

So if you don't use your custom extend params everything works, with it something don't? Then error is in it. And what do you mean with "watched did not run the extend fn"? Did the watcher call your do-compile? Perhaps try restarting your repl?

Eugen12:12:42

probably yes, I took a break from tha because I was going crazy

Eugen12:12:09

what I want is to be able to list all posts inside articles.html

Eugen12:12:24

and this led me to extend-params-fn

Eugen12:12:32

I also have the code to generate the tags there

Eugen12:12:03

without my customization and using {% for post in *latest-posts* %} in articles.html it works, but I want ALL posts, not just the latest

Eugen12:12:35

I got to go, I'll get back later

Jakub Holý (HolyJak)13:12:37

Then we know where the error is :-) If you show us your customizations...

Eugen14:12:36

the code on the website has this problem as well. (github link above).

Eugen14:12:13

all the code is there, you can clone it and lein ring server and you should be able to see it

Eugen16:12:19

ok, so I have something, but don't know yet what is the issue:

Eugen16:12:24

will post on main thread

Eugen16:12:27

Can someone help me figgure out why one function call works and another does not?

(defn extend-params [params 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)))) %))]
    (println "hellprrr")
    params))

(comment
 
  ;; This does not print hellprrr
  (compile-assets-timed {:extend-params-fn extend-params})
  
  ;; This does print hellp
  (compile-assets-timed {:extend-params-fn  (fn extend-params [params site-data]
                                              (println "hellp")
                                              params)})
  
 0)
I load the plugins and call each function in the REPL. Only the second one does it's job

Eugen16:12:00

@holyjak: I found the source of my issues. Adding :posts and/or :pages to the params causes havock . After changing the names to :all-my-pages and :all-my-posts things work as expected: pages compile, I see all the posts, I see all the content. Calling the function like (compile-assets-timed {:extend-params-fn extend-params}) also works (need to test more). Working version:

(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 am still puzzled as to why things behave and I do believe this is a bug that should be fixed or at least documented. Please confirm.

🎉 3
👀 3
Jakub Holý (HolyJak)17:12:25

Could you be so kind and https://github.com/cryogen-project/cryogen-core/issues/new describing your problem, preferably in an easy to reproduce way?

Eugen16:12:06

and to have start-watcher! work, it needs to call compile-assets-timed with the same options. I changed mine to look like

(defn init []
  (load-plugins)
  (let [ignored-files (-> (resolve-config) :ignored-files)
        public-dest (-> (resolve-config) :public-dest)
        cate (fn compile-assets-timed-extend []
               (compile-assets-timed {:extend-params-fn c/extend-params}))]
    (cate)
    (start-watcher! "content" ignored-files cate)
    (start-watcher! "themes" ignored-files cate)
    (println (str "Start Live Reload " public-dest))
    (live-reload/start! {:paths [public-dest]
                         :debug? true})))
should I add a PR?

Jakub Holý (HolyJak)17:12:45

Yes, you need to send the same options to the watcher as you do to other compile calls. Isn't that obvious? Here is how I do it https://github.com/holyjak/blog.jakubholy.net/blob/master/src/cryogen/server.clj#L15 A PR with what?

Jakub Holý (HolyJak)17:12:23

BTW I encourage everybody to read https://github.com/cryogen-project/cryogen-core/blob/master/src/cryogen_core/compiler.clj#L565 It isn't that complicated and will give you a much better understanding.

✔️ 3