Generate PDF and PDF is stored where it was generated from

Hello!
Im working on a pdf export for my Hugo site. I currently am using javascript to iterate through all of the markdown files, turn those into Latex files , which is stored into folder, and then those files are iterated through and turned into a pdf, which those are stored in another folder, so its messy!

what i need help with

i need to be able to somehow store the path of these files when they are being made in the first place, and instead of having them put into a seperate folder all together, all unorganized, i want the pdfs to then be loaded BACK into the exact directory that it had to be generated from . How would i do this?

so far i’ve come across Hugos siteMap template. If anyone has had experience with this would love some help. Thank you