emacs-love / weblorg

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

Make weblorg-export function interactive #47

Closed markokocic closed 3 years ago

markokocic commented 3 years ago

By making weblorg-export interactive it is no longer required to leave Emacs while publishing blog.

markokocic commented 3 years ago

Hi @clarete, I always find it more emacs-y and lispy to be able to interactively export the site, without leaving Emacs. However, I understand that weblorg is stateful, and it would be the major refactoring to make it more functional, without the need for the global state.

In the ideal case, I should be able to define something like the following function, that I can run interactively.

(defun exports-my-site-nr-1 ()
  (interactive)
  (weblorg-export
   :site (weblorg-site
          :base-url nil
          :theme nil
          :template-vars '())
   :routes '((weblorg-route
              :name "home"
              :input-pattern "posts/*.org"
              :input-aggregate #'weblorg-input-aggregate-all-desc
              :template "home.html"
              :output "output/index.html"
              :url "/")
             (weblorg-route
              :name "posts"
              :input-pattern "posts/*.org"
              :template "post.html"
              :output "output/posts/{{ slug }}.html"
              :url "/posts/{{ slug }}.html")
             (weblorg-route
              :name "pages"
              :input-pattern "pages/*.org"
              :template "page.html"
              :output "output/pages/{{ slug }}.html"
              :url "/pages/{{ slug }}.html")
             (weblorg-copy-static
              :output "output/static/{{ file }}"
              :url "/static/{{ file }}"))))

That would be self-contained, it would not need global hashtables with sites, routes and other state, and would be able to call it either interactively or from the script.

clarete commented 3 years ago

Hi @markokocic, thank you for taking the time to leave this comment 🙇🏾 I like your suggestion for an API change that is both backward compatible and elegant. Maybe to prevent giving too many responsibilities to weblorg-export, this feature could be provided by something like weblorg-export-site, which could then become a building block for weblorg-export. What do you think?

markokocic commented 3 years ago

hi @clarete, weblorg-export-site would be fine. Then you don't need explicit :site parameter, making a site simply a set of settings and routes to export. I would like this approach.

I'm just not sure about backward compatibility. Right now weblorg is stateful, while this would be stateless/functional API. Maintaining both weblorg-route and weblorg-site which set global state and functional weblorg-export-site could be tricky.