emacs-love / weblorg

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

Cannot #+INCLUDE files usign relative paths #26

Closed semente closed 3 years ago

semente commented 3 years ago

Considering the route below:

(weblorg-route
 :name "posts"
 :input-pattern "posts/*.org"
 :template "post.html"
 :output ".build/posts/{{ slug }}.html"
 :url "/posts/{{ slug }}.html")

And the files posts/post.org and posts/example.txt:

# post.org
#+INCLUDE: "example.txt"
# example.txt
Lorem ipsum...

I get an error when publishing the website:

Cannot include file /home/semente/pub/example.txt

To make this work I have to use #+INCLUDE: "posts/example.txt", which is not a big deal but I believe this is a bug. Perhaps the function that generates the HTML isn't switching to the directory of the file so it won't have the right context.

mrmechko commented 3 years ago

To expand on this, I would like to collect org-mode files that exist in other folders and export them in my weblorg instance.

The above workaround doesn't suffice when trying to render files included from another :base-dir

Say I have a folder called ~/docs/141 and a subfolder, ~/docs/141/sections/. If I set a weblorg-route that points to ~/docs/141/ the files render correctly but any #+INCLUDE: directives pointing to ~/docs/141/sections fail.

mrmechko commented 3 years ago

I can't quite figure out how to do it myself, but at line 942 in weblorg--parse-org-file if there was an org-to-org export, it would handle the includes, right? I'll try and figure it out next time I sit down with this.

clarete commented 3 years ago

Hi hi @mrmechko! that's right! you're definitely on the right path. I don't know if that's the cleanest, but I was thinking about solving this problem by saving the current directory in a local variable, cd'ing to the path where the Org file is located (dirname of input-path which is the only parameter for weblorg--parse-org-file) and then cd'ing back to the original path once the parsing is done! It'd be awesome if you wanted to take a stab at fixing this issue! <o/

mrmechko commented 3 years ago

Turns out you can change the file that a buffer points to! Once you got that, a simple org-to-org export into your temp buffer, and boom, the rest of weblorg handles everything.

This means I can set up routes for my various documents which are part of their own respective git repos and then generate a single webpage in my weblorg directory.

clarete commented 3 years ago

Thanks to @mrmechko's PR in #35, this issue should be fixed now! Please feel free top re-open it or to open a new one if you find anything weird in there 😄