How to specify a permalink for a specific file in Hugo's config

I’m trying to move a Jekyll website to Hugo and can’t replicate a Jekyll feature where you can specify a permalink via a file path in the config file.

Jekyll example in the _config.yml

defaults:
  -
    scope:
      type: web_pages
      path: _web_pages/index.html
    values:
      permalink: /

Rather than having an index.html at the root level of the site it’s located within the collection _web_pages .

How do I do this with a Hugo site without putting the permalink in the front matter. I want to be able to specify this in the config file so it can’t be edited within the CMS I am using.

Will there be more than just the home page in _web_pages, and if so, do you want all of the files in that directory served from root?

Yes there will be multiple files within _web_pages (collection). I just want one particular page served at ‘/’ (index.html), rather than having an index.html at the root of my project. The rest of the items have a permalink set to the following:

permalinks:
  web_pages: /:title/

Ideally I can specify the permalink for individual files in the config similarly to the Jekyll example above.

If I have to resort to setting the url in the front matter it means that customers will be able to mess with it in the CMS that I am using.

config.toml

[permalinks]
_web_pages = "/:title"

structure

content
├── blog
│   ├── post-1.md
│   └── post-2.md
└── _web_pages
    ├── about.md
    ├── contact.md
    └── _index.md

content/_web_pages/_index.md

+++
title = "Home"
date = 2021-03-30T14:59:16-07:00
draft = false
+++
This is the home page.

layouts/_default/home.html (assumes you’re using baseof/block approach)

{{ define "main" }}

  {{ with site.GetPage "_web_pages/_index.md" }}
    <h1>{{ .Title }}</h1>
    {{ .Content }}
    {{ range where .Site.RegularPages "Type" "blog" }}
      <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
      <p>{{ .Summary }}</p>
      {{ if .Truncated }}
        <p><a href="{{ .RelPermalink }}">Continue reading...</a></p>
      {{ end }}
    {{ end }}
  {{ end }}

{{ end }}

Thank you! That helped me get what I was after

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