[SOLVED] Programmatically replicate a folder


#1

Hi! I want to do something weird, so I’m not even sure this is possible.

I have a folder /a, which contains some other inner pages like /a/1, /a/2

and I want this to be replicated under /b, /c, /d and so on.

I don’t want to just copy that, it should be done at build time. Is there any way to achieve this, or any procedure you might think of?

Ideally I’d like to tell Hugo the structure in the config.yaml file, e.g.

clone:
  "a": ['b', 'c', 'd']

the reason is, I want to create some pages that I will uniquely send out (e.g. /b to person1, /c to person2), but the content is all the same and generated from a single page.

Any suggestion appreciated :slight_smile:


#2

Sounds more like you want to create several aliases for the same page … is that it?


#3

Yes. Maybe I should do this on the web server level rather than letting Hugo generate multiple pages.
But I’m evaluating all the options


#4

It sounds like what you’d want is aliases, which is really easy to configure (look in the docs).

If you for some reason want something other than redirects, Hugo supports symbolic links inside the /content directory.


#5

Thanks! I want to retain the URL (not redirect to another location) so AFAIK aliases will change the url.

Symlinks work fine locally, I just tried! I need to check later if I can push a symlink to Netlify and that will do it :slight_smile:


#6

It worked using symlinks! Thanks for the suggestions :raised_hands: