How to create url for /blog/ instead of /posts/?

I have my content stored in the content/posts/ folder. I also have permalink setup in config.toml as follows:

[permalinks]
posts = "/blog/:year/:title/"

Currently, this works and gives me example.com/blog/2020/title for each individual post. That said, how do I configure the url to work for example.com/blog instead of example.com/posts? Currently I can only see all posts when going to example.com/posts.

Thank you.

1 Like

rename content/post to content/blog and layout/post to layout/blog

Is this the only way of doing it? Ideally I would like to keep the folder as “posts” for semantic reasons (e.g. a separate folder called pages so I have posts and pages, rather than blog and pages).

Couldn’t you just set the slug front matter variable in content/posts/_index.md like so?

---
slug: blog
---

this is the default … don’t know how to change …

Nope, that doesn’t work. Navigating to example.com/blog gives nothing, and it only shows up in example.com/posts. Guess I’ll just have to rename the content folder to blog then. Strange that everyone uses “posts” in all the tutorials online, but have /blog in their websites.

Yes, I know that’s the default, just wondering if there was any way to change it. Thanks though!

And if you try with url?

---
url: /blog/
---

if you do this in content/posts/_index.html, it generates /blog/index.html - only this file!

Or also you may be able to make use of aliases

You need to do both of the following:

config.toml

[permalinks]
posts = "/blog/:year/:title/"

content/posts/_index.md

+++
title = "Posts"
date = 2020-08-26T06:05:24-04:00
draft = false
url = "/blog"
+++
This is content/posts/_index.md

The template for the list page will be layouts/posts/list.html.

Ok this works, thank you! For experienced users, how did you go about setting up the content organization? Do you do this method (i.e. posts folder, but url as blog), or simply make a blog folder in content? Thanks.

That one. Simpler, fewer moving parts, less things to remember, intuitive, easier to troubleshoot, etc.

1 Like

Gotcha. Thanks for the help!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.