diff --git a/org-publish.el b/org-publish.el index e3bfd436..5895e8bd 100644 --- a/org-publish.el +++ b/org-publish.el @@ -6,7 +6,7 @@ (require 's) (require 'f) -(defun async-export-function (chunk index) +(defun quick/async-export-function (chunk index) "A function to build a future that will export all it's chunk's files" (let ((func `(lambda () (setq lexical-binding t) @@ -70,7 +70,7 @@ func 'ignore))) -(defun chris/org-publish-site () +(defun quick/org-publish-site () "Publish my website by pushing files to specific locations" (interactive) (let* ((notes (--remove @@ -141,7 +141,7 @@ (workers 8) (chunks (seq-split files (ceiling (/ (length files) workers)))) (futures (cl-loop for chunk in chunks and index from 0 - collect (async-export-function chunk index)))) + collect (quick/async-export-function chunk index)))) (mapcar #'async-get futures) (message "Finished exporting all files")))) @@ -178,53 +178,70 @@ :publishing-function org-publish-attachment) ("cochrun.xyz" :components ("notes" "static" "teaching")))) -(defun quick/org-publish-projects (projects) - "Publish all files belonging to the PROJECTS alist. +(defun quick/org-publish-project (project workers) + "Publish all files belonging to the PROJECT. If `:auto-sitemap' is set, publish the sitemap too. If `:makeindex' is set, also produce a file \"theindex.org\"." - (dolist (project (org-publish-expand-projects projects)) - (let ((plist (cdr project))) - (let ((fun (org-publish-property :preparation-function project))) - (cond - ((functionp fun) (funcall fun plist)) - ((consp fun) (dolist (f fun) (funcall f plist))))) - ;; Each project uses its own cache file. - (org-publish-initialize-cache (car project)) - (when (org-publish-property :auto-sitemap project) - (let ((sitemap-filename - (or (org-publish-property :sitemap-filename project) - "sitemap.org"))) - (org-publish-sitemap project sitemap-filename))) - ;; Publish all files from PROJECT except "theindex.org". Its - ;; publishing will be deferred until "theindex.inc" is - ;; populated. - (let ((theindex - (expand-file-name "theindex.org" - (org-publish-property :base-directory project)))) - (dolist (file (org-publish-get-base-files project)) - (unless (file-equal-p file theindex) - (org-publish-file file project t))) - ;; Populate "theindex.inc", if needed, and publish - ;; "theindex.org". - (when (org-publish-property :makeindex project) - (org-publish-index-generate-theindex - project (org-publish-property :base-directory project)) - (org-publish-file theindex project t))) - (let ((fun (org-publish-property :completion-function project))) - (cond - ((functionp fun) (funcall fun plist)) - ((consp fun) (dolist (f fun) (funcall f plist)))))) - (org-publish-write-cache-file))) + (let ((plist (cdr project))) + (let ((fun (org-publish-property :preparation-function project))) + (cond + ((functionp fun) (funcall fun plist)) + ((consp fun) (dolist (f fun) (funcall f plist))))) + ;; Each project uses its own cache file. + (org-publish-initialize-cache (car project)) + (when (org-publish-property :auto-sitemap project) + (let ((sitemap-filename + (or (org-publish-property :sitemap-filename project) + "sitemap.org"))) + (org-publish-sitemap project sitemap-filename))) + ;; Publish all files from PROJECT except "theindex.org". Its + ;; publishing will be deferred until "theindex.inc" is + ;; populated. + (let ((theindex + (expand-file-name "theindex.org" + (org-publish-property :base-directory project)))) + (dolist (file (org-publish-get-base-files project)) + (unless (file-equal-p file theindex) + (org-publish-file file project t))) + ;; Populate "theindex.inc", if needed, and publish + ;; "theindex.org". + (when (org-publish-property :makeindex project) + (org-publish-index-generate-theindex + project (org-publish-property :base-directory project)) + (org-publish-file theindex project t))) + (let ((fun (org-publish-property :completion-function project))) + (cond + ((functionp fun) (funcall fun plist)) + ((consp fun) (dolist (f fun) (funcall f plist))))))) + +(defun quick/org-async-function (project workers)) + +;; This might be a helper function to setup our number of workers? +(defun quick/org-async-publisher (projects &optional workers) + "Builds a set of workers in the project that will +be responsible for ensuring all files are exported using +the most efficient outcome for your machine. + +When optional argument WORKERS is a number, publishing will use +that many sub-emacs processes to build the projects, else it +will use the amount of async workers that makes sense for your +computer." + (let ((workers (if workers workers + (comp--effective-async-max-jobs)))) + (cl-loop for project in projects + collect ))) (defun quick/org-publish (project &optional force async) - "Publish PROJECT. + "Publish PROJECT. This is a more aggressively async version of +`org-publish'. PROJECT is either a project name, as a string, or a project alist (see `org-publish-project-alist' variable). When optional argument FORCE is non-nil, force publishing all files in PROJECT. With a non-nil optional argument ASYNC, -publishing will be done asynchronously, in another process." +publishing will be done asynchronously, using as many workers +on your machine as makes sense." (interactive (list (assoc (completing-read "Publish project: " org-publish-project-alist nil t) @@ -237,6 +254,7 @@ publishing will be done asynchronously, in another process." (cond ((not project)) (async + (quick/org-async-publisher project) (org-export-async-start (lambda (_) nil) `(let ((org-publish-use-timestamps-flag ,(and (not force) org-publish-use-timestamps-flag))) @@ -249,5 +267,7 @@ publishing will be done asynchronously, in another process." (and (not force) org-publish-use-timestamps-flag))) (org-publish-projects (list project)))))))) -(chris/org-publish-site) +(org-publish-expand-projects (list '("cochrun.xyz" :components ("notes" "static" "teaching")))) + +(quick/org-publish "cochrun.xyz" nil t)