In each post I used the url param in front matter with the value being the existing URL of each post. I run the site and everything looks great (URL wise they are the same as my current).
Today I ran hugo and I took a look at the public folder and I was confused. After try and error I think I understand. The public folder looks like this:
So the public folder contain my posts at the top level directory, and not under posts/2018/.... And the folders are named as the url param I added in front matter. I understand this and I see this is by design (correct me if I’m wrong!)
My question is: How can I use my existing blog post URLs, but keep the posts organized (inside posts) when I publish the site? Ultimately I wanted them inside posts/year/… but override the url.
And then using slug instead of url in front matter of each post, but that also puts the files outside posts when I publish the site. The same if I use posts: /:filename.
Hey, thanks for your help! I tried briefly with Aliases after seeing other posts here… but I still have the top-level folders with the redirect html file… I guess there’s no way around them? I don’t have many posts but I will have, at least 10 of these folder hanging around… not so great =/
Did you have the same in your migration? Since you mentioned it was a large blog I wonder if you had the same issue? I saw the Customize section in the docs about having a template alias but now sure that can help?
I want the posts to not have the folder structure in the URL. I would like the URL to be like this: mysite.com/myfirst-post where myfirst-post is the URL of my existing blog post. So no “subfolder” in the URL at all.
As @jgreely mentioned above, I can use aliases but I still have the redirect .html files published at the root of my site… not sure I can avoid those using Hugo. I know I can work-around the redirects via DNS and whatnot… but would like to see if I can do something with Hugo first.
@maxjpg, sorry I misunderstood; I thought you just wanted to preserve the old URLs for existing posts, and use a standard organization for new posts. If you want to have a URL like /myfirst-post while only storing the file in content/posts/myfirst-post/index.html, you’ll have to implement it in your web server configuration; Hugo just generates a tree of files, it can’t tell your web server how to get from a virtual /A to a physical content/posts/2008/12/15/A/index.html.
For instance, in Nginx, you could use try_files to search sub-directories for any top-level post names:
If you wanted to get fancy, you could write a custom output format for your server’s redirect config and have Hugo generate a complete set of /A -> wherever/A/ mappings that would be slightly faster at runtime.
Could you clarify what structure you want Hugo to produce for you?
This is correct, and is expected.
What is your existing blog post URL?
So do you want it under yoursite.com/posts/2018/post1/ as mentioned in my second quote snippet of your post above, in bold; or do you want it in yoursite.com/post1/?
I figured it out that to have the same URL as above, I need either the url in front matter, or change the permalinks.
My actual question was how I could do this, but still have the “output” public folder organized inside the content/posts folder.
But I understand more… it’s not a concern of Hugo to do this, but more to configure on the server.
A general question now: I will use the ‘url’ in front matter for the existing posts I have, and use the Hugo structure for the new ones. Just thinking… if I move another day to another static generator or whatever, what is the best to keep? All the blogs I follow, they don’t use the pattern like /posts/year/month or any other combination. It’s just all at the “root” like mine example above.