emacs-love / weblorg

Static Site Generator for Emacs
https://emacs.love/weblorg
GNU General Public License v3.0
278 stars 20 forks source link

Coupling with org-ql to generate new content and dynamic weblorg-route during publish #18

Closed reyman closed 3 years ago

reyman commented 3 years ago

Hi,

I really love the concept of weblorg-route.

As explained in this issue (https://github.com/alphapapa/org-ql/issues/183) we could also also imagine some new type of routing, based on dynamic results generated by some org-ql queries, no ?

That could be very usefull to filter / extract many website from one big folder of ZK notes : https://github.com/org-roam/org-roam/issues/911

Best regards,

clarete commented 3 years ago

hi @reyman 👋🏾

Thank you for taking the time to open the issue. I think these sorts of mash ups are very interesting and I'm pretty excited to see what people will come up with. The way we might currently support such integrations is through the parameter :input-source of weblorg-route (docs).

When provided with a function, it bypasses the find, filter, aggregate steps and take whatever the input-source function returns to the template. There's a fun example of that I put together to auto-generate documentation of Emacs lisp functions:

(weblorg-route
 :name "api"
 :input-source (weblorg-input-source-autodoc-sections
                `(("Routing" . "^weblorg-\\(?:route\\|copy-static\\)")
                  ;; (...)
                  ("Filters" . "^weblorg-input-filter-")))
 :template "autodoc.html"
 :output "api.html"
 :url "/api.html")

You can build your own input-source function and get its return fed into the template passed down to :template.

I'm not very familiar with org-ql (though it did look pretty interesting at first glance 😃) but if you want to check the functions weblorg-input-source-autodoc and weblorg-input-source-autodoc-section you'll see that it really just returns a list of assocs:

(defun weblorg-input-source-autodoc-sections (sections)
  "Run `weblorg-input-source-autodoc' for various SECTIONS."
  `((("sections" . ,(mapcar
                     (lambda(section)
                       (cons "section"
                             `(("name" . ,(car section))
                               ("slug" . ,(weblorg--slugify (car section)))
                               ,@(car (weblorg-input-source-autodoc (cdr section))))))
                     sections)))))

The above function will make the sections variable available to the template autodoc.html. If you have an example of the org-ql query that you'd want to integrate with a weblorg-route, please share it and we can adapt it to get you the route you want.

guilhermecomum commented 3 years ago

Hey @reyman, I believe the solution provide by @clarete solves this request, can you confirm that? Thank you for your interest on weblorg :D

guilhermecomum commented 3 years ago

Closing this issue by the lack of activity