emacs-love / weblorg

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

Handle relative paths for INCLUDE directives #35

Closed mrmechko closed 3 years ago

mrmechko commented 3 years ago

weblorg--parse-org now starts off by performing an org-to-org export which resolves all relative paths in INCLUDE directives

Resolves #26

mrmechko commented 3 years ago

Adds :data-dir as an option for weblorg-copy-static which allows you to copy arbitrary non-theme static directories as desired.

For example, the following copies all the files (slides, images, etc) from ~/docs/141/static to output/cs141/static/.

(weblorg-copy-static
 :name "cs141-static"
 :data-dir "~/docs/141/static"
 :output "output/cs141/static/{{ file }}"
 :url "/static/{{ file }}")

Resolves #32

clarete commented 3 years ago

Hi @mrmechko! thank you so much for putting in the time and getting this PR up! 🙇🏾 it did make the include file issue go away, however it has shown a few different issues, mainly around capturing the file properties, like slug, title, date etc. Also, I think parsing org-mode as org-mode and inserting it within an org-mode buffer seems to be a bit resource inefficient. I mentioned in #26 that it could maybe work to just switch to the directory where the Org file is located while we export it. What do you think?

The second commit is a bit more delicate, I wanted to give some more thought to the issues around it. For example, issue #32 makes me feel like maybe a :recursive t parameter might be more helpful for the case of trying to copy some files under a directory structure recursively, but I also wanted to make it work more seamlessly with :input-pattern instead adding a new option (:data-dir). If we feel like we really need a new parameter for these public functions, some documentation on how it works would also be quite helpful!

mrmechko commented 3 years ago

I can resolve the first part by adding an optional parameter of input-path to weblorg--parse-org and then using (set-visited-file-name input-path t t) right before calling (org-html-export-as-html). I've made a start on it, but Im still learning elisp so its taking some time XD.

For the second part, I don't thing :data-dir bypasses :input-pattern. The issue I'm having is that the static directory must always be named theme, at the moment. I was going for an approach that didn't step on the toes of anything else.

clarete commented 3 years ago

I can resolve the first part by adding an optional parameter of input-path to weblorg--parse-org and then using (set-visited-file-name input-path t t) right before calling (org-html-export-as-html). I've made a start on it, but Im still learning elisp so its taking some time XD.

That could work, but I think it'd take a more complicated change than just something like this:

-  "Parse an Org-Mode file located at INPUT-PATH."
-  (let* ((input-data (with-temp-buffer
+  "Parse an Org-Mode file located at INPUT-PATH.
+
+The output of this function is a list of pairs of name-value
+properties parsed from the Org-Mode in the INPUT-PATH."
+  (let* ((input-dir (file-name-directory input-path))
+         (input-data (with-temp-buffer
                        (insert-file-contents input-path)
                        (buffer-string)))
-         (keywords (weblorg--parse-org input-data))
+         ;; Before actually parsing the Org-Mode file, we'll first CD
+         ;; into its directory, so that things like #+INCLUDE work
+         ;; nicely
+         (keywords (progn
+                     (cd input-dir)
+                     (let ((kw (weblorg--parse-org input-data)))
+                       (cd default-directory)
+                       kw)))

For the second part, I don't thing :data-dir bypasses :input-pattern. The issue I'm having is that the static directory must always be named theme, at the moment. I was going for an approach that didn't step on the toes of anything else.

yeah, I think people in the issue #32 wanted similar things, and we've been discussing what a support for more files would look like.

As a general good practice, I'd suggest to try to contribute with one single change per pull request because it makes it easier to reason/review/merge/revert each change separately.

mrmechko commented 3 years ago

As per suggestion, I reverted the commit for #32.

my latest solution to the include issue is to pass input-path to weblorg--parse-org and set the buffer file there. As far as I can see it doesn't break anything. Does that work?

clarete commented 3 years ago

And just taking back the part that I said CD'ing into the dir would be less complex, your solution looks way less complicated! Thanks for the different perspective here!

mrmechko commented 3 years ago

Resolved the two comments. Glad to have this working. Learning a lot about emacs/elisp here!

clarete commented 3 years ago

Thank you so much for the prompt updates @mrmechko! and for all the work in the PR!

clarete commented 3 years ago

Let me know if there's any information that could make your life easier/save your time in possible next PRs. Feel free to open issues to post questions about the overall design of the dool or how the code is structured! 😄

mrmechko commented 3 years ago

Absolutely. I appreciate all the work you've put in building this amazing tool. Thanks for all the constructive advice 🙂