Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to build an output directory structure different from the source directory structure? #63

Open
jbhoot opened this issue May 9, 2024 · 3 comments

Comments

@jbhoot
Copy link
Contributor

jbhoot commented May 9, 2024

The soupault manual says in overview:

Processed pages are then written to disk, into a directory structure that mirrors your source directory structure.

Is it possible to define an arbitrary structure different from the source structure?

I wish to map as follows:

  • site/yyyy-mm-dd-on-reading-book.md -> build/on-reading-book/index.html
  • site/yyyy-mm-dd-on-guix/{.leaf,index.md,asset.png} -> build/on-guix/{.leaf,index.html,asset.png}

Is anything like this possible?

@jbhoot
Copy link
Contributor Author

jbhoot commented May 9, 2024

I am almost there with the following hook:

[hooks.pre-process]
lua_source = '''
  base_path = Sys.dirname(Sys.dirname(target_file))
  file_name = Sys.basename(target_file)

  target_leaf_dir = Sys.basename(Sys.dirname(target_file))
  regex = "^[0-9]{4}-[0-9]{2}-[0-9]{2}-"

  if Regex.match(target_leaf_dir, regex) then
    new_target_leaf_dir = Regex.replace(target_leaf_dir, regex, "")
    new_target_dir = Sys.join_path(base_path, new_target_leaf_dir)
    new_target_file = Sys.join_path(new_target_dir, file_name)
    print(target_dir .. "->" .. new_target_dir)
    print(target_file .. "->" .. new_target_file)
    target_dir = new_target_dir
    target_file = new_target_file
  end
'''

However, if a page is in form of a leaf dir, i.e., 2024-05-09-on-guix/{.leaf,index.html,asset.jpg}, then after soupault is done processing, the files are split up in build/on-guix/index.html and build/2024-05-09-on-guix/{.leaf,asset.jpg}. This also breaks the links in build/on-guix/index.html.

Is there a way to also copy the assets to the modified target path?

@dmbaturin
Copy link
Collaborator

Hi Jayesh,

It looks like I didn't really consider how the target dir override would compose with assets in leaf directories... Right now, assets are processed very early, before any pages. Which means hooks would have no chance to influence that process in any way.

My original reasoning was that when I get to parallelizing the build process, that part could be delegated to a separate worker thread. But it clearly doesn't compose with the fact that the target path can be modified by a hook.

I'll look how I could make it work correctly. One idea is to move asset processing after pages, store asset file paths in a hash instead of a list and insert target paths generated by hooks in the entries. I hope I'll experiment with that over the weekend.

@jbhoot
Copy link
Contributor Author

jbhoot commented May 9, 2024

Another thing to keep in mind is to fix the reference to a modified target_file if it is crosslinked in some other page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants