Remove substring from bundle name in post URL

For sorting purposes, I structure my posts using only bundles, even if there’s only a single markdown file with no other assets:

posts/2021-08-17-my-first-post/index.md

I set it up this way so that when I’m looking at my posts in VS Code, they are sorted from oldest → newest post, as opposed to being sorted alphabetically which I don’t want.

When I view this post in my browser, the URL is:

domain.com/posts/2021-08-17-my-first-post

However, I want it to look like this (minus the date in the directory name):

domain.com/posts/my-first-post

How would I go about making the URL of every post ignore a date prefix like that, if it’s there? I’m hoping for a “generic” solution that doesn’t involve adding front matter to every page.

you missed this

Thanks for the link. I did see that but honestly there’s a lot of information there and I wasn’t sure what I should do. For example, what I need to do involves splitting a string, substring with regex, or some other type of operation. The examples there show using existing variables to build a URL. I don’t see a more complicated example which I think is what I need.

I’m also not sure what a “slug” is. I see :sections but I’m not sure what that means. I assume it means parts of the URL. So /posts/mypost would be two sections?

I also have no experience with golang so if there’s a simple mechanism to strip the string like I need, I won’t know about it.

:section is the upper most directory → posts (or more, read the link :wink: )
You can set title or slug in frontmatter and use it

ex.: my config contains

[permalinks]
    post                   = "/:section/:year/:month/:day/:title"
    photo                  = "/:section/:year/:month/:day/:title"
    book                   = "/:sections/:title"
    series                 = "/:section/:slug"
    tags                   = "/:section/:slug"
    about                  = "/:section/:slug"
    search                 = "/:section/:slug"
    intern                 = "/:section/:year/:month/:day/:title"
    test                   = "/:section/:title"

Right but how do you do an actual expression in there to strip the value of :title? That’s ultimately what I need to do.

samples here

I played around a bit more. With this:

permalinks:
  posts: /:section/:title

I get what looks correct. The issue is that if I change the title of the post, it will break the URL. So I don’t want that. I’d rather it take the name of the folder (which I won’t change). So I’d like to do something like this (rough example):

permalinks:
  posts: /:section/{{ splitstr .File.ContentBaseName 11 }}

But I can’t use those expressions here, it won’t process it. Does this make it more clear what I’m trying to do?

I would do this…

content/posts
└── 2021/
    └── 08/
        └── 17/
            └── my-first-post/
                └── index.md
[permalinks]
posts = "/posts/:title"

try it with slug

permalinks:
posts: /:section/:slug

and set slug in frontmatter
OR
try to set url in frontmatter

url

the full path to the content from the web root. It makes no assumptions about the path of the content file. It also ignores any language prefixes of the multilingual feature.

I considered that but I don’t like nested folder structures for posts. I like this view better:

posts/
    2021-08-16-my-first-post/
    2021-08-17-my-second-post/

It’s annoying that I have to specialize configuration for this, but the benefits are worth it:

  • I can see the post title from a flat view
  • They are all sorted chronologically by the filesystem

If there’s a way to get the above 2 a different way, I’m fully open to learning about it.

So in my archetype for my post bundle I’d basically do this in the front matter?

title: "{{ slicestr .Name 11 | humanize | title }}"
slug: "{{ slicestr .Name 11 }}"

I already did this for the title (to remove the date prefix). This would allow me to rename the title and keep the slug as it was before to control the URL. I didn’t want to add yet another property to my archetype frontmatter but I guess it’s a small price to pay. I appreciate the tip.

Then you’ll have to specify a slug for each post. And remember to change the slug if you change the title.

If I use permalink /:section/:slug why do I need to rename the slug when I rename the title?

Maybe it would be easier to use /:section/:title and just set up a URL alias if I rename the title. I don’t suspect title renaming will happen often.

I’m torn…

Example using Visual Studio Code:

  • List view in integrated terminal
  • Sorted
  • Paged
  • Ctrl + Click to open
alias posts='find content/posts -type f | sort | more'

ib2ht-wr0lw

This actually isn’t bad at all. Do you personally do this or do you have a better way to organize your posts? Loving the advice; thank you.