Moving from Jekyll - URL organisation and p

Hi there! Moving from Jekyll to Hugo. Since I don’t have the published date and permalink in the frontmatter and adding that per post would be tedious work, is there:

  1. a way to have Hugo detect the first part of the file name as the publish date e.g. 2021-03-05; and
  2. define the file name after the date as the permalink e.g 2021-03-05-i-like-pizza.md and the permalink becomes /i-like-pizza/?
  3. or alternatively, have the first part added to the front matter as date:?

Thanks in advance.

You need to configure your project.

See Permalinks and Date configuration in the documentation.

Also please have a look at the forum Requesting Help guidelines.

Add this to your config.yaml:

frontmatter:
  date:
    - :filename
    - date

permalinks:
  posts: /blog/:filename

@jhvanderschee the URL uses post title rather than the file name when I use your code. For example, if my post title is “How to Migrate from Jekyll to Hugo” and the URL is 2021-03-05-jekyll-to-hugo.md, I would like to retain the /jekyll-to-hugo/ as the URL. I stumbled upon this but it does not indicate how to get the slug part as well.

1 Like

It is not currently possible to trim the :filename so that the permalink does not include the date.

Yes, it is.

config.toml

[frontmatter]
date = [':filename', ':default']

structure

content/post/
└── 2021-03-05-i-like-pizza.md

published site

public/post/
└── i-like-pizza/
    └── index.html
1 Like

Right. So the :default value does the job.

Ok. Thanks for pointing this out.

The same results are achieved with:

[frontmatter]
date = [':filename']

Adding :default to the array ensures a non-zero date for content files (regular or bundles) that aren’t named yyyy-mm-dd-slug.

@jhvanderschee the URL uses post title rather than the file name when I use your code. For example, if my post title is “How to Migrate from Jekyll to Hugo” and the URL is 2021-03-05-jekyll-to-hugo.md , I would like to retain the /jekyll-to-hugo/ as the URL. I stumbled upon this but it does not indicate how to get the slug part as well.

I reproduced your problem and found in the docs that I should have used :slug instead of :filename. This works:

frontmatter:
  date:
    - :filename
    - date

permalinks:
  posts: /blog/:slug

@jhvanderschee thanks! Solved.

1 Like

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