cryogen

http://cryogenweb.org/ - static sites by @U0DJK1VH6 & Co.
Eugen 2020-12-23T09:02:28.281600Z

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ý 2020-12-23T09:06:16.281900Z

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

Eugen 2020-12-23T09:17:39.282500Z

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}))
  )

Eugen 2020-12-23T09:26:11.282700Z

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

Eugen 2020-12-23T09:31:40.282900Z

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

Eugen 2020-12-23T09:37:03.283100Z

... I still have no idea ..

Jakub Holý 2020-12-23T12:03:44.283300Z

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

Eugen 2020-12-23T12:05:04.283500Z

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

👍 1
Eugen 2020-12-23T12:05:15.283700Z

I don't understant

Jakub Holý 2020-12-23T12:06:04.284Z

Can I git clone your blog?

Eugen 2020-12-23T12:06:10.284200Z

sure

Eugen 2020-12-23T12:06:32.284400Z

lein ring server gets you to the issue

Jakub Holý 2020-12-23T12:16:08.284600Z

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?

Eugen 2020-12-23T12:16:42.284800Z

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

Eugen 2020-12-23T12:17:09.285Z

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

Eugen 2020-12-23T12:17:24.285200Z

and this led me to extend-params-fn

Eugen 2020-12-23T12:17:32.285400Z

I also have the code to generate the tags there

Eugen 2020-12-23T12:54:03.285800Z

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

Eugen 2020-12-23T12:54:35.286Z

I got to go, I'll get back later

Jakub Holý 2020-12-23T13:06:37.286200Z

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

Eugen 2020-12-23T14:15:36.286400Z

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

Eugen 2020-12-23T14:16:13.286700Z

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

Eugen 2020-12-23T16:01:19.286900Z

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

Eugen 2020-12-23T16:03:24.287100Z

will post on main thread

Eugen 2020-12-23T16:05:27.288800Z

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

Eugen 2020-12-23T16:33:00.292400Z

@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.

👀 1
🎉 1
Eugen 2020-12-23T16:43:06.295Z

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ý 2020-12-23T17:50:45.295100Z

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ý 2020-12-23T17:54:25.295400Z

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?

Jakub Holý 2020-12-23T17:56:23.296500Z

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.

✔️ 1
Eugen 2020-12-23T19:12:37.296700Z

is this enough ? https://github.com/cryogen-project/cryogen-core/issues/156

❤️ 1
✅ 1