Is it possible to have a page in hugo generate multiple identical output files? That is, if my page is at content/somepage.md, can I have the output copied to both somepage.html and also someotherpage.html?
I think you should be helped by aliases:
The alias from the previous URL to the new URL is a client-side redirect (from above doc)
aliasing is used to keep old urls out in the world keep working even if the real path changed for that page.
If aliasing is the “real” requirement that will fit.
If not, please refine the requirement
usually it’s uncommon to duplicate identical pages in one site to different paths. One would rather link (refer) to the one page multiple times using it’s link.
It’s not usually a good idea, but…
For a site I manage in French and German, one page (and only one) is exactly the same in both languages. But I want to keep 2 urls in the language directories: /fr/ma-page/
and /de/meine-seite/
(link with TranslationKey
).
So I’ve linked the 2 pages with ln
, directly in the local file system. So it’s synchronized and identical in the sources.
Scenario A
If you want to redirect from https://example.org/copy
to https://example.org/original
, use the aliases
field in front matter as suggested by @irkode.
Scenario B
If you want to publish content/original.md
to both https://example.org/original
and https://example.org/copy
, you can use a module mount:
[[module.mounts]]
source = 'content'
target = 'content'
[[module.mounts]]
source = 'content/original.md'
target = 'content/copy.md'
This is impractical if you have more than a few.
Scenario C
Create content/original.md
and populate the content. Then create content/copy.md
like this:
+++
title = 'Copy'
date = 2024-12-13T00:08:02-08:00
+++
{{% include "/original" %}}
And the “include” shortcode should look like this:
{{ with site.GetPage (.Get 0) }}
{{ .RenderShortcodes }}
{{ end }}
With this approach you can control the front matter of the copy without having to duplicate the content.
Symbolic links
Support for symbolic links, also known as soft links or junctions, was removed in v0.123.0.
But the hard links still work. I use them with the latest version of Hugo.
But maybe they are dependent on the operating system used.
I’ve edited my previous response. Hard links should work fine regardless of operating system.